mc/src/tty/tty-ncurses.c

243 lines
4.4 KiB
C
Raw Normal View History

/** \file
* \brief Source: NCurses-based tty layer of Midnight-commander
*/
#include <config.h>
#include <stdlib.h>
#include <stdarg.h>
#include "../../src/global.h"
#ifndef WANT_TERM_H
# define WANT_TERM_H
#endif
2009-05-14 19:18:03 +04:00
#include "../../src/tty/tty.h" /* tty_is_ugly_line_drawing() */
#include "../../src/tty/color-ncurses.h"
2009-05-14 19:18:03 +04:00
#include "../../src/tty/color-internal.h"
#include "../../src/tty/win.h"
#include "../../src/background.h" /* we_are_background */
#include "../../src/strutil.h" /* str_term_form */
#include "../../src/util.h" /* str_unconst */
/* include at last !!! */
#ifdef WANT_TERM_H
# include <term.h>
#endif /* WANT_TERM_H*/
/*** global variables **************************************************/
/*** file scope macro definitions **************************************/
/*** global variables **************************************************/
/*** file scope type declarations **************************************/
/*** file scope variables **********************************************/
static const struct {
int acscode;
int character;
} acs_approx [] = {
{ 'q', '-' }, /* ACS_HLINE */
{ 'x', '|' }, /* ACS_VLINE */
{ 'l', '+' }, /* ACS_ULCORNER */
{ 'k', '+' }, /* ACS_URCORNER */
{ 'm', '+' }, /* ACS_LLCORNER */
{ 'j', '+' }, /* ACS_LRCORNER */
{ 'a', '#' }, /* ACS_CKBOARD */
{ 'u', '+' }, /* ACS_RTEE */
{ 't', '+' }, /* ACS_LTEE */
{ 'w', '+' }, /* ACS_TTEE */
{ 'v', '+' }, /* ACS_BTEE */
{ 'n', '+' }, /* ACS_PLUS */
{ 0, 0 } };
/*** file scope functions **********************************************/
/*** public functions **************************************************/
void
init_curses (void)
{
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 */
do_enter_ca_mode ();
raw ();
noecho ();
keypad (stdscr, TRUE);
nodelay (stdscr, FALSE);
2009-05-14 19:18:03 +04:00
tty_init_colors ();
if (tty_is_ugly_line_drawing ()) {
int i;
for (i = 0; acs_approx[i].acscode != 0; i++)
acs_map[acs_approx[i].acscode] = acs_approx[i].character;
}
}
void
tty_reset_prog_mode (void)
{
reset_prog_mode ();
}
void
tty_reset_shell_mode (void)
{
reset_shell_mode ();
}
void
tty_raw_mode (void)
{
raw ();
}
void
tty_noraw_mode (void)
{
noraw ();
}
void
tty_keypad (gboolean set)
{
keypad (stdscr, (bool) set);
}
void
tty_nodelay (gboolean set)
{
nodelay (stdscr, (bool) set);
}
int
tty_baudrate (void)
{
return baudrate();
}
void
tty_touch_screen (void)
{
touchwin (stdscr);
}
void
tty_gotoyx (int y, int x)
{
move (y, x);
}
void
tty_getyx (int *py, int *px)
{
getyx (stdscr, *py, *px);
}
void
tty_draw_box (int y, int x, int rows, int cols)
{
#define waddc(_y, _x, c) move (_y, _x); addch (c)
waddc (y, x, ACS_ULCORNER);
hline (ACS_HLINE, cols - 2);
waddc (y + rows - 1, x, ACS_LLCORNER);
hline (ACS_HLINE, cols - 2);
waddc (y, x + cols - 1, ACS_URCORNER);
waddc (y + rows - 1, x + cols - 1, ACS_LRCORNER);
move (y + 1, x);
vline (ACS_VLINE, rows - 2);
move (y + 1, x + cols - 1);
vline (ACS_VLINE, rows - 2);
#undef waddc
}
void
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
{
int i;
for (i = 0; i < rows; i++) {
move (y + i, x);
hline (ch, cols);
}
move (y, x);
}
void
tty_set_alt_charset (gboolean alt_charset)
{
(void) alt_charset;
}
void
tty_print_char (int c)
{
addch (c);
}
void
tty_print_alt_char (int c)
{
addch (c);
}
void
2009-05-13 12:38:11 +04:00
tty_print_string (const char *s)
{
addstr (str_term_form (s));
}
void
tty_printf (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
vw_printw (stdscr, fmt, args);
va_end (args);
}
char *
tty_tgetstr (const char *cap)
{
char *unused = NULL;
return tgetstr (str_unconst (cap), &unused);
}
void
2009-05-13 12:38:11 +04:00
tty_refresh (void)
{
#ifdef WITH_BACKGROUND
if (!we_are_background)
#endif /* WITH_BACKGROUND */
refresh ();
}
void
tty_beep (void)
{
beep ();
}