2009-06-12 14:55:06 +04:00
|
|
|
/*
|
|
|
|
Interface to the terminal controlling library.
|
|
|
|
Ncurses wrapper.
|
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2005-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2009-06-12 14:55:06 +04:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
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: 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>
|
2012-10-15 16:03:04 +04:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#include <termios.h>
|
2009-05-10 19:01:15 +04: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 */
|
2010-01-21 15:17:26 +03:00
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
#ifndef WANT_TERM_H
|
2010-11-08 13:21:45 +03:00
|
|
|
#define WANT_TERM_H
|
2009-05-10 19:01:15 +04:00
|
|
|
#endif
|
|
|
|
|
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"
|
2020-07-19 19:47:15 +03:00
|
|
|
#include "color.h" /* tty_setcolor */
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "color-internal.h"
|
2013-12-02 16:42:01 +04:00
|
|
|
#include "key.h"
|
2011-09-01 11:09:55 +04:00
|
|
|
#include "mouse.h"
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "win.h"
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
/* include at last !!! */
|
|
|
|
#ifdef WANT_TERM_H
|
2010-01-17 15:51:07 +03:00
|
|
|
#ifdef HAVE_NCURSES_TERM_H
|
2010-11-08 13:21:45 +03:00
|
|
|
#include <ncurses/term.h>
|
2010-01-17 15:51:07 +03:00
|
|
|
#else
|
2010-11-08 13:21:45 +03:00
|
|
|
#include <term.h>
|
2010-01-17 15:51:07 +03:00
|
|
|
#endif /* HAVE_NCURSES_TERM_H */
|
2009-09-17 02:07:04 +04:00
|
|
|
#endif /* WANT_TERM_H */
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2010-02-06 13:07:35 +03:00
|
|
|
|
2014-09-27 21:03:17 +04:00
|
|
|
#if !defined(CTRL)
|
2010-11-08 13:21:45 +03:00
|
|
|
#define CTRL(x) ((x) & 0x1f)
|
2010-01-17 15:51:07 +03:00
|
|
|
#endif
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2011-11-01 12:43:00 +04:00
|
|
|
#define yx_in_screen(y, x) \
|
|
|
|
(y >= 0 && y < LINES && x >= 0 && x < COLS)
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2009-05-10 19:01:15 +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 ************************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2011-11-01 12:43:00 +04:00
|
|
|
/* ncurses supports cursor positions only within window */
|
2016-08-10 09:54:04 +03:00
|
|
|
/* We use our own cursor coordinates to support partially visible widgets */
|
2011-11-01 12:43:00 +04:00
|
|
|
static int mc_curs_row, mc_curs_col;
|
|
|
|
|
2010-11-08 13:21:45 +03: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
|
|
|
/*** file scope functions ************************************************************************/
|
2011-09-01 11:21:47 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tty_setup_sigwinch (void (*handler) (int))
|
|
|
|
{
|
|
|
|
#if (NCURSES_VERSION_MAJOR >= 4) && defined (SIGWINCH)
|
|
|
|
struct sigaction act, oact;
|
2013-09-29 10:59:47 +04:00
|
|
|
|
2013-11-17 09:55:18 +04:00
|
|
|
memset (&act, 0, sizeof (act));
|
2011-09-01 11:21:47 +04:00
|
|
|
act.sa_handler = handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
#ifdef SA_RESTART
|
2013-09-29 10:59:47 +04:00
|
|
|
act.sa_flags = SA_RESTART;
|
2011-09-01 11:21:47 +04:00
|
|
|
#endif /* SA_RESTART */
|
|
|
|
sigaction (SIGWINCH, &act, &oact);
|
|
|
|
#endif /* SIGWINCH */
|
2019-08-17 17:55:50 +03:00
|
|
|
|
|
|
|
tty_create_winch_pipe ();
|
2011-09-01 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-10-26 13:42:35 +04:00
|
|
|
static void
|
2011-09-01 11:21:47 +04:00
|
|
|
sigwinch_handler (int dummy)
|
|
|
|
{
|
2019-08-17 17:55:50 +03:00
|
|
|
ssize_t n = 0;
|
|
|
|
|
2011-09-01 11:21:47 +04:00
|
|
|
(void) dummy;
|
|
|
|
|
2019-08-17 17:55:50 +03:00
|
|
|
n = write (sigwinch_pipe[1], "", 1);
|
|
|
|
(void) n;
|
2011-09-01 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get visible part of area.
|
|
|
|
*
|
|
|
|
* @returns TRUE if any part of area is in screen bounds, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
tty_clip (int *y, int *x, int *rows, int *cols)
|
|
|
|
{
|
|
|
|
if (*y < 0)
|
|
|
|
{
|
|
|
|
*rows += *y;
|
|
|
|
|
|
|
|
if (*rows <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*x < 0)
|
|
|
|
{
|
|
|
|
*cols += *x;
|
|
|
|
|
|
|
|
if (*cols <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*y + *rows > LINES)
|
|
|
|
*rows = LINES - *y;
|
2021-02-03 09:47:13 +03:00
|
|
|
|
|
|
|
if (*rows <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
if (*x + *cols > COLS)
|
|
|
|
*cols = COLS - *x;
|
|
|
|
|
2021-02-03 09:47:13 +03:00
|
|
|
if (*cols <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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 *ch)
|
2009-09-14 17:43:03 +04:00
|
|
|
{
|
2009-09-28 12:04:54 +04:00
|
|
|
char *str2;
|
|
|
|
int res;
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
struct mc_tty_lines_struct
|
|
|
|
{
|
2009-09-14 17:43:03 +04:00
|
|
|
const char *line;
|
|
|
|
int line_code;
|
2009-09-17 02:07:04 +04:00
|
|
|
} const lines_codes[] = {
|
2010-04-14 14:35:26 +04:00
|
|
|
{"\342\224\230", ACS_LRCORNER}, /* ┌ */
|
|
|
|
{"\342\224\224", ACS_LLCORNER}, /* └ */
|
|
|
|
{"\342\224\220", ACS_URCORNER}, /* ┐ */
|
|
|
|
{"\342\224\214", ACS_ULCORNER}, /* ┘ */
|
2010-04-06 11:16:11 +04:00
|
|
|
{"\342\224\234", ACS_LTEE}, /* ├ */
|
|
|
|
{"\342\224\244", ACS_RTEE}, /* ┤ */
|
|
|
|
{"\342\224\254", ACS_TTEE}, /* ┬ */
|
|
|
|
{"\342\224\264", ACS_BTEE}, /* ┴ */
|
|
|
|
{"\342\224\200", ACS_HLINE}, /* ─ */
|
|
|
|
{"\342\224\202", ACS_VLINE}, /* │ */
|
|
|
|
{"\342\224\274", ACS_PLUS}, /* ┼ */
|
|
|
|
|
|
|
|
{"\342\225\235", ACS_LRCORNER | A_BOLD}, /* ╔ */
|
2010-04-14 14:35:26 +04:00
|
|
|
{"\342\225\232", ACS_LLCORNER | A_BOLD}, /* ╚ */
|
|
|
|
{"\342\225\227", ACS_URCORNER | A_BOLD}, /* ╗ */
|
2010-04-06 11:16:11 +04:00
|
|
|
{"\342\225\224", ACS_ULCORNER | A_BOLD}, /* ╝ */
|
|
|
|
{"\342\225\237", ACS_LTEE | A_BOLD}, /* ╟ */
|
|
|
|
{"\342\225\242", ACS_RTEE | A_BOLD}, /* ╢ */
|
|
|
|
{"\342\225\244", ACS_TTEE | A_BOLD}, /* ╤ */
|
|
|
|
{"\342\225\247", ACS_BTEE | A_BOLD}, /* ╧ */
|
|
|
|
{"\342\225\220", ACS_HLINE | A_BOLD}, /* ═ */
|
|
|
|
{"\342\225\221", ACS_VLINE | A_BOLD}, /* ║ */
|
2009-09-28 12:04:54 +04:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
{NULL, 0}
|
2009-09-14 17:43:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (ch == NULL)
|
2009-09-17 02:07:04 +04:00
|
|
|
return (int) ' ';
|
2009-09-14 17:43:03 +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 (ch, lines_codes[res].line) == 0)
|
|
|
|
return lines_codes[res].line_code;
|
2009-09-14 17:43:03 +04:00
|
|
|
}
|
|
|
|
|
2009-09-28 12:04:54 +04:00
|
|
|
str2 = mc_tty_normalize_from_utf8 (ch);
|
|
|
|
res = g_utf8_get_char_validated (str2, -1);
|
|
|
|
|
|
|
|
if (res < 0)
|
|
|
|
res = (unsigned char) str2[0];
|
|
|
|
g_free (str2);
|
2009-09-14 17:43:03 +04:00
|
|
|
|
2009-09-28 12:04:54 +04:00
|
|
|
return res;
|
2009-09-14 17:43:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-13 17:05:55 +04:00
|
|
|
void
|
2011-09-06 19:24:18 +04:00
|
|
|
tty_init (gboolean mouse_enable, gboolean is_xterm)
|
2009-05-13 17:05:55 +04:00
|
|
|
{
|
2017-04-14 14:06:13 +03:00
|
|
|
struct termios mode;
|
|
|
|
|
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 */
|
|
|
|
|
2017-04-14 14:06:13 +03:00
|
|
|
tcgetattr (STDIN_FILENO, &mode);
|
2009-12-23 19:18:25 +03:00
|
|
|
/* use Ctrl-g to generate SIGINT */
|
2017-04-14 18:54:22 +03:00
|
|
|
mode.c_cc[VINTR] = CTRL ('g'); /* ^g */
|
2010-02-06 13:07:35 +03:00
|
|
|
/* disable SIGQUIT to allow use Ctrl-\ key */
|
2017-04-14 14:06:13 +03:00
|
|
|
mode.c_cc[VQUIT] = NULL_VALUE;
|
|
|
|
tcsetattr (STDIN_FILENO, TCSANOW, &mode);
|
|
|
|
|
|
|
|
/* curses remembers the "in-program" modes after this call */
|
|
|
|
def_prog_mode ();
|
2009-12-23 19:18:25 +03:00
|
|
|
|
2009-08-04 22:06:26 +04:00
|
|
|
tty_start_interrupt_key ();
|
|
|
|
|
2011-09-01 11:09:55 +04:00
|
|
|
if (!mouse_enable)
|
|
|
|
use_mouse_p = MOUSE_DISABLED;
|
2016-05-04 13:29:47 +03:00
|
|
|
tty_init_xterm_support (is_xterm); /* do it before tty_enter_ca_mode() call */
|
|
|
|
tty_enter_ca_mode ();
|
2009-12-23 19:18:25 +03:00
|
|
|
tty_raw_mode ();
|
2009-05-13 17:05:55 +04:00
|
|
|
noecho ();
|
|
|
|
keypad (stdscr, TRUE);
|
|
|
|
nodelay (stdscr, FALSE);
|
2011-09-01 11:21:47 +04:00
|
|
|
|
|
|
|
tty_setup_sigwinch (sigwinch_handler);
|
2009-05-13 17:05:55 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
|
|
|
tty_shutdown (void)
|
|
|
|
{
|
2020-02-02 14:38:31 +03:00
|
|
|
tty_destroy_winch_pipe ();
|
2011-09-01 16:40:40 +04:00
|
|
|
tty_reset_shell_mode ();
|
|
|
|
tty_noraw_mode ();
|
|
|
|
tty_keypad (FALSE);
|
|
|
|
tty_reset_screen ();
|
2016-05-04 13:29:47 +03:00
|
|
|
tty_exit_ca_mode ();
|
2009-06-02 21:40:37 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-05-03 13:08:01 +03:00
|
|
|
void
|
|
|
|
tty_enter_ca_mode (void)
|
|
|
|
{
|
|
|
|
if (mc_global.tty.xterm_flag && smcup != NULL)
|
|
|
|
{
|
|
|
|
fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h");
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_exit_ca_mode (void)
|
|
|
|
{
|
|
|
|
if (mc_global.tty.xterm_flag && rmcup != NULL)
|
|
|
|
{
|
|
|
|
fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2012-10-15 16:03:04 +04:00
|
|
|
void
|
|
|
|
tty_change_screen_size (void)
|
|
|
|
{
|
|
|
|
#if defined(TIOCGWINSZ) && NCURSES_VERSION_MAJOR >= 4
|
|
|
|
struct winsize winsz;
|
|
|
|
|
|
|
|
winsz.ws_col = winsz.ws_row = 0;
|
|
|
|
|
|
|
|
#ifndef NCURSES_VERSION
|
|
|
|
tty_noraw_mode ();
|
|
|
|
tty_reset_screen ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Ioctl on the STDIN_FILENO */
|
|
|
|
ioctl (fileno (stdout), TIOCGWINSZ, &winsz);
|
|
|
|
if (winsz.ws_col != 0 && winsz.ws_row != 0)
|
|
|
|
{
|
|
|
|
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
|
|
|
|
resizeterm (winsz.ws_row, winsz.ws_col);
|
|
|
|
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
|
|
|
|
#else
|
|
|
|
COLS = winsz.ws_col;
|
|
|
|
LINES = winsz.ws_row;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* defined(TIOCGWINSZ) || NCURSES_VERSION_MAJOR >= 4 */
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_reset_prog_mode (void)
|
|
|
|
{
|
|
|
|
reset_prog_mode ();
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_reset_shell_mode (void)
|
|
|
|
{
|
|
|
|
reset_shell_mode ();
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-19 20:12:29 +04:00
|
|
|
void
|
|
|
|
tty_raw_mode (void)
|
|
|
|
{
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
raw (); /* FIXME: unneeded? */
|
2009-12-23 19:18:25 +03:00
|
|
|
cbreak ();
|
2009-05-19 20:12:29 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-19 20:12:29 +04:00
|
|
|
void
|
|
|
|
tty_noraw_mode (void)
|
|
|
|
{
|
2010-04-06 11:16:11 +04:00
|
|
|
nocbreak (); /* FIXME: unneeded? */
|
2009-05-19 20:12:29 +04:00
|
|
|
noraw ();
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
void
|
|
|
|
tty_noecho (void)
|
|
|
|
{
|
|
|
|
noecho ();
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
int
|
|
|
|
tty_flush_input (void)
|
|
|
|
{
|
|
|
|
return flushinp ();
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_keypad (gboolean set)
|
|
|
|
{
|
|
|
|
keypad (stdscr, (bool) set);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_nodelay (gboolean set)
|
|
|
|
{
|
|
|
|
nodelay (stdscr, (bool) set);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
int
|
|
|
|
tty_baudrate (void)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
return baudrate ();
|
2009-06-19 21:33:41 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-19 21:33:41 +04:00
|
|
|
int
|
|
|
|
tty_lowlevel_getch (void)
|
|
|
|
{
|
|
|
|
return getch ();
|
2009-06-02 08:55:07 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 21:40:37 +04:00
|
|
|
int
|
|
|
|
tty_reset_screen (void)
|
|
|
|
{
|
|
|
|
return endwin ();
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
void
|
|
|
|
tty_touch_screen (void)
|
|
|
|
{
|
|
|
|
touchwin (stdscr);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_gotoyx (int y, int x)
|
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
mc_curs_row = y;
|
|
|
|
mc_curs_col = x;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
if (y >= LINES)
|
|
|
|
y = LINES - 1;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
if (x >= COLS)
|
|
|
|
x = COLS - 1;
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
move (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)
|
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
*py = mc_curs_row;
|
|
|
|
*px = mc_curs_col;
|
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;
|
|
|
|
|
|
|
|
x1 = x;
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
len += x;
|
|
|
|
if (len <= 0)
|
|
|
|
return;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
if ((chtype) ch == ACS_HLINE)
|
2010-03-21 20:50:20 +03:00
|
|
|
ch = mc_tty_frm[MC_TTY_FRM_HORIZ];
|
2009-08-24 00:42:28 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
move (y, x);
|
2009-06-03 23:07:06 +04:00
|
|
|
hline (ch, len);
|
2011-01-14 20:52:40 +03:00
|
|
|
move (y, x1);
|
2011-11-01 12:43:00 +04:00
|
|
|
|
|
|
|
mc_curs_row = y;
|
|
|
|
mc_curs_col = 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;
|
|
|
|
|
|
|
|
y1 = y;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
|
|
|
len += y;
|
|
|
|
if (len <= 0)
|
|
|
|
return;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
if ((chtype) ch == ACS_VLINE)
|
2010-03-21 20:50:20 +03:00
|
|
|
ch = mc_tty_frm[MC_TTY_FRM_VERT];
|
2009-09-14 17:43:03 +04:00
|
|
|
|
2011-01-14 20:52:40 +03:00
|
|
|
move (y, x);
|
2009-06-03 23:07:06 +04:00
|
|
|
vline (ch, len);
|
2011-01-14 20:52:40 +03:00
|
|
|
move (y1, x);
|
2011-11-01 12:43:00 +04:00
|
|
|
|
|
|
|
mc_curs_row = y1;
|
|
|
|
mc_curs_col = 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)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
if (!tty_clip (&y, &x, &rows, &cols))
|
|
|
|
return;
|
2010-05-13 17:21:49 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
for (i = 0; i < rows; i++)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
move (y + i, x);
|
|
|
|
hline (ch, cols);
|
2009-05-26 18:56:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
move (y, x);
|
2011-11-01 12:43:00 +04:00
|
|
|
|
|
|
|
mc_curs_row = y;
|
|
|
|
mc_curs_col = x;
|
2009-05-26 18:56:42 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2020-07-19 19:47:15 +03:00
|
|
|
void
|
|
|
|
tty_colorize_area (int y, int x, int rows, int cols, int color)
|
|
|
|
{
|
2021-08-28 11:46:53 +03:00
|
|
|
#ifdef ENABLE_SHADOWS
|
2020-07-19 19:47:15 +03:00
|
|
|
cchar_t *ctext;
|
2020-08-05 10:49:50 +03:00
|
|
|
wchar_t wch[10]; /* TODO not sure if the length is correct */
|
2020-07-19 19:47:15 +03:00
|
|
|
attr_t attrs;
|
|
|
|
short color_pair;
|
|
|
|
|
|
|
|
if (!use_colors || !tty_clip (&y, &x, &rows, &cols))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tty_setcolor (color);
|
|
|
|
ctext = g_malloc (sizeof (cchar_t) * (cols + 1));
|
|
|
|
|
|
|
|
for (int row = 0; row < rows; row++)
|
|
|
|
{
|
|
|
|
mvin_wchnstr (y + row, x, ctext, cols);
|
|
|
|
|
|
|
|
for (int col = 0; col < cols; col++)
|
|
|
|
{
|
|
|
|
getcchar (&ctext[col], wch, &attrs, &color_pair, NULL);
|
|
|
|
setcchar (&ctext[col], wch, attrs, color, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
mvadd_wchnstr (y + row, x, ctext, cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (ctext);
|
2021-08-28 11:46:53 +03:00
|
|
|
#else
|
|
|
|
(void) y;
|
|
|
|
(void) x;
|
|
|
|
(void) rows;
|
|
|
|
(void) cols;
|
|
|
|
(void) color;
|
|
|
|
#endif /* ENABLE_SHADOWS */
|
2020-07-19 19:47:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
void
|
|
|
|
tty_set_alt_charset (gboolean alt_charset)
|
|
|
|
{
|
|
|
|
(void) alt_charset;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-08 13:49:46 +04:00
|
|
|
void
|
|
|
|
tty_display_8bit (gboolean what)
|
|
|
|
{
|
|
|
|
meta (stdscr, (int) what);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
|
|
|
tty_print_char (int c)
|
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
if (yx_in_screen (mc_curs_row, mc_curs_col))
|
|
|
|
addch (c);
|
|
|
|
mc_curs_col++;
|
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)
|
|
|
|
{
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.utf8_display || c > 255)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
int res;
|
2013-12-02 16:42:01 +04:00
|
|
|
unsigned char str[UTF8_CHAR_LEN + 1];
|
2011-11-01 12:43:00 +04:00
|
|
|
|
|
|
|
res = g_unichar_to_utf8 (c, (char *) str);
|
2010-04-06 11:16:11 +04:00
|
|
|
if (res == 0)
|
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
if (yx_in_screen (mc_curs_row, mc_curs_col))
|
|
|
|
addch ('.');
|
|
|
|
mc_curs_col++;
|
2009-10-13 14:46:28 +04:00
|
|
|
}
|
2010-04-06 11:16:11 +04:00
|
|
|
else
|
2011-11-01 12:43:00 +04:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
str[res] = '\0';
|
2011-11-01 12:43:00 +04:00
|
|
|
s = str_term_form ((char *) str);
|
|
|
|
|
|
|
|
if (yx_in_screen (mc_curs_row, mc_curs_col))
|
|
|
|
addstr (s);
|
|
|
|
|
|
|
|
if (g_unichar_iswide (c))
|
|
|
|
mc_curs_col += 2;
|
|
|
|
else if (!g_unichar_iszerowidth (c))
|
|
|
|
mc_curs_col++;
|
|
|
|
}
|
2009-08-13 09:59:31 +04:00
|
|
|
}
|
2010-04-06 11:16:11 +04:00
|
|
|
else
|
2011-11-01 12:43:00 +04:00
|
|
|
{
|
|
|
|
if (yx_in_screen (mc_curs_row, mc_curs_col))
|
|
|
|
addch (c);
|
|
|
|
mc_curs_col++;
|
|
|
|
}
|
2009-08-13 09:59:31 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
void
|
2010-03-18 21:24:28 +03:00
|
|
|
tty_print_alt_char (int c, gboolean single)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
if (yx_in_screen (mc_curs_row, mc_curs_col))
|
|
|
|
{
|
|
|
|
if ((chtype) c == ACS_VLINE)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT];
|
|
|
|
else if ((chtype) c == ACS_HLINE)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ];
|
|
|
|
else if ((chtype) c == ACS_LTEE)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_LEFTMIDDLE : MC_TTY_FRM_DLEFTMIDDLE];
|
|
|
|
else if ((chtype) c == ACS_RTEE)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_RIGHTMIDDLE : MC_TTY_FRM_DRIGHTMIDDLE];
|
|
|
|
else if ((chtype) c == ACS_ULCORNER)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_LEFTTOP : MC_TTY_FRM_DLEFTTOP];
|
|
|
|
else if ((chtype) c == ACS_LLCORNER)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_LEFTBOTTOM : MC_TTY_FRM_DLEFTBOTTOM];
|
|
|
|
else if ((chtype) c == ACS_URCORNER)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_RIGHTTOP : MC_TTY_FRM_DRIGHTTOP];
|
|
|
|
else if ((chtype) c == ACS_LRCORNER)
|
|
|
|
c = mc_tty_frm[single ? MC_TTY_FRM_RIGHTBOTTOM : MC_TTY_FRM_DRIGHTBOTTOM];
|
|
|
|
else if ((chtype) c == ACS_PLUS)
|
|
|
|
c = mc_tty_frm[MC_TTY_FRM_CROSS];
|
2009-09-14 17:43:03 +04:00
|
|
|
|
2011-11-01 12:43:00 +04:00
|
|
|
addch (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
mc_curs_col++;
|
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
|
2009-05-13 12:38:11 +04:00
|
|
|
tty_print_string (const char *s)
|
2009-05-10 19:01:15 +04:00
|
|
|
{
|
2011-11-01 12:43:00 +04:00
|
|
|
int len;
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
s = str_term_form (s);
|
|
|
|
len = str_term_width1 (s);
|
|
|
|
|
2016-04-25 10:35:17 +03:00
|
|
|
/* line is upper or below the screen or entire line is before or after screen */
|
2011-11-01 12:43:00 +04:00
|
|
|
if (mc_curs_row < 0 || mc_curs_row >= LINES || mc_curs_col + len <= 0 || mc_curs_col >= COLS)
|
|
|
|
{
|
|
|
|
mc_curs_col += len;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip invisible left part */
|
|
|
|
if (mc_curs_col < 0)
|
|
|
|
{
|
|
|
|
start = -mc_curs_col;
|
|
|
|
len += mc_curs_col;
|
|
|
|
mc_curs_col = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mc_curs_col += len;
|
|
|
|
if (mc_curs_col >= COLS)
|
|
|
|
len = COLS - (mc_curs_col - len);
|
|
|
|
|
|
|
|
addstr (str_term_substring (s, start, len));
|
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;
|
2011-11-01 12:43:00 +04:00
|
|
|
char buf[BUF_1K]; /* FIXME: is it enough? */
|
2009-05-10 19:01:15 +04:00
|
|
|
|
|
|
|
va_start (args, fmt);
|
2011-11-01 12:43:00 +04:00
|
|
|
g_vsnprintf (buf, sizeof (buf), fmt, args);
|
2009-05-10 19:01:15 +04:00
|
|
|
va_end (args);
|
2011-11-01 12:43:00 +04:00
|
|
|
tty_print_string (buf);
|
2009-05-10 19:01:15 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-10 19:01:15 +04:00
|
|
|
char *
|
|
|
|
tty_tgetstr (const char *cap)
|
|
|
|
{
|
|
|
|
char *unused = NULL;
|
2016-04-18 16:16:12 +03:00
|
|
|
|
|
|
|
return tgetstr ((NCURSES_CONST char *) cap, &unused);
|
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
|
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
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-05-31 16:23:10 +04:00
|
|
|
void
|
|
|
|
tty_beep (void)
|
|
|
|
{
|
|
|
|
beep ();
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|