mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-22 03:02:06 +03:00
Ticket #2601: incorrect TTY layer initialization.
The xterm_flag variable was initialized in setup_mc() but used first time in init_key() and in tty_init() (in do_enter_ca_mode()) before setup_mc() call. Now xterm initialized in early step of mc start up process and xterm support and mouse are initialized in tty_init(). Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
eba55ddb56
commit
68468a25ac
@ -39,6 +39,7 @@ extern gboolean mouse_enabled;
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
char *mc_tty_normalize_from_utf8 (const char *);
|
||||
void tty_init_xterm_support (gboolean is_xterm);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_TTY_INTERNAL_H */
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "tty-internal.h" /* slow_tty */
|
||||
#include "tty.h"
|
||||
#include "color-internal.h"
|
||||
#include "mouse.h"
|
||||
#include "win.h"
|
||||
|
||||
/* include at last !!! */
|
||||
@ -137,7 +138,7 @@ mc_tty_normalize_lines_char (const char *ch)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_init (gboolean slow, gboolean ugly_lines)
|
||||
tty_init (gboolean slow, gboolean ugly_lines, gboolean mouse_enable, gboolean is_xterm)
|
||||
{
|
||||
slow_tty = slow;
|
||||
(void) ugly_lines;
|
||||
@ -165,6 +166,10 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
||||
|
||||
tty_start_interrupt_key ();
|
||||
|
||||
if (!mouse_enable)
|
||||
use_mouse_p = MOUSE_DISABLED;
|
||||
tty_init_xterm_support (is_xterm); /* do it before do_enter_ca_mode() call */
|
||||
init_mouse ();
|
||||
do_enter_ca_mode ();
|
||||
tty_raw_mode ();
|
||||
noecho ();
|
||||
|
@ -243,14 +243,14 @@ mc_tty_normalize_lines_char (const char *str)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_init (gboolean slow, gboolean ugly_lines)
|
||||
tty_init (gboolean slow, gboolean ugly_lines, gboolean mouse_enable, gboolean is_xterm)
|
||||
{
|
||||
slow_tty = slow;
|
||||
ugly_line_drawing = ugly_lines;
|
||||
|
||||
SLtt_Ignore_Beep = 1;
|
||||
|
||||
SLutf8_enable (-1); /* has to be called first before any of the other functions. */
|
||||
SLutf8_enable (-1); /* has to be called first before any of the other functions. */
|
||||
SLtt_get_terminfo ();
|
||||
/*
|
||||
* If the terminal in not in terminfo but begins with a well-known
|
||||
@ -303,7 +303,18 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
||||
/* It's the small part from the previous init_key() */
|
||||
init_key_input_fd ();
|
||||
|
||||
/* 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);
|
||||
|
||||
SLsmg_init_smg ();
|
||||
if (!mouse_enable)
|
||||
use_mouse_p = MOUSE_DISABLED;
|
||||
tty_init_xterm_support (is_xterm); /* do it before do_enter_ca_mode() call */
|
||||
init_mouse ();
|
||||
do_enter_ca_mode ();
|
||||
tty_keypad (TRUE);
|
||||
tty_nodelay (FALSE);
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* exit() */
|
||||
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
@ -43,6 +45,7 @@
|
||||
|
||||
#include "tty.h"
|
||||
#include "tty-internal.h"
|
||||
#include "mouse.h" /* use_mouse_p */
|
||||
#include "win.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
@ -82,6 +85,34 @@ sigintr_handler (int signo)
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Check terminal type. If $TERM is not set or value is empty, mc finishes with EXIT_FAILURE.
|
||||
*
|
||||
* @param force_xterm Set forced the XTerm type
|
||||
*
|
||||
* @return true if @param force_xterm is true or value of $TERM is one of term*, konsole*
|
||||
* rxvt*, Eterm or dtterm
|
||||
*/
|
||||
gboolean
|
||||
tty_check_term (gboolean force_xterm)
|
||||
{
|
||||
const char *termvalue;
|
||||
|
||||
termvalue = getenv ("TERM");
|
||||
if (termvalue == NULL || *termvalue == '\0')
|
||||
{
|
||||
fputs (_("The TERM environment variable is unset!\n"), stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return force_xterm || strncmp (termvalue, "xterm", 5) == 0
|
||||
|| strncmp (termvalue, "konsole", 7) == 0
|
||||
|| strncmp (termvalue, "rxvt", 4) == 0
|
||||
|| strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern gboolean
|
||||
tty_is_slow (void)
|
||||
{
|
||||
@ -259,3 +290,41 @@ tty_low_level_change_screen_size (void)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_init_xterm_support (gboolean is_xterm)
|
||||
{
|
||||
const char *termvalue;
|
||||
|
||||
termvalue = getenv ("TERM");
|
||||
|
||||
/* Check mouse capabilities */
|
||||
xmouse_seq = tty_tgetstr ("Km");
|
||||
|
||||
if (strcmp (termvalue, "cygwin") == 0)
|
||||
{
|
||||
is_xterm = TRUE;
|
||||
use_mouse_p = MOUSE_DISABLED;
|
||||
}
|
||||
|
||||
if (is_xterm)
|
||||
{
|
||||
/* Default to the standard xterm sequence */
|
||||
if (xmouse_seq == NULL)
|
||||
xmouse_seq = ESC_STR "[M";
|
||||
|
||||
/* Enable mouse unless explicitly disabled by --nomouse */
|
||||
if (use_mouse_p != MOUSE_DISABLED)
|
||||
{
|
||||
const char *color_term = getenv ("COLORTERM");
|
||||
if (strncmp (termvalue, "rxvt", 4) == 0 ||
|
||||
(color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
|
||||
strcmp (termvalue, "Eterm") == 0)
|
||||
use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
|
||||
else
|
||||
use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -75,7 +75,9 @@ extern void tty_beep (void);
|
||||
|
||||
/* {{{ Input }}} */
|
||||
|
||||
extern void tty_init (gboolean slow, gboolean ugly_lines);
|
||||
extern gboolean tty_check_term (gboolean force_xterm);
|
||||
extern void tty_init (gboolean slow, gboolean ugly_lines, gboolean mouse_enable,
|
||||
gboolean is_xterm);
|
||||
extern void tty_shutdown (void);
|
||||
|
||||
extern gboolean tty_is_slow (void);
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
/* This flag is set by xterm detection routine in function main() */
|
||||
/* It is used by function view_other_cmd() */
|
||||
int xterm_flag = 0;
|
||||
gboolean xterm_flag = FALSE;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int xterm_flag;
|
||||
extern gboolean xterm_flag;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/tty/tty.h"
|
||||
#include "lib/tty/mouse.h"
|
||||
#include "lib/strutil.h"
|
||||
#include "lib/vfs/vfs.h"
|
||||
#include "lib/util.h" /* x_basename() */
|
||||
@ -410,9 +409,6 @@ mc_setup_by_args (int argc, char *argv[])
|
||||
const char *base;
|
||||
char *tmp;
|
||||
|
||||
if (mc_args__nomouse)
|
||||
use_mouse_p = MOUSE_DISABLED;
|
||||
|
||||
if (mc_args__netfs_logfile != NULL)
|
||||
{
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
|
@ -37,14 +37,13 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h> /* for username in xterm title */
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
#include "lib/tty/tty.h"
|
||||
#include "lib/tty/key.h" /* For init_key() */
|
||||
#include "lib/tty/mouse.h"
|
||||
#include "lib/tty/key.h" /* For init_key() */
|
||||
#include "lib/tty/win.h" /* xterm_flag */
|
||||
#include "lib/skin.h"
|
||||
#include "lib/util.h"
|
||||
@ -807,69 +806,6 @@ ctl_x_cmd (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_xterm_support (void)
|
||||
{
|
||||
const char *termvalue;
|
||||
|
||||
termvalue = getenv ("TERM");
|
||||
if (!termvalue || !(*termvalue))
|
||||
{
|
||||
fputs (_("The TERM environment variable is unset!\n"), stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Check mouse capabilities */
|
||||
xmouse_seq = tty_tgetstr ("Km");
|
||||
|
||||
if (strcmp (termvalue, "cygwin") == 0)
|
||||
{
|
||||
mc_args__force_xterm = 1;
|
||||
use_mouse_p = MOUSE_DISABLED;
|
||||
}
|
||||
|
||||
if (mc_args__force_xterm || strncmp (termvalue, "xterm", 5) == 0
|
||||
|| strncmp (termvalue, "konsole", 7) == 0
|
||||
|| strncmp (termvalue, "rxvt", 4) == 0
|
||||
|| strcmp (termvalue, "Eterm") == 0 || strcmp (termvalue, "dtterm") == 0)
|
||||
{
|
||||
xterm_flag = 1;
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
/* 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);
|
||||
#endif
|
||||
|
||||
/* Default to the standard xterm sequence */
|
||||
if (!xmouse_seq)
|
||||
{
|
||||
xmouse_seq = ESC_STR "[M";
|
||||
}
|
||||
|
||||
/* Enable mouse unless explicitly disabled by --nomouse */
|
||||
if (use_mouse_p != MOUSE_DISABLED)
|
||||
{
|
||||
const char *color_term = getenv ("COLORTERM");
|
||||
if (strncmp (termvalue, "rxvt", 4) == 0 ||
|
||||
(color_term != NULL && strncmp (color_term, "rxvt", 4) == 0) ||
|
||||
strcmp (termvalue, "Eterm") == 0)
|
||||
{
|
||||
use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
|
||||
}
|
||||
else
|
||||
{
|
||||
use_mouse_p = MOUSE_XTERM_BUTTON_EVENT_TRACKING;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
setup_mc (void)
|
||||
{
|
||||
@ -898,9 +834,6 @@ setup_mc (void)
|
||||
|
||||
if ((tty_baudrate () < 9600) || tty_is_slow ())
|
||||
verbose = 0;
|
||||
|
||||
init_xterm_support ();
|
||||
init_mouse ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
10
src/main.c
10
src/main.c
@ -411,6 +411,13 @@ main (int argc, char *argv[])
|
||||
if (!mc_args_handle (argc, argv, "mc"))
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
/* check terminal type
|
||||
* $TEMR must be set and not empty
|
||||
* xterm_flag is used in init_key() and tty_init()
|
||||
* Do this after mc_args_handle() where mc_args__force_xterm is set up.
|
||||
*/
|
||||
xterm_flag = tty_check_term (mc_args__force_xterm);
|
||||
|
||||
/* NOTE: This has to be called before tty_init or whatever routine
|
||||
calls any define_sequence */
|
||||
init_key ();
|
||||
@ -435,7 +442,8 @@ main (int argc, char *argv[])
|
||||
|
||||
/* Must be done before init_subshell, to set up the terminal size: */
|
||||
/* FIXME: Should be removed and LINES and COLS computed on subshell */
|
||||
tty_init (mc_global.args.slow_terminal, mc_global.args.ugly_line_drawing);
|
||||
tty_init (mc_global.args.slow_terminal, mc_global.args.ugly_line_drawing, !mc_args__nomouse,
|
||||
xterm_flag);
|
||||
|
||||
load_setup ();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user