2005-08-29 12:45:28 +04:00
|
|
|
/*
|
|
|
|
Interface to the terminal controlling library.
|
|
|
|
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
|
2005-08-29 12:45:28 +04:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Roland Illig <roland.illig@gmx.de>, 2005.
|
|
|
|
|
|
|
|
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 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>
|
|
|
|
|
|
|
|
#include <signal.h>
|
2005-09-05 02:02:25 +04:00
|
|
|
#include <stdarg.h>
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2009-05-08 14:01:05 +04:00
|
|
|
#include "../../src/global.h"
|
2006-05-15 17:26:18 +04:00
|
|
|
|
2009-05-08 14:01:05 +04:00
|
|
|
#include "../../src/tty/color.h"
|
2008-12-29 03:01:53 +03:00
|
|
|
#if defined(USE_NCURSES) || defined(USE_NCURSESW)
|
2006-05-15 17:26:18 +04:00
|
|
|
#define WANT_TERM_H
|
|
|
|
#endif
|
2009-05-08 14:01:05 +04:00
|
|
|
#include "../../src/tty/tty.h"
|
|
|
|
|
|
|
|
#include "../../src/main.h" /* for slow_terminal */
|
|
|
|
#include "../../src/strutil.h"
|
2005-08-29 12:45:28 +04:00
|
|
|
|
|
|
|
/*** file scope macro definitions **************************************/
|
|
|
|
|
|
|
|
#ifndef HAVE_SLANG
|
|
|
|
# define acs()
|
|
|
|
# define noacs()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*** global variables **************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations **************************************/
|
|
|
|
|
|
|
|
/*** file scope variables **********************************************/
|
|
|
|
|
|
|
|
static volatile sig_atomic_t got_interrupt = 0;
|
|
|
|
|
|
|
|
/*** file scope functions **********************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
sigintr_handler(int signo)
|
|
|
|
{
|
|
|
|
(void) &signo;
|
|
|
|
got_interrupt = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** public functions **************************************************/
|
|
|
|
|
2009-07-15 22:31:52 +04:00
|
|
|
extern void
|
|
|
|
tty_start_interrupt_key(void)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
act.sa_handler = sigintr_handler;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
sigaction (SIGINT, &act, NULL);
|
|
|
|
}
|
|
|
|
|
2005-08-29 12:45:28 +04:00
|
|
|
extern void
|
|
|
|
tty_enable_interrupt_key(void)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
2005-08-29 13:04:39 +04:00
|
|
|
|
2005-08-29 12:45:28 +04: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 12:45:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
|
|
|
tty_disable_interrupt_key(void)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
2005-08-29 13:04:39 +04:00
|
|
|
|
2005-08-29 12:45:28 +04:00
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
sigaction (SIGINT, &act, NULL);
|
|
|
|
}
|
|
|
|
|
2009-02-06 01:46:07 +03:00
|
|
|
extern gboolean
|
2005-08-29 12:45:28 +04:00
|
|
|
tty_got_interrupt(void)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
|
|
|
tty_gotoyx(int y, int x)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
SLsmg_gotorc(y, x);
|
|
|
|
#else
|
|
|
|
move(y, x);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
|
|
|
tty_getyx(int *py, int *px)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
*px = SLsmg_get_column();
|
|
|
|
*py = SLsmg_get_row();
|
|
|
|
#else
|
2005-08-29 14:02:35 +04:00
|
|
|
getyx(stdscr, *py, *px);
|
2005-08-29 12:45:28 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-02-03 06:55:37 +03:00
|
|
|
extern void
|
|
|
|
tty_setcolor(int c)
|
|
|
|
{
|
|
|
|
attrset(c);
|
|
|
|
}
|
|
|
|
|
2005-08-29 12:45:28 +04:00
|
|
|
extern void
|
|
|
|
tty_print_char(int c)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
2006-01-07 15:17:07 +03:00
|
|
|
/* We cannot use SLsmg_write_char here because the Debian and Redhat
|
|
|
|
* people thought changing the API of an external project was fun,
|
2005-09-05 07:05:39 +04:00
|
|
|
* especially when it depends on the preprocessor symbol UTF8 being
|
|
|
|
* defined or not. Congratulations! At least, they left the API call
|
|
|
|
* for SLsmg_write_nchars as it has always been.
|
|
|
|
*/
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
ch = c;
|
|
|
|
SLsmg_write_nchars(&ch, 1);
|
2005-08-29 12:45:28 +04:00
|
|
|
#else
|
|
|
|
addch(c);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
|
|
|
tty_print_alt_char(int c)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
SLsmg_draw_object(SLsmg_get_row(), SLsmg_get_column(), c);
|
|
|
|
#else
|
|
|
|
acs();
|
|
|
|
addch(c);
|
|
|
|
noacs();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-01 21:01:12 +04:00
|
|
|
extern void
|
|
|
|
tty_print_string(const char *s)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
patches by Rostislav Beneš: mc-28-fix
rest of fixes in files cmc.c, main.c (xterm title), panelize.c, subshell.c,
tree.c, tty.c, user.c, util.c, win.c
now, basic mc's function should work well, editor and view are still broken.
2008-12-29 02:53:08 +03:00
|
|
|
SLsmg_write_string (str_unconst (str_term_form (s)));
|
2005-08-29 12:45:28 +04:00
|
|
|
#else
|
patches by Rostislav Beneš: mc-28-fix
rest of fixes in files cmc.c, main.c (xterm title), panelize.c, subshell.c,
tree.c, tty.c, user.c, util.c, win.c
now, basic mc's function should work well, editor and view are still broken.
2008-12-29 02:53:08 +03:00
|
|
|
addstr (str_term_form (s));
|
2005-08-29 12:45:28 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-09-01 21:01:12 +04:00
|
|
|
extern void
|
|
|
|
tty_print_one_hline(void)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
|
|
|
if (slow_terminal)
|
|
|
|
tty_print_char(' ');
|
|
|
|
else
|
|
|
|
tty_print_alt_char(ACS_HLINE);
|
|
|
|
}
|
|
|
|
|
2005-09-01 21:01:12 +04:00
|
|
|
extern void
|
|
|
|
tty_print_one_vline(void)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
|
|
|
if (slow_terminal)
|
|
|
|
tty_print_char(' ');
|
|
|
|
else
|
|
|
|
tty_print_alt_char(ACS_VLINE);
|
|
|
|
}
|
|
|
|
|
2005-09-01 21:01:12 +04:00
|
|
|
extern void
|
|
|
|
tty_print_hline(int top, int left, int length)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
2005-08-29 13:03:10 +04:00
|
|
|
int i;
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2005-08-29 13:03:10 +04:00
|
|
|
tty_gotoyx(top, left);
|
|
|
|
for (i = 0; i < length; i++)
|
2005-08-29 12:45:28 +04:00
|
|
|
tty_print_one_hline();
|
|
|
|
}
|
|
|
|
|
2005-09-01 21:01:12 +04:00
|
|
|
extern void
|
|
|
|
tty_print_vline(int top, int left, int length)
|
2005-08-29 12:45:28 +04:00
|
|
|
{
|
2005-08-29 13:03:10 +04:00
|
|
|
int i;
|
2005-08-29 12:45:28 +04:00
|
|
|
|
2005-08-29 13:03:10 +04:00
|
|
|
tty_gotoyx(top, left);
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
tty_gotoyx(top + i, left);
|
2005-08-29 12:45:28 +04:00
|
|
|
tty_print_one_vline();
|
2005-08-29 13:03:10 +04:00
|
|
|
}
|
2005-08-29 12:45:28 +04:00
|
|
|
}
|
2005-09-05 02:02:25 +04:00
|
|
|
|
|
|
|
extern void
|
|
|
|
tty_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
SLsmg_vprintf(str_unconst(fmt), args);
|
|
|
|
#else
|
|
|
|
vw_printw(stdscr, fmt, args);
|
|
|
|
#endif
|
|
|
|
va_end(args);
|
|
|
|
}
|
2006-05-15 17:26:18 +04:00
|
|
|
|
|
|
|
extern char *
|
|
|
|
tty_tgetstr (const char *cap)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
2006-05-23 11:38:59 +04:00
|
|
|
return SLtt_tgetstr (str_unconst (cap));
|
2006-05-15 17:26:18 +04:00
|
|
|
#else
|
|
|
|
{
|
2008-12-03 01:32:46 +03:00
|
|
|
char *unused = NULL;
|
2006-05-15 17:26:18 +04:00
|
|
|
return tgetstr (str_unconst (cap), &unused);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|