From bcc6a404865f848f74bfb8b6136c0565b292eb50 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 13 May 2009 17:05:55 +0400 Subject: [PATCH] Reorganization of TTY initalization and line drawing. Created some TTY functions instead of MC core global variables. Moved init_layer() function from MC core to TTY layer. Renamed slang_init() to init_slang(). Added required #include's in TTY layer. Moved S-Lang color and attribute definitions from src/tty/tty-slang.h to colors-slang.h. --- src/layout.c | 61 +--------------------------------------- src/layout.h | 1 - src/main.c | 27 +++++++++--------- src/main.h | 2 -- src/tty/color-internal.c | 4 +++ src/tty/color-internal.h | 5 ++++ src/tty/color-ncurses.h | 2 ++ src/tty/color-slang.h | 27 ++++++++++++++++++ src/tty/color.h | 1 - src/tty/key.c | 2 +- src/tty/tty-ncurses.c | 59 ++++++++++++++++++++++++++++++++++++++ src/tty/tty-ncurses.h | 1 + src/tty/tty-slang.c | 28 ++++++++++++++---- src/tty/tty-slang.h | 28 ++---------------- src/tty/tty.c | 13 +++++++++ src/tty/tty.h | 8 +++++- 16 files changed, 158 insertions(+), 111 deletions(-) diff --git a/src/layout.c b/src/layout.c index 2838a34cc..9c63efc0f 100644 --- a/src/layout.c +++ b/src/layout.c @@ -48,7 +48,7 @@ #include "global.h" -#include "../src/tty/tty.h" /* COLS */ +#include "../src/tty/tty.h" #include "../src/tty/color.h" #include "../src/tty/key.h" #include "../src/tty/mouse.h" @@ -567,65 +567,6 @@ static void check_split (void) } } -#ifdef HAVE_SLANG -void -init_curses () -{ - SLsmg_init_smg (); - do_enter_ca_mode (); - init_colors (); - keypad (stdscr, TRUE); - nodelay (stdscr, FALSE); -} -#else -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 } }; - -void init_curses (void) -{ - int i; - 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 (); - mc_raw_mode (); - noecho (); - keypad (stdscr, TRUE); - nodelay (stdscr, FALSE); - init_colors (); - if (force_ugly_line_drawing) { - for (i = 0; acs_approx[i].acscode != 0; i++) { - acs_map[acs_approx[i].acscode] = acs_approx[i].character; - } - } -} -#endif /* ! HAVE_SLANG */ - void clr_scr (void) { diff --git a/src/layout.h b/src/layout.h index 7a14a0940..5d543264c 100644 --- a/src/layout.h +++ b/src/layout.h @@ -10,7 +10,6 @@ #include "widget.h" void layout_cmd (void); -void init_curses (void); void done_screen (void); void setup_panels (void); void destroy_panels (void); diff --git a/src/main.c b/src/main.c index cd7689bbe..94fdf50de 100644 --- a/src/main.c +++ b/src/main.c @@ -184,9 +184,6 @@ int mouse_move_pages = 1; /* If true: l&r arrows are used to chdir if the input line is empty */ int navigate_with_arrows = 0; -/* If true use +, -, | for line drawing */ -int force_ugly_line_drawing = 0; - /* 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 */ @@ -276,9 +273,6 @@ static char *last_wd_string = NULL; /* Set to 1 to suppress printing the last directory */ static int print_last_revert = 0; -/* Force colors, only used by Slang */ -int force_colors = 0; - /* colors specified on the command line: they override any other setting */ char *command_line_colors = NULL; @@ -2034,11 +2028,16 @@ process_args (poptContext ctx, int c, const char *option_arg) exit (0); break; + case 'a': + tty_set_ugly_line_drawing (TRUE); + break; + + case 'b': + tty_disable_colors (TRUE, FALSE); + break; + case 'c': - disable_colors = 0; -#ifdef HAVE_SLANG - force_colors = 1; -#endif /* HAVE_SLANG */ + tty_disable_colors (FALSE, TRUE); break; case 'f': @@ -2102,11 +2101,11 @@ static const struct poptOption argument_table[] = { N_("Resets soft keys on HP terminals"), NULL}, {"slow", 's', POPT_ARG_NONE, {&slow_terminal}, 0, N_("To run on slow terminals"), NULL}, - {"stickchars", 'a', 0, {&force_ugly_line_drawing}, 0, + {"stickchars", 'a', POPT_ARG_NONE, {NULL}, 'a', N_("Use stickchars to draw"), NULL}, /* color options */ - {"nocolor", 'b', POPT_ARG_NONE, {&disable_colors}, 0, + {"nocolor", 'b', POPT_ARG_NONE, {NULL}, 'b', N_("Requests to run in black and white"), NULL}, {"color", 'c', POPT_ARG_NONE, {NULL}, 'c', N_("Request to run in color mode"), NULL}, @@ -2281,7 +2280,7 @@ main (int argc, char *argv[]) handle_args (argc, argv); - /* NOTE: This has to be called before slang_init or whatever routine + /* NOTE: This has to be called before init_slang or whatever routine calls any define_sequence */ init_key (); @@ -2306,7 +2305,7 @@ main (int argc, char *argv[]) /* Must be done before init_subshell, to set up the terminal size: */ /* FIXME: Should be removed and LINES and COLS computed on subshell */ #ifdef HAVE_SLANG - slang_init (); + init_slang (); #endif start_interrupt_key (); diff --git a/src/main.h b/src/main.h index 588ec5b97..734352f5c 100644 --- a/src/main.h +++ b/src/main.h @@ -56,7 +56,6 @@ extern int utf8_display; extern int confirm_view_dir; extern int fast_refresh; extern int navigate_with_arrows; -extern int force_ugly_line_drawing; extern int drop_menus; extern int cd_symlinks; extern int show_all_if_ambiguous; @@ -68,7 +67,6 @@ extern int confirm_directory_hotlist_delete; extern int confirm_execute; extern int confirm_exit; extern int confirm_overwrite; -extern int force_colors; extern int boot_current_is_left; extern int use_file_to_check_type; extern int vfs_use_limit; diff --git a/src/tty/color-internal.c b/src/tty/color-internal.c index ef91a7be1..8c6e39ba1 100644 --- a/src/tty/color-internal.c +++ b/src/tty/color-internal.c @@ -7,8 +7,12 @@ #include /* size_t */ +#include "../../src/tty/color.h" /* colors and attributes */ #include "../../src/tty/color-internal.h" +gboolean disable_colors = FALSE; +gboolean force_colors = FALSE; /* unused with NCurses */ + struct color_table_s const color_table [] = { { "black", COLOR_BLACK }, { "gray", COLOR_BLACK | A_BOLD }, diff --git a/src/tty/color-internal.h b/src/tty/color-internal.h index 73b8fb54c..92be4d561 100644 --- a/src/tty/color-internal.h +++ b/src/tty/color-internal.h @@ -8,12 +8,17 @@ #include /* size_t */ +#include "../../src/global.h" + #ifdef HAVE_SLANG # include "../../src/tty/tty-slang.h" #else # include "../../src/tty/tty-ncurses.h" #endif /* HAVE_SLANG */ +extern gboolean disable_colors; +extern gboolean force_colors; /* for S-Lang only */ + struct color_table_s { const char *name; int value; diff --git a/src/tty/color-ncurses.h b/src/tty/color-ncurses.h index 9d5025e94..1e09fa118 100644 --- a/src/tty/color-ncurses.h +++ b/src/tty/color-ncurses.h @@ -6,6 +6,8 @@ #ifndef MC_COLOR_NCURSES_H #define MC_COLOR_NCURSES_H +#include "../../src/tty/tty-ncurses.h" /* NCurses headers */ + #define MAX_PAIRS 64 extern int attr_pairs [MAX_PAIRS]; diff --git a/src/tty/color-slang.h b/src/tty/color-slang.h index e81221ab0..fa186f3c7 100644 --- a/src/tty/color-slang.h +++ b/src/tty/color-slang.h @@ -6,6 +6,33 @@ #ifndef MC_COLOR_SLANG_H #define MC_COLOR_SLANG_H +#include "../../src/tty/tty-slang.h" /* S-Lang headers */ + +enum { + COLOR_BLACK = 0, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE +}; + +/* When using Slang with color, we have all the indexes free but + * those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE) + */ +#define A_BOLD 0x40 +#define A_UNDERLINE 0x40 +#define A_REVERSE 0x20 +#define A_BOLD_REVERSE 0x21 + +#ifndef A_NORMAL +# define A_NORMAL 0x00 +#endif + +#define COLOR_PAIR(x) x + #define IF_COLOR(co, bw) (use_colors ? COLOR_PAIR (co) : bw) #define MARKED_SELECTED_COLOR IF_COLOR (4, (SLtt_Use_Ansi_Colors ? A_BOLD_REVERSE : A_REVERSE | A_BOLD)) diff --git a/src/tty/color.h b/src/tty/color.h index 5f390a6f5..fe01bf624 100644 --- a/src/tty/color.h +++ b/src/tty/color.h @@ -13,7 +13,6 @@ #endif extern int use_colors; -extern int disable_colors; /* Beware! When using Slang with color, not all the indexes are free. See myslang.h (A_*) */ diff --git a/src/tty/key.c b/src/tty/key.c index 2713a74ea..11a7267da 100644 --- a/src/tty/key.c +++ b/src/tty/key.c @@ -488,7 +488,7 @@ init_key_x11 (void) #endif /* HAVE_TEXTMODE_X11_SUPPORT */ -/* This has to be called before slang_init or whatever routine +/* This has to be called before init_slang or whatever routine calls any define_sequence */ void init_key (void) diff --git a/src/tty/tty-ncurses.c b/src/tty/tty-ncurses.c index 95d095c9b..74f4d877b 100644 --- a/src/tty/tty-ncurses.c +++ b/src/tty/tty-ncurses.c @@ -16,6 +16,8 @@ #include "../../src/tty/color-ncurses.h" #include "../../src/tty/tty-ncurses.h" +#include "../../src/tty/color-internal.h" /* disable_colors */ +#include "../../src/tty/win.h" #include "../../src/background.h" /* we_are_background */ #include "../../src/strutil.h" /* str_term_form */ @@ -36,10 +38,67 @@ /*** 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 (); + mc_raw_mode (); + noecho (); + keypad (stdscr, TRUE); + nodelay (stdscr, FALSE); + 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_disable_colors (gboolean disable, gboolean force) +{ + disable_colors = disable; + (void) force_colors; +} + void tty_setcolor (int color) { diff --git a/src/tty/tty-ncurses.h b/src/tty/tty-ncurses.h index a324413ae..3c2d4534a 100644 --- a/src/tty/tty-ncurses.h +++ b/src/tty/tty-ncurses.h @@ -18,6 +18,7 @@ # include #endif /* USE_NCURSESW */ +void init_curses (void); #define acs() #define noacs() diff --git a/src/tty/tty-slang.c b/src/tty/tty-slang.c index 60b9952c2..68bf5a039 100644 --- a/src/tty/tty-slang.c +++ b/src/tty/tty-slang.c @@ -16,16 +16,17 @@ #include "../../src/global.h" -#include "../../src/tty/tty-slang.h" /* mc-init_pair */ +#include "../../src/tty/tty-slang.h" /* mc_init_pair */ #include "../../src/tty/color.h" +#include "../../src/tty/color-internal.h" #include "../../src/tty/mouse.h" /* Gpm_Event is required in key.h */ #include "../../src/tty/key.h" /* define_sequence */ -#include "../../src/tty/win.h" /* do_exit_ca_mode */ +#include "../../src/tty/win.h" #include "../../src/background.h" /* we_are_background */ +#include "../../src/main.h" /* for slow_terminal */ #include "../../src/util.h" /* str_unconst */ #include "../../src/strutil.h" /* str_term_form */ -#include "../../src/main.h" /* extern: force_colors */ #include "../../src/setup.h" /*** global variables **************************************************/ @@ -217,7 +218,7 @@ load_terminfo_keys (void) /*** public functions **************************************************/ void -slang_init (void) +init_slang (void) { SLtt_get_terminfo (); #if SLANG_VERSION >= 20000 @@ -251,7 +252,7 @@ slang_init (void) if (SLang_TT_Read_FD == fileno (stderr)) SLang_TT_Read_FD = fileno (stdin); - if (force_ugly_line_drawing) + if (tty_is_ugly_line_drawing ()) SLtt_Has_Alt_Charset = 0; if (tcgetattr (SLang_TT_Read_FD, &new_mode) == 0) { #ifdef VDSUSP @@ -329,6 +330,16 @@ set_slang_delay (int v) no_slang_delay = v; } +void +init_curses (void) +{ + SLsmg_init_smg (); + do_enter_ca_mode (); + init_colors (); + keypad (stdscr, TRUE); + nodelay (stdscr, FALSE); +} + void hline (int ch, int len) { @@ -427,6 +438,13 @@ has_colors (void) return SLtt_Use_Ansi_Colors; } +void +tty_disable_colors (gboolean disable, gboolean force) +{ + disable_colors = disable; + force_colors = force; +} + void tty_setcolor (int color) { diff --git a/src/tty/tty-slang.h b/src/tty/tty-slang.h index 292646016..4fa587181 100644 --- a/src/tty/tty-slang.h +++ b/src/tty/tty-slang.h @@ -32,31 +32,6 @@ enum { #define noacs() SLsmg_set_char_set (0) #define baudrate() SLang_TT_Baud_Rate -enum { - COLOR_BLACK = 0, - COLOR_RED, - COLOR_GREEN, - COLOR_YELLOW, - COLOR_BLUE, - COLOR_MAGENTA, - COLOR_CYAN, - COLOR_WHITE -}; - -/* When using Slang with color, we have all the indexes free but - * those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE) - */ -#define A_BOLD 0x40 -#define A_UNDERLINE 0x40 -#define A_REVERSE 0x20 -#define A_BOLD_REVERSE 0x21 - -#ifndef A_NORMAL -# define A_NORMAL 0x00 -#endif - -#define COLOR_PAIR(x) x - #ifndef TRUE # define TRUE 1 # define FALSE 0 @@ -80,7 +55,8 @@ void slang_set_raw_mode (void); #define flushinp() void set_slang_delay (int); -void slang_init (void); +void init_slang (void); +void init_curses (void); void slang_prog_mode (void); void hline (int ch, int len); void vline (int ch, int len); diff --git a/src/tty/tty.c b/src/tty/tty.c index 347f2670b..38e0c6945 100644 --- a/src/tty/tty.c +++ b/src/tty/tty.c @@ -52,6 +52,9 @@ static volatile sig_atomic_t got_interrupt = 0; +/* If true use +, -, | for line drawing */ +static gboolean force_ugly_line_drawing = FALSE; + /*** file scope functions **********************************************/ static void @@ -107,6 +110,16 @@ tty_got_interrupt(void) return rv; } +void tty_set_ugly_line_drawing (gboolean do_ugly) +{ + force_ugly_line_drawing = do_ugly; +} + +gboolean tty_is_ugly_line_drawing (void) +{ + return force_ugly_line_drawing; +} + extern void tty_print_one_hline(void) { diff --git a/src/tty/tty.h b/src/tty/tty.h index 0a48fc22a..8b0e16489 100644 --- a/src/tty/tty.h +++ b/src/tty/tty.h @@ -26,6 +26,7 @@ extern void tty_enable_interrupt_key(void); extern void tty_disable_interrupt_key(void); extern gboolean tty_got_interrupt(void); + /* {{{ Output }}} */ /* @@ -37,18 +38,23 @@ extern gboolean tty_got_interrupt(void); extern void tty_gotoyx(int y, int x); extern void tty_getyx(int *py, int *px); +extern void tty_disable_colors (gboolean disable, gboolean force); extern void tty_setcolor(int color); extern void tty_lowlevel_setcolor(int color); extern void tty_print_char(int c); extern void tty_print_alt_char(int c); extern void tty_print_string(const char *s); +extern void tty_printf(const char *s, ...); + +extern void tty_set_ugly_line_drawing (gboolean do_ugly); +extern gboolean tty_is_ugly_line_drawing (void); extern void tty_print_one_vline(void); extern void tty_print_one_hline(void); extern void tty_print_vline(int top, int left, int length); extern void tty_print_hline(int top, int left, int length); extern void tty_draw_box (int y, int x, int rows, int cols); -extern void tty_printf(const char *s, ...); + extern char *tty_tgetstr (const char *name);