2005-08-29 12:45:28 +04:00
|
|
|
/*
|
|
|
|
Interface to the terminal controlling library.
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2005-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2005-08-29 12:45:28 +04:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Roland Illig <roland.illig@gmx.de>, 2005.
|
2009-06-12 14:55:06 +04:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
2005-08-29 12:45:28 +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
|
2005-08-29 12:45:28 +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.
|
2005-08-29 12:45:28 +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.
|
2005-08-29 12:45:28 +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/>.
|
2005-08-29 12:45:28 +04:00
|
|
|
*/
|
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file tty.c
|
2009-02-06 17:46:15 +03:00
|
|
|
* \brief Source: %interface to the terminal controlling library
|
2009-02-05 21:28:18 +03:00
|
|
|
*/
|
|
|
|
|
2005-08-29 12:45:28 +04:00
|
|
|
#include <config.h>
|
|
|
|
|
2019-08-17 17:55:50 +03:00
|
|
|
#include <errno.h>
|
2005-08-29 12:45:28 +04:00
|
|
|
#include <signal.h>
|
2005-09-05 02:02:25 +04:00
|
|
|
#include <stdarg.h>
|
2011-09-01 11:09:55 +04:00
|
|
|
#include <stdlib.h>
|
2013-11-17 09:55:18 +04:00
|
|
|
#include <string.h> /* memset() */
|
2019-09-21 20:44:51 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
#include <sys/select.h>
|
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2011-09-06 19:24:18 +04:00
|
|
|
#include <unistd.h> /* exit() */
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2011-02-18 14:30:15 +03:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
2020-06-24 19:57:02 +03:00
|
|
|
/* In some systems (like Solaris 11.4 SPARC), TIOCSWINSZ is defined in termios.h */
|
|
|
|
#include <termios.h>
|
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2024-07-28 19:50:55 +03:00
|
|
|
#include "lib/util.h"
|
2006-05-15 17:26:18 +04:00
|
|
|
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "tty.h"
|
|
|
|
#include "tty-internal.h"
|
2020-10-31 14:26:10 +03:00
|
|
|
#include "color.h" /* tty_set_normal_attrs() */
|
2011-09-06 19:24:18 +04:00
|
|
|
#include "mouse.h" /* use_mouse_p */
|
2011-02-18 14:30:15 +03:00
|
|
|
#include "win.h"
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2010-03-21 20:50:20 +03:00
|
|
|
int mc_tty_frm[MC_TTY_FRM_MAX];
|
2009-08-24 00:42:28 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2005-08-29 12:45:28 +04:00
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2012-10-31 11:33:50 +04:00
|
|
|
static SIG_ATOMIC_VOLATILE_T got_interrupt = 0;
|
2005-08-29 12:45:28 +04:00
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2005-08-29 12:45:28 +04:00
|
|
|
|
|
|
|
static void
|
2009-09-17 02:07:04 +04:00
|
|
|
sigintr_handler (int signo)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
|
|
|
(void) &signo;
|
|
|
|
got_interrupt = 1;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2011-09-01 11:09:55 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2021-05-29 13:50:30 +03:00
|
|
|
* @return true if @param force_xterm is true or value of $TERM is one of following:
|
|
|
|
* term*
|
|
|
|
* konsole*
|
|
|
|
* rxvt*
|
|
|
|
* Eterm
|
|
|
|
* dtterm
|
|
|
|
* alacritty*
|
2021-05-29 19:09:27 +03:00
|
|
|
* foot*
|
2021-04-13 16:28:51 +03:00
|
|
|
* screen*
|
2021-04-13 16:28:51 +03:00
|
|
|
* tmux*
|
2022-07-30 12:54:43 +03:00
|
|
|
* contour*
|
2011-09-01 11:09:55 +04:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-08-02 09:41:42 +03:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
return force_xterm
|
|
|
|
|| strncmp (termvalue, "xterm", 5) == 0
|
2011-09-01 11:09:55 +04:00
|
|
|
|| strncmp (termvalue, "konsole", 7) == 0
|
|
|
|
|| strncmp (termvalue, "rxvt", 4) == 0
|
2013-05-29 16:41:37 +04:00
|
|
|
|| strcmp (termvalue, "Eterm") == 0
|
|
|
|
|| strcmp (termvalue, "dtterm") == 0
|
2021-05-25 17:26:30 +03:00
|
|
|
|| strncmp (termvalue, "alacritty", 9) == 0
|
2021-05-29 19:09:27 +03:00
|
|
|
|| strncmp (termvalue, "foot", 4) == 0
|
2021-04-13 16:28:51 +03:00
|
|
|
|| strncmp (termvalue, "screen", 6) == 0
|
2022-07-30 12:54:43 +03:00
|
|
|
|| strncmp (termvalue, "tmux", 4) == 0
|
|
|
|
|| strncmp (termvalue, "contour", 7) == 0;
|
2021-08-02 09:41:42 +03:00
|
|
|
/* *INDENT-ON* */
|
2011-09-01 11:09:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-15 22:31:52 +04:00
|
|
|
extern void
|
2009-09-17 02:07:04 +04:00
|
|
|
tty_start_interrupt_key (void)
|
2009-07-15 22:31:52 +04:00
|
|
|
{
|
|
|
|
struct sigaction act;
|
|
|
|
|
2013-11-17 09:55:18 +04:00
|
|
|
memset (&act, 0, sizeof (act));
|
2009-07-15 22:31:52 +04:00
|
|
|
act.sa_handler = sigintr_handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
2013-09-29 10:59:47 +04:00
|
|
|
#ifdef SA_RESTART
|
2009-07-15 22:31:52 +04:00
|
|
|
act.sa_flags = SA_RESTART;
|
2013-10-04 09:26:08 +04:00
|
|
|
#endif /* SA_RESTART */
|
2024-07-28 19:50:55 +03:00
|
|
|
my_sigaction (SIGINT, &act, NULL);
|
2009-07-15 22:31:52 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2005-08-29 12:45:28 +04:00
|
|
|
extern void
|
2009-09-17 02:07:04 +04:00
|
|
|
tty_enable_interrupt_key (void)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
|
|
|
struct sigaction act;
|
2005-08-29 13:04:39 +04:00
|
|
|
|
2013-11-17 09:55:18 +04:00
|
|
|
memset (&act, 0, sizeof (act));
|
2005-08-29 12:45:28 +04:00
|
|
|
act.sa_handler = sigintr_handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
2024-07-28 19:50:55 +03:00
|
|
|
my_sigaction (SIGINT, &act, NULL);
|
2009-07-15 22:31:52 +04:00
|
|
|
got_interrupt = 0;
|
2005-08-29 12:45:28 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2005-08-29 12:45:28 +04:00
|
|
|
extern void
|
2009-09-17 02:07:04 +04:00
|
|
|
tty_disable_interrupt_key (void)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
|
|
|
struct sigaction act;
|
2005-08-29 13:04:39 +04:00
|
|
|
|
2013-11-17 09:55:18 +04:00
|
|
|
memset (&act, 0, sizeof (act));
|
2005-08-29 12:45:28 +04:00
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset (&act.sa_mask);
|
2024-07-28 19:50:55 +03:00
|
|
|
my_sigaction (SIGINT, &act, NULL);
|
2005-08-29 12:45:28 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-02-06 01:46:07 +03:00
|
|
|
extern gboolean
|
2009-09-17 02:07:04 +04:00
|
|
|
tty_got_interrupt (void)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
2009-02-06 01:46:07 +03:00
|
|
|
gboolean rv;
|
2005-08-29 12:45:28 +04:00
|
|
|
|
|
|
|
rv = (got_interrupt != 0);
|
|
|
|
got_interrupt = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2019-08-17 17:55:50 +03:00
|
|
|
gboolean
|
|
|
|
tty_got_winch (void)
|
|
|
|
{
|
2019-09-21 20:44:51 +03:00
|
|
|
fd_set fdset;
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
/* instant timeout */
|
|
|
|
struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 };
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
int ok;
|
|
|
|
|
|
|
|
FD_ZERO (&fdset);
|
|
|
|
FD_SET (sigwinch_pipe[0], &fdset);
|
|
|
|
|
|
|
|
while ((ok = select (sigwinch_pipe[0] + 1, &fdset, NULL, NULL, &timeout)) < 0)
|
|
|
|
if (errno != EINTR)
|
|
|
|
{
|
|
|
|
perror (_("Cannot check SIGWINCH pipe"));
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ok != 0 && FD_ISSET (sigwinch_pipe[0], &fdset));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_flush_winch (void)
|
|
|
|
{
|
2019-08-17 17:55:50 +03:00
|
|
|
ssize_t n;
|
|
|
|
|
|
|
|
/* merge all SIGWINCH events raised to this moment */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
char x[16];
|
|
|
|
|
|
|
|
/* read multiple events at a time */
|
|
|
|
n = read (sigwinch_pipe[0], &x, sizeof (x));
|
|
|
|
}
|
|
|
|
while (n > 0 || (n == -1 && errno == EINTR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-14 19:18:03 +04:00
|
|
|
void
|
2010-03-21 11:58:45 +03:00
|
|
|
tty_print_one_hline (gboolean single)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
2010-03-21 11:58:45 +03:00
|
|
|
tty_print_alt_char (ACS_HLINE, single);
|
2005-08-29 12:45:28 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-03 23:07:06 +04:00
|
|
|
void
|
2010-03-21 11:58:45 +03:00
|
|
|
tty_print_one_vline (gboolean single)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
2010-03-21 11:58:45 +03:00
|
|
|
tty_print_alt_char (ACS_VLINE, single);
|
2005-08-29 12:45:28 +04:00
|
|
|
}
|
2009-07-18 18:30:06 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-18 18:30:06 +04:00
|
|
|
void
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_draw_box (int y, int x, int ys, int xs, gboolean single)
|
2009-07-18 18:30:06 +04:00
|
|
|
{
|
2011-01-14 20:52:40 +03:00
|
|
|
int y2, x2;
|
|
|
|
|
2012-03-30 12:50:22 +04:00
|
|
|
if (ys <= 0 || xs <= 0)
|
|
|
|
return;
|
|
|
|
|
2010-04-05 22:02:31 +04:00
|
|
|
ys--;
|
|
|
|
xs--;
|
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
y2 = y + ys;
|
|
|
|
x2 = x + xs;
|
|
|
|
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_draw_vline (y, x, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
|
2011-01-14 20:52:40 +03:00
|
|
|
tty_draw_vline (y, x2, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_draw_hline (y, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
|
2011-01-14 20:52:40 +03:00
|
|
|
tty_draw_hline (y2, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
|
2010-03-18 21:44:35 +03:00
|
|
|
tty_gotoyx (y, x);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_print_alt_char (ACS_ULCORNER, single);
|
2011-01-14 20:52:40 +03:00
|
|
|
tty_gotoyx (y2, x);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_print_alt_char (ACS_LLCORNER, single);
|
2011-01-14 20:52:40 +03:00
|
|
|
tty_gotoyx (y, x2);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_print_alt_char (ACS_URCORNER, single);
|
2011-01-14 20:52:40 +03:00
|
|
|
tty_gotoyx (y2, x2);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_print_alt_char (ACS_LRCORNER, single);
|
2009-07-18 18:30:06 +04:00
|
|
|
}
|
2009-09-28 12:04:54 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
void
|
|
|
|
tty_draw_box_shadow (int y, int x, int rows, int cols, int shadow_color)
|
|
|
|
{
|
|
|
|
/* draw right shadow */
|
|
|
|
tty_colorize_area (y + 1, x + cols, rows - 1, 2, shadow_color);
|
|
|
|
/* draw bottom shadow */
|
|
|
|
tty_colorize_area (y + rows, x + 2, 1, cols, shadow_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-09-28 12:04:54 +04:00
|
|
|
char *
|
|
|
|
mc_tty_normalize_from_utf8 (const char *str)
|
|
|
|
{
|
|
|
|
GIConv conv;
|
|
|
|
GString *buffer;
|
|
|
|
const char *_system_codepage = str_detect_termencoding ();
|
|
|
|
|
|
|
|
if (str_isutf8 (_system_codepage))
|
|
|
|
return g_strdup (str);
|
|
|
|
|
|
|
|
conv = g_iconv_open (_system_codepage, "UTF-8");
|
|
|
|
if (conv == INVALID_CONV)
|
|
|
|
return g_strdup (str);
|
|
|
|
|
|
|
|
buffer = g_string_new ("");
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
if (str_convert (conv, str, buffer) == ESTR_FAILURE)
|
|
|
|
{
|
2009-09-28 12:04:54 +04:00
|
|
|
g_string_free (buffer, TRUE);
|
|
|
|
str_close_conv (conv);
|
|
|
|
return g_strdup (str);
|
|
|
|
}
|
|
|
|
str_close_conv (conv);
|
|
|
|
|
|
|
|
return g_string_free (buffer, FALSE);
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2011-02-18 14:30:15 +03:00
|
|
|
|
|
|
|
/** Resize given terminal using TIOCSWINSZ, return ioctl() result */
|
|
|
|
int
|
|
|
|
tty_resize (int fd)
|
|
|
|
{
|
|
|
|
#if defined TIOCSWINSZ
|
|
|
|
struct winsize tty_size;
|
|
|
|
|
|
|
|
tty_size.ws_row = LINES;
|
|
|
|
tty_size.ws_col = COLS;
|
|
|
|
tty_size.ws_xpixel = tty_size.ws_ypixel = 0;
|
|
|
|
|
|
|
|
return ioctl (fd, TIOCSWINSZ, &tty_size);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2020-10-31 14:26:10 +03:00
|
|
|
/** Clear screen */
|
|
|
|
void
|
|
|
|
tty_clear_screen (void)
|
|
|
|
{
|
|
|
|
tty_set_normal_attrs ();
|
|
|
|
tty_fill_region (0, 0, LINES, COLS, ' ');
|
|
|
|
tty_refresh ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-09-01 11:09:55 +04:00
|
|
|
void
|
|
|
|
tty_init_xterm_support (gboolean is_xterm)
|
|
|
|
{
|
|
|
|
const char *termvalue;
|
|
|
|
|
|
|
|
termvalue = getenv ("TERM");
|
|
|
|
|
2011-09-02 13:30:59 +04:00
|
|
|
/* Check mouse and ca capabilities */
|
|
|
|
/* terminfo/termcap structures have been already initialized,
|
|
|
|
in slang_init() or/and init_curses() */
|
|
|
|
/* Check terminfo at first, then check termcap */
|
|
|
|
xmouse_seq = tty_tgetstr ("kmous");
|
|
|
|
if (xmouse_seq == NULL)
|
|
|
|
xmouse_seq = tty_tgetstr ("Km");
|
|
|
|
smcup = tty_tgetstr ("smcup");
|
|
|
|
if (smcup == NULL)
|
|
|
|
smcup = tty_tgetstr ("ti");
|
|
|
|
rmcup = tty_tgetstr ("rmcup");
|
|
|
|
if (rmcup == NULL)
|
|
|
|
rmcup = tty_tgetstr ("te");
|
2011-09-01 11:09:55 +04:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-09-07 13:06:03 +04:00
|
|
|
if (mc_global.tty.old_mouse)
|
2011-09-01 11:09:55 +04:00
|
|
|
use_mouse_p = MOUSE_XTERM_NORMAL_TRACKING;
|
|
|
|
else
|
2011-09-07 11:17:03 +04:00
|
|
|
{
|
|
|
|
/* FIXME: this dirty hack to set supported type of tracking the mouse */
|
|
|
|
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;
|
|
|
|
}
|
2011-09-01 11:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-13 13:37:50 +04:00
|
|
|
|
2020-02-15 00:14:19 +03:00
|
|
|
/* There's only one termcap entry "kmous", typically containing "\E[M" or "\E[<".
|
|
|
|
* We need the former in xmouse_seq, the latter in xmouse_extended_seq.
|
2020-06-16 21:58:25 +03:00
|
|
|
* See tickets 2956, 3954, and 4063 for details. */
|
2013-02-13 13:37:50 +04:00
|
|
|
if (xmouse_seq != NULL)
|
2020-02-15 00:14:19 +03:00
|
|
|
{
|
|
|
|
if (strcmp (xmouse_seq, ESC_STR "[<") == 0)
|
2020-06-16 21:58:25 +03:00
|
|
|
xmouse_seq = ESC_STR "[M";
|
2020-02-15 00:14:19 +03:00
|
|
|
|
2013-02-13 13:37:50 +04:00
|
|
|
xmouse_extended_seq = ESC_STR "[<";
|
2020-02-15 00:14:19 +03:00
|
|
|
}
|
2011-09-01 11:09:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|