2009-06-12 14:55:06 +04:00
|
|
|
/*
|
|
|
|
Interface to the terminal controlling library.
|
|
|
|
Slang wrapper.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011
|
|
|
|
The Free Software Foundation, Inc.
|
2009-06-12 14:55:06 +04:00
|
|
|
|
|
|
|
Written by:
|
2010-12-29 12:58:10 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009
|
|
|
|
Egmont Koblinger <egmont@gmail.com>, 2010
|
2009-06-12 14:55:06 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
2009-06-12 14:55:06 +04:00
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
2011-10-15 14:56:47 +04:00
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2009-06-12 14:55:06 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
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.
|
2009-06-12 14:55:06 +04:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-12 14:55:06 +04:00
|
|
|
*/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \brief Source: S-Lang-based tty layer of Midnight Commander
|
2009-02-05 21:28:18 +03:00
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-09-17 02:07:04 +04:00
|
|
|
#include <sys/types.h> /* size_t */
|
2009-08-06 13:17:01 +04:00
|
|
|
#include <unistd.h>
|
2012-10-15 16:03:04 +04:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#include <termios.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-04-06 11:16:11 +04:00
|
|
|
#include "lib/strutil.h" /* str_term_form */
|
2011-02-27 17:50:32 +03:00
|
|
|
#include "lib/util.h" /* is_printable() */
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2011-09-06 19:24:18 +04:00
|
|
|
#include "tty-internal.h" /* mc_tty_normalize_from_utf8() */
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "tty.h"
|
2011-01-11 17:11:08 +03:00
|
|
|
#include "color.h"
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "color-slang.h"
|
|
|
|
#include "color-internal.h"
|
2010-04-06 11:16:11 +04:00
|
|
|
#include "mouse.h" /* Gpm_Event is required in key.h */
|
|
|
|
#include "key.h" /* define_sequence */
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "win.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2010-02-06 13:07:35 +03:00
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
extern int reset_hp_softkeys;
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-08-09 16:55:02 +04:00
|
|
|
#ifndef SLTT_MAX_SCREEN_COLS
|
|
|
|
#define SLTT_MAX_SCREEN_COLS 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SLTT_MAX_SCREEN_ROWS
|
|
|
|
#define SLTT_MAX_SCREEN_ROWS 512
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Various saved termios settings that we control here */
|
|
|
|
static struct termios boot_mode;
|
|
|
|
static struct termios new_mode;
|
|
|
|
|
2009-06-19 21:33:41 +04:00
|
|
|
/* Controls whether we should wait for input in tty_lowlevel_getch */
|
2009-05-31 16:23:10 +04:00
|
|
|
static gboolean no_slang_delay;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
/* This table describes which capabilities we want and which values we
|
|
|
|
* assign to them.
|
|
|
|
*/
|
2010-04-06 11:16:11 +04:00
|
|
|
static const struct
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
int key_code;
|
2009-05-10 19:01:15 +04:00
|
|
|
const char *key_name;
|
2010-04-06 11:16:11 +04:00
|
|
|
} key_table[] =
|
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
{ KEY_F (0), "k0" },
|
|
|
|
{ KEY_F (1), "k1" },
|
|
|
|
{ KEY_F (2), "k2" },
|
|
|
|
{ KEY_F (3), "k3" },
|
|
|
|
{ KEY_F (4), "k4" },
|
|
|
|
{ KEY_F (5), "k5" },
|
|
|
|
{ KEY_F (6), "k6" },
|
|
|
|
{ KEY_F (7), "k7" },
|
|
|
|
{ KEY_F (8), "k8" },
|
|
|
|
{ KEY_F (9), "k9" },
|
|
|
|
{ KEY_F (10), "k;" },
|
|
|
|
{ KEY_F (11), "F1" },
|
|
|
|
{ KEY_F (12), "F2" },
|
|
|
|
{ KEY_F (13), "F3" },
|
|
|
|
{ KEY_F (14), "F4" },
|
|
|
|
{ KEY_F (15), "F5" },
|
|
|
|
{ KEY_F (16), "F6" },
|
|
|
|
{ KEY_F (17), "F7" },
|
|
|
|
{ KEY_F (18), "F8" },
|
|
|
|
{ KEY_F (19), "F9" },
|
|
|
|
{ KEY_F (20), "FA" },
|
|
|
|
{ KEY_IC, "kI" },
|
|
|
|
{ KEY_NPAGE, "kN" },
|
|
|
|
{ KEY_PPAGE, "kP" },
|
|
|
|
{ KEY_LEFT, "kl" },
|
|
|
|
{ KEY_RIGHT, "kr" },
|
|
|
|
{ KEY_UP, "ku" },
|
|
|
|
{ KEY_DOWN, "kd" },
|
|
|
|
{ KEY_DC, "kD" },
|
|
|
|
{ KEY_BACKSPACE, "kb" },
|
|
|
|
{ KEY_HOME, "kh" },
|
|
|
|
{ KEY_END, "@7" },
|
|
|
|
{ 0, NULL }
|
|
|
|
/* *INDENT-ON* */
|
2009-05-10 19:01:15 +04:00
|
|
|
};
|
|
|
|
|
2012-10-30 14:56:02 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2005-03-19 22:31:23 +03:00
|
|
|
|
2011-09-01 11:21:47 +04:00
|
|
|
static void
|
|
|
|
tty_setup_sigwinch (void (*handler) (int))
|
|
|
|
{
|
2012-10-30 14:56:02 +04:00
|
|
|
(void) SLsignal (SIGWINCH, handler);
|
2011-09-01 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
sigwinch_handler (int dummy)
|
|
|
|
{
|
|
|
|
(void) dummy;
|
|
|
|
|
2012-10-31 10:48:56 +04:00
|
|
|
mc_global.tty.winch_flag = 1;
|
2012-10-30 14:56:02 +04:00
|
|
|
(void) SLsignal (SIGWINCH, sigwinch_handler);
|
2011-09-01 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
/* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
|
|
|
|
elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
|
|
|
|
consequence is that function keys don't work in MC sometimes...
|
|
|
|
Unfortunately I don't now the one and only escape sequence to turn off.
|
|
|
|
softkeys (elm uses three different capabilities to turn on softkeys and two.
|
|
|
|
capabilities to turn them off)..
|
|
|
|
Among other things elm uses the pair we already use in slang_keypad. That's.
|
|
|
|
the reason why I call slang_reset_softkeys from slang_keypad. In lack of
|
|
|
|
something better the softkeys are programmed to their defaults from the
|
|
|
|
termcap/terminfo database.
|
|
|
|
The escape sequence to program the softkeys is taken from elm and it is.
|
|
|
|
hardcoded because neither slang nor ncurses 4.1 know how to 'printf' this.
|
|
|
|
sequence. -- Norbert
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
slang_reset_softkeys (void)
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
static const char display[] = " ";
|
|
|
|
char tmp[BUF_SMALL];
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
for (key = 1; key < 9; key++)
|
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
char *send;
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
g_snprintf (tmp, sizeof (tmp), "k%d", key);
|
|
|
|
send = (char *) SLtt_tgetstr (tmp);
|
2010-04-06 11:16:11 +04:00
|
|
|
if (send != NULL)
|
|
|
|
{
|
2011-08-26 11:27:41 +04:00
|
|
|
g_snprintf (tmp, sizeof (tmp), ESC_STR "&f%dk%dd%dL%s%s", key,
|
2009-09-17 02:07:04 +04:00
|
|
|
(int) (sizeof (display) - 1), (int) strlen (send), display, send);
|
|
|
|
SLtt_write_string (tmp);
|
|
|
|
}
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
static void
|
|
|
|
do_define_key (int code, const char *strcap)
|
|
|
|
{
|
|
|
|
char *seq;
|
|
|
|
|
|
|
|
seq = (char *) SLtt_tgetstr ((char *) strcap);
|
|
|
|
if (seq != NULL)
|
2009-09-17 02:07:04 +04:00
|
|
|
define_sequence (code, seq, MCKEY_NOACTION);
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
static void
|
|
|
|
load_terminfo_keys (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
for (i = 0; key_table[i].key_code; i++)
|
|
|
|
do_define_key (key_table[i].key_code, key_table[i].key_name);
|
2009-02-04 22:37:00 +03:00
|
|
|
}
|
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** public functions ****************************************************************************/
|
2009-09-14 17:43:03 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
2009-09-17 02:07:04 +04:00
|
|
|
mc_tty_normalize_lines_char (const char *str)
|
2009-09-14 17:43:03 +04:00
|
|
|
{
|
|
|
|
char *str2;
|
|
|
|
int res;
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
struct mc_tty_lines_struct
|
|
|
|
{
|
2009-09-28 12:04:54 +04:00
|
|
|
const char *line;
|
|
|
|
int line_code;
|
|
|
|
} const lines_codes[] = {
|
|
|
|
{"\342\224\214", SLSMG_ULCORN_CHAR},
|
|
|
|
{"\342\224\220", SLSMG_URCORN_CHAR},
|
|
|
|
{"\342\224\224", SLSMG_LLCORN_CHAR},
|
|
|
|
{"\342\224\230", SLSMG_LRCORN_CHAR},
|
|
|
|
{"\342\224\234", SLSMG_LTEE_CHAR},
|
|
|
|
{"\342\224\244", SLSMG_RTEE_CHAR},
|
|
|
|
{"\342\224\254", SLSMG_UTEE_CHAR},
|
|
|
|
{"\342\224\264", SLSMG_DTEE_CHAR},
|
|
|
|
{"\342\224\200", SLSMG_HLINE_CHAR},
|
|
|
|
{"\342\224\202", SLSMG_VLINE_CHAR},
|
|
|
|
{"\342\224\274", SLSMG_PLUS_CHAR},
|
|
|
|
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
if (!str)
|
|
|
|
return (int) ' ';
|
2009-09-28 12:04:54 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
for (res = 0; lines_codes[res].line; res++)
|
|
|
|
{
|
2009-09-28 12:04:54 +04:00
|
|
|
if (strcmp (str, lines_codes[res].line) == 0)
|
|
|
|
return lines_codes[res].line_code;
|
|
|
|
}
|
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
str2 = mc_tty_normalize_from_utf8 (str);
|
|
|
|
res = g_utf8_get_char_validated (str2, -1);
|
|
|
|
|
|
|
|
if (res < 0)
|
2009-09-17 02:07:04 +04:00
|
|
|
res = (unsigned char) str2[0];
|
|
|
|
g_free (str2);
|
2009-09-14 17:43:03 +04:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
2011-09-06 19:24:18 +04:00
|
|
|
tty_init (gboolean mouse_enable, gboolean is_xterm)
|
2009-06-02 21:40:37 +04:00
|
|
|
{
|
2010-11-09 14:10:14 +03:00
|
|
|
SLtt_Ignore_Beep = 1;
|
2011-02-28 20:57:13 +03:00
|
|
|
|
2011-09-01 11:09:55 +04:00
|
|
|
SLutf8_enable (-1); /* has to be called first before any of the other functions. */
|
1998-02-27 07:54:42 +03:00
|
|
|
SLtt_get_terminfo ();
|
2009-09-17 02:07:04 +04:00
|
|
|
/*
|
|
|
|
* If the terminal in not in terminfo but begins with a well-known
|
|
|
|
* string such as "linux" or "xterm" S-Lang will go on, but the
|
|
|
|
* terminal size and several other variables won't be initialized
|
|
|
|
* (as of S-Lang 1.4.4). Detect it and abort. Also detect extremely
|
|
|
|
* small, large and negative screen dimensions.
|
|
|
|
*/
|
2009-05-10 19:01:15 +04:00
|
|
|
if ((COLS < 10) || (LINES < 5)
|
2010-04-06 11:16:11 +04:00
|
|
|
|| (COLS > SLTT_MAX_SCREEN_COLS) || (LINES > SLTT_MAX_SCREEN_ROWS))
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
fprintf (stderr,
|
|
|
|
_("Screen size %dx%d is not supported.\n"
|
|
|
|
"Check the TERM environment variable.\n"), COLS, LINES);
|
2010-03-31 13:28:06 +04:00
|
|
|
exit (EXIT_FAILURE);
|
2001-06-13 10:53:08 +04:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
tcgetattr (fileno (stdin), &boot_mode);
|
|
|
|
/* 255 = ignore abort char; XCTRL('g') for abort char = ^g */
|
2009-12-23 19:18:25 +03:00
|
|
|
SLang_init_tty (XCTRL ('g'), 1, 0);
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2011-09-07 13:06:03 +04:00
|
|
|
if (mc_global.tty.ugly_line_drawing)
|
2009-09-17 02:07:04 +04:00
|
|
|
SLtt_Has_Alt_Charset = 0;
|
2009-07-12 14:22:41 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* If SLang uses fileno(stderr) for terminal input MC will hang
|
|
|
|
if we call SLang_getkey between calls to open_error_pipe and
|
|
|
|
close_error_pipe, e.g. when we do a growing view of an gzipped
|
|
|
|
file. */
|
|
|
|
if (SLang_TT_Read_FD == fileno (stderr))
|
2009-09-17 02:07:04 +04:00
|
|
|
SLang_TT_Read_FD = fileno (stdin);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
if (tcgetattr (SLang_TT_Read_FD, &new_mode) == 0)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef VDSUSP
|
2009-09-17 02:07:04 +04:00
|
|
|
new_mode.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
|
|
|
#ifdef VLNEXT
|
2009-09-17 02:07:04 +04:00
|
|
|
new_mode.c_cc[VLNEXT] = NULL_VALUE; /* to ignore ^V */
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
2009-09-17 02:07:04 +04:00
|
|
|
tcsetattr (SLang_TT_Read_FD, TCSADRAIN, &new_mode);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_reset_prog_mode ();
|
1998-02-27 07:54:42 +03:00
|
|
|
load_terminfo_keys ();
|
2011-01-11 17:10:27 +03:00
|
|
|
|
|
|
|
SLtt_Blink_Mode = tty_use_256colors ()? 1 : 0;
|
2009-06-08 15:59:04 +04:00
|
|
|
|
2009-08-04 22:06:26 +04:00
|
|
|
tty_start_interrupt_key ();
|
|
|
|
|
2009-06-08 15:59:04 +04:00
|
|
|
/* It's the small part from the previous init_key() */
|
|
|
|
init_key_input_fd ();
|
2009-07-12 14:22:41 +04:00
|
|
|
|
2011-09-01 11:09:55 +04:00
|
|
|
/* For 8-bit locales, NCurses handles 154 (0x9A) symbol properly, while S-Lang
|
|
|
|
* requires SLsmg_Display_Eight_Bit >= 154 (OR manual filtering if xterm display
|
|
|
|
* detected - but checking TERM would fail under screen, OR running xterm
|
|
|
|
* with allowC1Printable).
|
|
|
|
*/
|
|
|
|
tty_display_8bit (FALSE);
|
|
|
|
|
2009-07-12 14:22:41 +04:00
|
|
|
SLsmg_init_smg ();
|
2011-09-01 11:09:55 +04:00
|
|
|
if (!mouse_enable)
|
|
|
|
use_mouse_p = MOUSE_DISABLED;
|
|
|
|
tty_init_xterm_support (is_xterm); /* do it before do_enter_ca_mode() call */
|
2009-07-12 14:22:41 +04:00
|
|
|
do_enter_ca_mode ();
|
|
|
|
tty_keypad (TRUE);
|
|
|
|
tty_nodelay (FALSE);
|
2011-09-01 11:21:47 +04:00
|
|
|
|
|
|
|
tty_setup_sigwinch (sigwinch_handler);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
|
|
|
tty_shutdown (void)
|
|
|
|
{
|
|
|
|
char *op_cap;
|
|
|
|
|
2011-09-01 16:40:40 +04:00
|
|
|
disable_mouse ();
|
2013-10-01 13:31:13 +04:00
|
|
|
disable_bracketed_paste ();
|
2009-06-02 21:40:37 +04:00
|
|
|
tty_reset_shell_mode ();
|
2011-09-01 16:40:40 +04:00
|
|
|
tty_noraw_mode ();
|
|
|
|
tty_keypad (FALSE);
|
|
|
|
tty_reset_screen ();
|
2009-06-02 21:40:37 +04:00
|
|
|
do_exit_ca_mode ();
|
|
|
|
SLang_reset_tty ();
|
|
|
|
|
|
|
|
/* Load the op capability to reset the colors to those that were
|
|
|
|
* active when the program was started up
|
|
|
|
*/
|
|
|
|
op_cap = SLtt_tgetstr ((char *) "op");
|
2010-04-06 11:16:11 +04:00
|
|
|
if (op_cap != NULL)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
fputs (op_cap, stdout);
|
|
|
|
fflush (stdout);
|
2009-06-02 21:40:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 16:03:04 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_change_screen_size (void)
|
|
|
|
{
|
|
|
|
SLtt_get_screen_size ();
|
|
|
|
SLsmg_reinit_smg ();
|
|
|
|
|
2012-10-30 14:56:02 +04:00
|
|
|
#ifdef ENABLE_SUBSHELL
|
|
|
|
if (mc_global.tty.use_subshell)
|
|
|
|
tty_resize (mc_global.tty.subshell_pty);
|
|
|
|
#endif
|
2012-10-15 16:03:04 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-31 16:23:10 +04:00
|
|
|
/* Done each time we come back from done mode */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_reset_prog_mode (void)
|
|
|
|
{
|
|
|
|
tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
|
|
|
|
SLsmg_init_smg ();
|
|
|
|
SLsmg_touch_lines (0, LINES);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-05-31 16:23:10 +04:00
|
|
|
/* Called each time we want to shutdown slang screen manager */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_reset_shell_mode (void)
|
|
|
|
{
|
|
|
|
tcsetattr (SLang_TT_Read_FD, TCSANOW, &boot_mode);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
void
|
2009-05-19 20:12:29 +04:00
|
|
|
tty_raw_mode (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-19 20:12:29 +04:00
|
|
|
void
|
|
|
|
tty_noraw_mode (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
|
|
|
tty_noecho (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
int
|
|
|
|
tty_flush_input (void)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
return 0; /* OK */
|
2009-06-02 21:40:37 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
void
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_keypad (gboolean set)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-31 16:23:10 +04:00
|
|
|
char *keypad_string;
|
|
|
|
|
|
|
|
keypad_string = (char *) SLtt_tgetstr ((char *) (set ? "ks" : "ke"));
|
|
|
|
if (keypad_string != NULL)
|
2009-09-17 02:07:04 +04:00
|
|
|
SLtt_write_string (keypad_string);
|
2009-05-31 16:23:10 +04:00
|
|
|
if (set && reset_hp_softkeys)
|
2009-09-17 02:07:04 +04:00
|
|
|
slang_reset_softkeys ();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
void
|
2009-05-31 16:23:10 +04:00
|
|
|
tty_nodelay (gboolean set)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-31 16:23:10 +04:00
|
|
|
no_slang_delay = set;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
int
|
|
|
|
tty_baudrate (void)
|
|
|
|
{
|
|
|
|
return SLang_TT_Baud_Rate;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2002-11-29 00:35:49 +03:00
|
|
|
int
|
2009-06-19 21:33:41 +04:00
|
|
|
tty_lowlevel_getch (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-04-13 23:21:03 +04:00
|
|
|
int c;
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2009-08-09 16:55:02 +04:00
|
|
|
if (no_slang_delay && (SLang_input_pending (0) == 0))
|
2009-09-17 02:07:04 +04:00
|
|
|
return -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-08-09 16:55:02 +04:00
|
|
|
c = SLang_getkey ();
|
2010-04-06 11:16:11 +04:00
|
|
|
if (c == SLANG_GETKEY_ERROR)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
fprintf (stderr,
|
|
|
|
"SLang_getkey returned SLANG_GETKEY_ERROR\n"
|
|
|
|
"Assuming EOF on stdin and exiting\n");
|
2010-03-31 13:28:06 +04:00
|
|
|
exit (EXIT_FAILURE);
|
1999-04-13 23:21:03 +04:00
|
|
|
}
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2002-11-29 00:35:49 +03:00
|
|
|
return c;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
int
|
|
|
|
tty_reset_screen (void)
|
|
|
|
{
|
|
|
|
SLsmg_reset_smg ();
|
2009-09-17 02:07:04 +04:00
|
|
|
return 0; /* OK */
|
2009-06-02 21:40:37 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
void
|
|
|
|
tty_touch_screen (void)
|
|
|
|
{
|
|
|
|
SLsmg_touch_lines (0, LINES);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_gotoyx (int y, int x)
|
|
|
|
{
|
|
|
|
SLsmg_gotorc (y, x);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_getyx (int *py, int *px)
|
|
|
|
{
|
|
|
|
*py = SLsmg_get_row ();
|
2009-05-11 16:13:58 +04:00
|
|
|
*px = SLsmg_get_column ();
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
void
|
|
|
|
tty_draw_hline (int y, int x, int ch, int len)
|
|
|
|
{
|
2011-01-14 20:52:40 +03:00
|
|
|
int x1;
|
|
|
|
|
|
|
|
if (y < 0 || y >= LINES || x >= COLS)
|
|
|
|
return;
|
2009-08-24 00:42:28 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
x1 = x;
|
|
|
|
|
|
|
|
if (x < 0)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2011-01-14 20:52:40 +03:00
|
|
|
len += x;
|
|
|
|
if (len <= 0)
|
|
|
|
return;
|
|
|
|
x = 0;
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
if (ch == ACS_HLINE)
|
|
|
|
ch = mc_tty_frm[MC_TTY_FRM_HORIZ];
|
2009-06-03 23:07:06 +04:00
|
|
|
if (ch == 0)
|
2009-09-17 02:07:04 +04:00
|
|
|
ch = ACS_HLINE;
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
SLsmg_gotorc (y, x);
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
if (ch == ACS_HLINE)
|
2009-09-17 02:07:04 +04:00
|
|
|
SLsmg_draw_hline (len);
|
2009-06-03 23:07:06 +04:00
|
|
|
else
|
2009-09-17 02:07:04 +04:00
|
|
|
while (len-- != 0)
|
|
|
|
tty_print_char (ch);
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
SLsmg_gotorc (y, x1);
|
2009-06-03 23:07:06 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
void
|
|
|
|
tty_draw_vline (int y, int x, int ch, int len)
|
|
|
|
{
|
2011-01-14 20:52:40 +03:00
|
|
|
int y1;
|
|
|
|
|
|
|
|
if (x < 0 || x >= COLS || y >= LINES)
|
|
|
|
return;
|
2009-09-10 16:14:18 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
y1 = y;
|
|
|
|
|
|
|
|
if (y < 0)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2011-01-14 20:52:40 +03:00
|
|
|
len += y;
|
|
|
|
if (len <= 0)
|
|
|
|
return;
|
|
|
|
y = 0;
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
if (ch == ACS_VLINE)
|
|
|
|
ch = mc_tty_frm[MC_TTY_FRM_VERT];
|
2009-06-03 23:07:06 +04:00
|
|
|
if (ch == 0)
|
2009-09-17 02:07:04 +04:00
|
|
|
ch = ACS_VLINE;
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
SLsmg_gotorc (y, x);
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
if (ch == ACS_VLINE)
|
2009-09-17 02:07:04 +04:00
|
|
|
SLsmg_draw_vline (len);
|
2010-04-06 11:16:11 +04:00
|
|
|
else
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
int pos = 0;
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
while (len-- != 0)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
SLsmg_gotorc (y + pos, x);
|
|
|
|
tty_print_char (ch);
|
|
|
|
pos++;
|
|
|
|
}
|
2009-06-03 23:07:06 +04:00
|
|
|
}
|
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
SLsmg_gotorc (y1, x);
|
2009-06-03 23:07:06 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-26 18:56:42 +04:00
|
|
|
void
|
|
|
|
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
|
|
|
{
|
|
|
|
SLsmg_fill_region (y, x, rows, cols, ch);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
void
|
|
|
|
tty_set_alt_charset (gboolean alt_charset)
|
|
|
|
{
|
|
|
|
SLsmg_set_char_set ((int) alt_charset);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-08 13:49:46 +04:00
|
|
|
void
|
|
|
|
tty_display_8bit (gboolean what)
|
|
|
|
{
|
|
|
|
SLsmg_Display_Eight_Bit = what ? 128 : 160;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_print_char (int c)
|
|
|
|
{
|
2009-05-29 19:30:45 +04:00
|
|
|
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
2010-03-17 22:19:03 +03:00
|
|
|
tty_print_alt_char (int c, gboolean single)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
2009-09-10 16:14:18 +04:00
|
|
|
#define DRAW(x, y) (x == y) \
|
2009-09-28 12:04:54 +04:00
|
|
|
? SLsmg_draw_object (SLsmg_get_row(), SLsmg_get_column(), x) \
|
|
|
|
: SLsmg_write_char ((unsigned int) y)
|
2010-04-06 11:16:11 +04:00
|
|
|
switch (c)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
case ACS_VLINE:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_HLINE:
|
2010-04-06 11:16:11 +04:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_LTEE:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTMIDDLE : MC_TTY_FRM_DLEFTMIDDLE]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_RTEE:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_RIGHTMIDDLE : MC_TTY_FRM_DRIGHTMIDDLE]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_ULCORNER:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTTOP : MC_TTY_FRM_DLEFTTOP]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_LLCORNER:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_LEFTBOTTOM : MC_TTY_FRM_DLEFTBOTTOM]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_URCORNER:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_RIGHTTOP : MC_TTY_FRM_DRIGHTTOP]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_LRCORNER:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[single ? MC_TTY_FRM_RIGHTBOTTOM : MC_TTY_FRM_DRIGHTBOTTOM]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
case ACS_PLUS:
|
2010-03-21 20:50:20 +03:00
|
|
|
DRAW (c, mc_tty_frm[MC_TTY_FRM_CROSS]);
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SLsmg_write_char ((unsigned int) c);
|
2009-08-24 00:42:28 +04:00
|
|
|
}
|
2009-09-10 16:14:18 +04:00
|
|
|
#undef DRAW
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-13 09:59:31 +04:00
|
|
|
void
|
|
|
|
tty_print_anychar (int c)
|
|
|
|
{
|
2010-04-06 11:16:11 +04:00
|
|
|
if (c > 255)
|
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
char str[UTF8_CHAR_LEN + 1];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = g_unichar_to_utf8 (c, str);
|
2010-04-06 11:16:11 +04:00
|
|
|
if (res == 0)
|
|
|
|
{
|
2009-08-13 09:59:31 +04:00
|
|
|
str[0] = '.';
|
|
|
|
str[1] = '\0';
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-13 09:59:31 +04:00
|
|
|
str[res] = '\0';
|
|
|
|
}
|
|
|
|
SLsmg_write_string ((char *) str_term_form (str));
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-27 17:50:32 +03:00
|
|
|
if (!is_printable (c))
|
|
|
|
c = '.';
|
2009-08-13 09:59:31 +04:00
|
|
|
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_print_string (const char *s)
|
|
|
|
{
|
2009-07-10 22:09:41 +04:00
|
|
|
SLsmg_write_string ((char *) str_term_form (s));
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2009-05-13 12:38:11 +04:00
|
|
|
va_start (args, fmt);
|
2009-07-10 22:09:41 +04:00
|
|
|
SLsmg_vprintf ((char *) fmt, args);
|
2009-05-10 19:01:15 +04:00
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
char *
|
|
|
|
tty_tgetstr (const char *cap)
|
|
|
|
{
|
2009-07-10 22:09:41 +04:00
|
|
|
return SLtt_tgetstr ((char *) cap);
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
void
|
2009-05-13 12:38:11 +04:00
|
|
|
tty_refresh (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-16 19:27:33 +04:00
|
|
|
SLsmg_refresh ();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-05-31 16:23:10 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_beep (void)
|
|
|
|
{
|
|
|
|
SLtt_beep ();
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|