2009-06-12 14:55:06 +04:00
|
|
|
/*
|
|
|
|
Interface to the terminal controlling library.
|
|
|
|
Ncurses wrapper.
|
|
|
|
|
|
|
|
Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by:
|
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
2009-08-13 09:59:31 +04:00
|
|
|
Ilia Maslakov <il.smind@gmail.com>, 2009.
|
2009-06-12 14:55:06 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be
|
|
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
*/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \brief Source: NCurses-based tty layer of Midnight-commander
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2009-08-06 13:17:01 +04:00
|
|
|
#include <signal.h>
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
#include "../../src/global.h"
|
|
|
|
|
|
|
|
#ifndef WANT_TERM_H
|
|
|
|
# define WANT_TERM_H
|
|
|
|
#endif
|
|
|
|
|
2009-07-12 14:22:41 +04:00
|
|
|
#include "../../src/tty/tty-internal.h" /* slow_tty */
|
2009-09-14 17:43:03 +04:00
|
|
|
#include "../../src/tty/tty.h"
|
2009-05-14 19:18:03 +04:00
|
|
|
#include "../../src/tty/color-internal.h"
|
2009-05-13 17:05:55 +04:00
|
|
|
#include "../../src/tty/win.h"
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
#include "../../src/strutil.h" /* str_term_form */
|
|
|
|
|
|
|
|
/* include at last !!! */
|
|
|
|
#ifdef WANT_TERM_H
|
|
|
|
# include <term.h>
|
|
|
|
#endif /* WANT_TERM_H*/
|
|
|
|
|
|
|
|
/*** global variables **************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions **************************************/
|
|
|
|
|
|
|
|
/*** global variables **************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations **************************************/
|
|
|
|
|
|
|
|
/*** file scope variables **********************************************/
|
|
|
|
|
|
|
|
/*** file scope functions **********************************************/
|
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-10 19:01:15 +04:00
|
|
|
/*** public functions **************************************************/
|
2009-09-14 17:43:03 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
mc_tty_normalize_lines_char(const char *ch)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct mc_tty_lines_struct {
|
|
|
|
const char *line;
|
|
|
|
int line_code;
|
|
|
|
} const lines_codes[] =
|
|
|
|
{
|
|
|
|
{"┌", ACS_BSSB},
|
|
|
|
{"┐", ACS_BBSS},
|
|
|
|
{"└", ACS_SSBB},
|
|
|
|
{"┘", ACS_SBBS},
|
|
|
|
{"├", ACS_SBSS},
|
|
|
|
{"┤", ACS_SSSB},
|
|
|
|
{"┬", ACS_BSSS},
|
|
|
|
{"┴", ACS_SSBS},
|
|
|
|
{"─", ACS_BSBS},
|
|
|
|
{"│", ACS_SBSB},
|
|
|
|
{"┼", ACS_SSSS},
|
|
|
|
{"╔", ACS_BSSB | A_BOLD},
|
|
|
|
{"╗", ACS_BBSS | A_BOLD},
|
|
|
|
{"╤", ACS_BSSS | A_BOLD},
|
|
|
|
{"╧", ACS_SSBS | A_BOLD},
|
|
|
|
{"╚", ACS_SSBB | A_BOLD},
|
|
|
|
{"╝", ACS_SBBS | A_BOLD},
|
|
|
|
{"╟", ACS_SSSB | A_BOLD},
|
|
|
|
{"╢", ACS_SBSS | A_BOLD},
|
|
|
|
{"═", ACS_BSBS | A_BOLD},
|
|
|
|
{"║", ACS_SBSB | A_BOLD},
|
|
|
|
{NULL,0}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return (int) ' ';
|
|
|
|
|
|
|
|
for(i=0;lines_codes[i].line;i++)
|
|
|
|
{
|
|
|
|
if (strcmp(ch,lines_codes[i].line) == 0)
|
|
|
|
return lines_codes[i].line_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) ' ';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2009-05-13 17:05:55 +04:00
|
|
|
void
|
2009-07-12 14:22:41 +04:00
|
|
|
tty_init (gboolean slow, gboolean ugly_lines)
|
2009-05-13 17:05:55 +04:00
|
|
|
{
|
2009-07-12 14:22:41 +04:00
|
|
|
slow_tty = slow;
|
|
|
|
|
2009-05-13 17:05:55 +04:00
|
|
|
initscr ();
|
|
|
|
|
|
|
|
#ifdef HAVE_ESCDELAY
|
|
|
|
/*
|
|
|
|
* If ncurses exports the ESCDELAY variable, it should be set to
|
|
|
|
* a low value, or you'll experience a delay in processing escape
|
|
|
|
* sequences that are recognized by mc (e.g. Esc-Esc). On the other
|
|
|
|
* hand, making ESCDELAY too small can result in some sequences
|
|
|
|
* (e.g. cursor arrows) being reported as separate keys under heavy
|
|
|
|
* processor load, and this can be a problem if mc hasn't learned
|
|
|
|
* them in the "Learn Keys" dialog. The value is in milliseconds.
|
|
|
|
*/
|
|
|
|
ESCDELAY = 200;
|
|
|
|
#endif /* HAVE_ESCDELAY */
|
|
|
|
|
2009-08-04 22:06:26 +04:00
|
|
|
tty_start_interrupt_key ();
|
|
|
|
|
2009-05-13 17:05:55 +04:00
|
|
|
do_enter_ca_mode ();
|
2009-05-19 20:12:29 +04:00
|
|
|
raw ();
|
2009-05-13 17:05:55 +04:00
|
|
|
noecho ();
|
|
|
|
keypad (stdscr, TRUE);
|
|
|
|
nodelay (stdscr, FALSE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
|
|
|
tty_shutdown (void)
|
|
|
|
{
|
|
|
|
endwin ();
|
|
|
|
}
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_reset_prog_mode (void)
|
|
|
|
{
|
|
|
|
reset_prog_mode ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_reset_shell_mode (void)
|
|
|
|
{
|
|
|
|
reset_shell_mode ();
|
|
|
|
}
|
|
|
|
|
2009-05-19 20:12:29 +04:00
|
|
|
void
|
|
|
|
tty_raw_mode (void)
|
|
|
|
{
|
|
|
|
raw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_noraw_mode (void)
|
|
|
|
{
|
|
|
|
noraw ();
|
|
|
|
}
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
|
|
|
tty_noecho (void)
|
|
|
|
{
|
|
|
|
noecho ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tty_flush_input (void)
|
|
|
|
{
|
|
|
|
return flushinp ();
|
|
|
|
}
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_keypad (gboolean set)
|
|
|
|
{
|
|
|
|
keypad (stdscr, (bool) set);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_nodelay (gboolean set)
|
|
|
|
{
|
|
|
|
nodelay (stdscr, (bool) set);
|
|
|
|
}
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
int
|
|
|
|
tty_baudrate (void)
|
|
|
|
{
|
|
|
|
return baudrate();
|
2009-06-19 21:33:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tty_lowlevel_getch (void)
|
|
|
|
{
|
|
|
|
return getch ();
|
2009-06-02 08:55:07 +04:00
|
|
|
}
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
int
|
|
|
|
tty_reset_screen (void)
|
|
|
|
{
|
|
|
|
return endwin ();
|
|
|
|
}
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
void
|
|
|
|
tty_touch_screen (void)
|
|
|
|
{
|
|
|
|
touchwin (stdscr);
|
|
|
|
}
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_gotoyx (int y, int x)
|
|
|
|
{
|
|
|
|
move (y, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_getyx (int *py, int *px)
|
|
|
|
{
|
|
|
|
getyx (stdscr, *py, *px);
|
|
|
|
}
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
/* if x < 0 or y < 0, draw line starting from current position */
|
|
|
|
void
|
|
|
|
tty_draw_hline (int y, int x, int ch, int len)
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
if (ch == ACS_HLINE)
|
2009-09-10 16:14:18 +04:00
|
|
|
ch = mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz];
|
2009-08-24 00:42:28 +04:00
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
if ((y >= 0) && (x >= 0))
|
2009-08-24 00:42:28 +04:00
|
|
|
move (y, x);
|
2009-06-03 23:07:06 +04:00
|
|
|
hline (ch, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if x < 0 or y < 0, draw line starting from current position */
|
|
|
|
void
|
|
|
|
tty_draw_vline (int y, int x, int ch, int len)
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
if (ch == ACS_VLINE)
|
|
|
|
ch = mc_tty_ugly_frm[MC_TTY_FRM_thinvert];
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
if ((y >= 0) && (x >= 0))
|
|
|
|
move (y, x);
|
|
|
|
vline (ch, len);
|
|
|
|
}
|
|
|
|
|
2009-05-26 18:56:42 +04:00
|
|
|
void
|
|
|
|
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
move (y + i, x);
|
|
|
|
hline (ch, cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
move (y, x);
|
|
|
|
}
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
void
|
|
|
|
tty_set_alt_charset (gboolean alt_charset)
|
|
|
|
{
|
|
|
|
(void) alt_charset;
|
|
|
|
}
|
|
|
|
|
2009-06-08 13:49:46 +04:00
|
|
|
void
|
|
|
|
tty_display_8bit (gboolean what)
|
|
|
|
{
|
|
|
|
meta (stdscr, (int) what);
|
|
|
|
}
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_print_char (int c)
|
|
|
|
{
|
|
|
|
addch (c);
|
|
|
|
}
|
|
|
|
|
2009-08-13 09:59:31 +04:00
|
|
|
void
|
|
|
|
tty_print_anychar (int c)
|
|
|
|
{
|
|
|
|
unsigned char str[6 + 1];
|
|
|
|
|
|
|
|
if ( c > 255 ) {
|
|
|
|
int res = g_unichar_to_utf8 (c, (char *)str);
|
|
|
|
if ( res == 0 ) {
|
|
|
|
str[0] = '.';
|
|
|
|
str[1] = '\0';
|
|
|
|
} else {
|
|
|
|
str[res] = '\0';
|
|
|
|
}
|
2009-09-14 17:43:03 +04:00
|
|
|
addstr (str_term_form ((char *)str));
|
2009-08-13 09:59:31 +04:00
|
|
|
} else {
|
|
|
|
addch (c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_print_alt_char (int c)
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
if (c == ACS_VLINE)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_thinvert];
|
|
|
|
else if (c == ACS_HLINE)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_thinhoriz];
|
|
|
|
else if (c == ACS_LTEE)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_leftmiddle];
|
|
|
|
else if (c == ACS_RTEE)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_rightmiddle];
|
|
|
|
else if (c == ACS_ULCORNER)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_lefttop];
|
|
|
|
else if (c == ACS_LLCORNER)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_leftbottom];
|
|
|
|
else if (c == ACS_URCORNER)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_righttop];
|
|
|
|
else if (c == ACS_LRCORNER)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_rightbottom];
|
|
|
|
else if (c == ACS_PLUS)
|
|
|
|
c = mc_tty_ugly_frm[MC_TTY_FRM_centermiddle];
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
addch (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-13 12:38:11 +04:00
|
|
|
tty_print_string (const char *s)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
|
|
|
addstr (str_term_form (s));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
vw_printw (stdscr, fmt, args);
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
tty_tgetstr (const char *cap)
|
|
|
|
{
|
|
|
|
char *unused = NULL;
|
2009-07-10 22:09:41 +04:00
|
|
|
return tgetstr ((char *) cap, &unused);
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-13 12:38:11 +04:00
|
|
|
tty_refresh (void)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
2009-08-16 19:27:33 +04:00
|
|
|
refresh ();
|
|
|
|
doupdate ();
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
2009-05-31 16:23:10 +04:00
|
|
|
|
2009-08-06 13:17:01 +04:00
|
|
|
void
|
|
|
|
tty_setup_sigwinch (void (*handler) (int))
|
|
|
|
{
|
|
|
|
#if (NCURSES_VERSION_MAJOR >= 4) && defined (SIGWINCH)
|
|
|
|
struct sigaction act, oact;
|
|
|
|
act.sa_handler = handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
#ifdef SA_RESTART
|
|
|
|
act.sa_flags |= SA_RESTART;
|
|
|
|
#endif /* SA_RESTART */
|
|
|
|
sigaction (SIGWINCH, &act, &oact);
|
|
|
|
#endif /* SIGWINCH */
|
|
|
|
}
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_beep (void)
|
|
|
|
{
|
|
|
|
beep ();
|
|
|
|
}
|