* slint.c: The handling of user interrupts has been moved to ...
* tty.c: ... this newly created file, which contains a simple, not yet complete interface to the terminal library. It should be used instead of depending directly on ncurses or SLang features. * tty.h: Added the new function prototypes from tty.c and some legacy definitions.
Этот коммит содержится в:
родитель
f1452c9580
Коммит
66332a4fb1
@ -1,3 +1,12 @@
|
||||
2005-08-29 Roland Illig <roland.illig@gmx.de>
|
||||
|
||||
* slint.c: The handling of user interrupts has been moved to ...
|
||||
* tty.c: ... this newly created file, which contains a simple,
|
||||
not yet complete interface to the terminal library. It should be
|
||||
used instead of depending directly on ncurses or SLang features.
|
||||
* tty.h: Added the new function prototypes from tty.c and some
|
||||
legacy definitions.
|
||||
|
||||
2005-08-28 Roland Illig <roland.illig@gmx.de>
|
||||
|
||||
* view.c (view_hexedit_save_changes): Added an assertion that
|
||||
|
45
src/slint.c
45
src/slint.c
@ -139,51 +139,10 @@ static int SLang_input_pending2 (int tsecs)
|
||||
}
|
||||
#endif /* HAVE_SLANG_PRIVATE */
|
||||
|
||||
static void
|
||||
slang_intr (int signo)
|
||||
{
|
||||
slinterrupt = 1;
|
||||
}
|
||||
|
||||
void
|
||||
enable_interrupt_key(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = slang_intr;
|
||||
sigemptyset (&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
sigaction (SIGINT, &act, NULL);
|
||||
slinterrupt = 0;
|
||||
}
|
||||
|
||||
void
|
||||
disable_interrupt_key(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = SIG_IGN;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset (&act.sa_mask);
|
||||
sigaction (SIGINT, &act, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
got_interrupt (void)
|
||||
{
|
||||
int t;
|
||||
|
||||
t = slinterrupt;
|
||||
slinterrupt = 0;
|
||||
return t;
|
||||
}
|
||||
|
||||
/* Only done the first time */
|
||||
void
|
||||
slang_init (void)
|
||||
{
|
||||
struct sigaction act, oact;
|
||||
|
||||
SLtt_get_terminfo ();
|
||||
|
||||
/*
|
||||
@ -228,10 +187,6 @@ slang_init (void)
|
||||
}
|
||||
slang_prog_mode ();
|
||||
load_terminfo_keys ();
|
||||
act.sa_handler = slang_intr;
|
||||
sigemptyset (&act.sa_mask);
|
||||
act.sa_flags = SA_RESTART;
|
||||
sigaction (SIGINT, &act, &oact);
|
||||
SLtt_Blink_Mode = 0;
|
||||
}
|
||||
|
||||
|
178
src/tty.c
Обычный файл
178
src/tty.c
Обычный файл
@ -0,0 +1,178 @@
|
||||
/*
|
||||
Interface to the terminal controlling library.
|
||||
|
||||
Copyright (C) 2005 The Free Software Foundation, Inc.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "main.h" /* for slow_terminal */
|
||||
#include "tty.h"
|
||||
|
||||
/*** 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 **************************************************/
|
||||
|
||||
extern void
|
||||
tty_enable_interrupt_key(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
got_interrupt = 0;
|
||||
act.sa_handler = sigintr_handler;
|
||||
sigemptyset (&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
sigaction (SIGINT, &act, NULL);
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_disable_interrupt_key(void)
|
||||
{
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = SIG_IGN;
|
||||
sigemptyset (&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
sigaction (SIGINT, &act, NULL);
|
||||
}
|
||||
|
||||
extern gboolean
|
||||
tty_got_interrupt(void)
|
||||
{
|
||||
gboolean rv;
|
||||
|
||||
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
|
||||
getyx(*py, *px);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void
|
||||
tty_print_char(int c)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
SLsmg_write_char(c);
|
||||
#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
|
||||
}
|
||||
|
||||
extern void tty_print_string(const char *s)
|
||||
{
|
||||
#ifdef HAVE_SLANG
|
||||
SLsmg_write_string(str_unconst(s));
|
||||
#else
|
||||
addstr(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void tty_print_one_hline(void)
|
||||
{
|
||||
if (slow_terminal)
|
||||
tty_print_char(' ');
|
||||
else
|
||||
tty_print_alt_char(ACS_HLINE);
|
||||
}
|
||||
|
||||
extern void tty_print_one_vline(void)
|
||||
{
|
||||
if (slow_terminal)
|
||||
tty_print_char(' ');
|
||||
else
|
||||
tty_print_alt_char(ACS_VLINE);
|
||||
}
|
||||
|
||||
extern void tty_print_hline(int left, int right, int y)
|
||||
{
|
||||
int x;
|
||||
|
||||
tty_gotoyx(y, left);
|
||||
for (x = left; x < right; x++)
|
||||
tty_print_one_hline();
|
||||
}
|
||||
|
||||
extern void tty_print_vline(int x, int top, int bottom)
|
||||
{
|
||||
int y;
|
||||
|
||||
tty_gotoyx(top, x);
|
||||
for (y = top; y < bottom; y++)
|
||||
tty_print_one_vline();
|
||||
}
|
43
src/tty.h
43
src/tty.h
@ -1,19 +1,15 @@
|
||||
#ifndef MC_TTY_H
|
||||
#define MC_TTY_H
|
||||
|
||||
/* This file takes care of loading ncurses or slang */
|
||||
|
||||
int got_interrupt (void);
|
||||
/*
|
||||
This file is the interface to the terminal controlling library---
|
||||
ncurses, slang or the built-in slang. It provides an additional
|
||||
layer of abstraction above the "real" libraries to keep the number
|
||||
of ifdefs in the other files small.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# include "myslang.h"
|
||||
#else
|
||||
# define enable_interrupt_key()
|
||||
# define disable_interrupt_key()
|
||||
# define acs()
|
||||
# define noacs()
|
||||
# define one_vline() addch (slow_terminal ? ' ' : ACS_VLINE)
|
||||
# define one_hline() addch (slow_terminal ? ' ' : ACS_HLINE)
|
||||
#endif
|
||||
|
||||
#ifdef USE_NCURSES
|
||||
@ -26,6 +22,33 @@ int got_interrupt (void);
|
||||
# endif
|
||||
#endif /* USE_NCURSES */
|
||||
|
||||
/* Input */
|
||||
extern void tty_enable_interrupt_key(void);
|
||||
extern void tty_disable_interrupt_key(void);
|
||||
extern gboolean tty_got_interrupt(void);
|
||||
|
||||
/* Output */
|
||||
extern void tty_gotoyx(int, int);
|
||||
extern void tty_getyx(int *, int *);
|
||||
extern void tty_print_char(int);
|
||||
extern void tty_print_alt_char(int);
|
||||
extern void tty_print_string(const char *);
|
||||
extern void tty_print_one_vline(void);
|
||||
extern void tty_print_one_hline(void);
|
||||
extern void tty_print_vline(int x, int top, int bottom);
|
||||
extern void tty_print_hline(int left, int right, int y);
|
||||
|
||||
/* legacy interface */
|
||||
|
||||
#define enable_interrupt_key() tty_enable_interrupt_key()
|
||||
#define disable_interrupt_key() tty_disable_interrupt_key()
|
||||
#define got_interrupt() tty_got_interrupt()
|
||||
|
||||
#ifndef HAVE_SLANG
|
||||
# define acs()
|
||||
# define noacs()
|
||||
#endif
|
||||
|
||||
#define KEY_KP_ADD 4001
|
||||
#define KEY_KP_SUBTRACT 4002
|
||||
#define KEY_KP_MULTIPLY 4003
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user