2005-08-29 08:45:28 +00:00
|
|
|
/*
|
|
|
|
Interface to the terminal controlling library.
|
|
|
|
|
2009-06-12 13:55:06 +03:00
|
|
|
Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
|
2005-08-29 08:45:28 +00:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Roland Illig <roland.illig@gmx.de>, 2005.
|
2009-06-12 13:55:06 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
2005-08-29 08:45:28 +00:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be
|
|
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2009-02-05 20:28:18 +02:00
|
|
|
/** \file tty.c
|
2009-02-06 16:46:15 +02:00
|
|
|
* \brief Source: %interface to the terminal controlling library
|
2009-02-05 20:28:18 +02:00
|
|
|
*/
|
|
|
|
|
2005-08-29 08:45:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
2005-09-04 22:02:25 +00:00
|
|
|
#include <stdarg.h>
|
2005-08-29 08:45:28 +00:00
|
|
|
|
2010-01-20 17:11:52 +02:00
|
|
|
#include "lib/global.h"
|
2010-01-21 14:17:26 +02:00
|
|
|
#include "lib/strutil.h"
|
2006-05-15 13:26:18 +00:00
|
|
|
|
2010-01-07 01:57:27 +02:00
|
|
|
#include "tty.h"
|
|
|
|
#include "tty-internal.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2005-08-29 08:45:28 +00:00
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/*** global variables ****************************************************************************/
|
2005-08-29 08:45:28 +00:00
|
|
|
|
2010-02-15 11:21:30 +00:00
|
|
|
/* If true program softkeys (HP terminals only) on startup and after every
|
|
|
|
command ran in the subshell to the description found in the termcap/terminfo
|
|
|
|
database */
|
|
|
|
int reset_hp_softkeys = 0;
|
|
|
|
|
2009-07-12 14:22:41 +04:00
|
|
|
/* If true lines are drown by spaces */
|
|
|
|
gboolean slow_tty = FALSE;
|
|
|
|
|
|
|
|
/* If true use +, -, | for line drawing */
|
|
|
|
gboolean ugly_line_drawing = FALSE;
|
|
|
|
|
2010-03-21 20:50:20 +03:00
|
|
|
int mc_tty_frm[MC_TTY_FRM_MAX];
|
2009-08-23 20:42:28 +00:00
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2009-05-10 19:01:15 +04:00
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2005-08-29 08:45:28 +00:00
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/*** file scope variables ************************************************************************/
|
2005-08-29 08:45:28 +00:00
|
|
|
|
|
|
|
static volatile sig_atomic_t got_interrupt = 0;
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2005-08-29 08:45:28 +00:00
|
|
|
|
|
|
|
static void
|
2009-09-17 01:07:04 +03:00
|
|
|
sigintr_handler (int signo)
|
2005-08-29 08:45:28 +00:00
|
|
|
{
|
|
|
|
(void) &signo;
|
|
|
|
got_interrupt = 1;
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2005-08-29 08:45:28 +00:00
|
|
|
|
2009-07-12 14:22:41 +04:00
|
|
|
extern gboolean
|
|
|
|
tty_is_slow (void)
|
|
|
|
{
|
|
|
|
return slow_tty;
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-15 22:31:52 +04:00
|
|
|
extern void
|
2009-09-17 01:07:04 +03:00
|
|
|
tty_start_interrupt_key (void)
|
2009-07-15 22:31:52 +04:00
|
|
|
{
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
act.sa_handler = sigintr_handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
sigaction (SIGINT, &act, NULL);
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2005-08-29 08:45:28 +00:00
|
|
|
extern void
|
2009-09-17 01:07:04 +03:00
|
|
|
tty_enable_interrupt_key (void)
|
2005-08-29 08:45:28 +00:00
|
|
|
{
|
|
|
|
struct sigaction act;
|
2005-08-29 09:04:39 +00:00
|
|
|
|
2005-08-29 08:45:28 +00:00
|
|
|
act.sa_handler = sigintr_handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
sigaction (SIGINT, &act, NULL);
|
2009-07-15 22:31:52 +04:00
|
|
|
got_interrupt = 0;
|
2005-08-29 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2005-08-29 08:45:28 +00:00
|
|
|
extern void
|
2009-09-17 01:07:04 +03:00
|
|
|
tty_disable_interrupt_key (void)
|
2005-08-29 08:45:28 +00:00
|
|
|
{
|
|
|
|
struct sigaction act;
|
2005-08-29 09:04:39 +00:00
|
|
|
|
2005-08-29 08:45:28 +00:00
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
sigaction (SIGINT, &act, NULL);
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-02-05 23:46:07 +01:00
|
|
|
extern gboolean
|
2009-09-17 01:07:04 +03:00
|
|
|
tty_got_interrupt (void)
|
2005-08-29 08:45:28 +00:00
|
|
|
{
|
2009-02-05 23:46:07 +01:00
|
|
|
gboolean rv;
|
2005-08-29 08:45:28 +00:00
|
|
|
|
|
|
|
rv = (got_interrupt != 0);
|
|
|
|
got_interrupt = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
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 08:45:28 +00:00
|
|
|
{
|
2010-03-21 11:58:45 +03:00
|
|
|
tty_print_alt_char (ACS_HLINE, single);
|
2005-08-29 08:45:28 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 12:21:45 +02: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 08:45:28 +00:00
|
|
|
{
|
2010-03-21 11:58:45 +03:00
|
|
|
tty_print_alt_char (ACS_VLINE, single);
|
2005-08-29 08:45:28 +00:00
|
|
|
}
|
2009-07-18 18:30:06 +04:00
|
|
|
|
2010-11-08 12:21:45 +02: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
|
|
|
{
|
2010-04-05 22:02:31 +04:00
|
|
|
ys--;
|
|
|
|
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);
|
2010-04-05 22:02:31 +04:00
|
|
|
tty_draw_vline (y, x + xs, 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);
|
2010-04-05 22:02:31 +04:00
|
|
|
tty_draw_hline (y + ys, 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);
|
2010-04-05 22:02:31 +04:00
|
|
|
tty_gotoyx (y + ys, x);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_print_alt_char (ACS_LLCORNER, single);
|
2010-04-05 22:02:31 +04:00
|
|
|
tty_gotoyx (y, x + xs);
|
2010-03-22 21:55:10 +03:00
|
|
|
tty_print_alt_char (ACS_URCORNER, single);
|
2010-04-05 22:02:31 +04:00
|
|
|
tty_gotoyx (y + ys, x + xs);
|
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 11:04:54 +03:00
|
|
|
|
2010-11-08 12:21:45 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-09-28 11:04:54 +03: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 11:04:54 +03: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 12:21:45 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|