From 16a15c0ee2f973219957ad38b4401f45f7f96b59 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 2 Jun 2009 21:40:37 +0400 Subject: [PATCH] New functions. tty_noecho() is used instead of noecho() function or macro. tty_flush_input() is used instead of flushinp() function or macro. tty_reset_screen() is used instead of endwin() function or macro. tty_shutdown() is based on slang_shutdown(). Also implemented for NCurses as wrapper for endwin(). --- src/execute.c | 8 ++--- src/layout.c | 2 +- src/main.c | 5 +-- src/tty/tty-ncurses.c | 24 ++++++++++++++ src/tty/tty-slang.c | 77 +++++++++++++++++++++++++++---------------- src/tty/tty-slang.h | 7 ---- src/tty/tty.h | 6 ++++ 7 files changed, 84 insertions(+), 45 deletions(-) diff --git a/src/execute.c b/src/execute.c index 9b257d7e9..85817c065 100644 --- a/src/execute.c +++ b/src/execute.c @@ -48,7 +48,7 @@ edition_post_exec (void) /* FIXME: Missing on slang endwin? */ tty_reset_prog_mode (); - flushinp (); + tty_flush_input (); tty_keypad (TRUE); tty_raw_mode (); @@ -74,7 +74,7 @@ edition_pre_exec (void) tty_reset_shell_mode (); tty_keypad (FALSE); - endwin (); + tty_reset_screen (); numeric_keypad_mode (); @@ -234,10 +234,10 @@ toggle_panels (void) * is no tty_raw_mode supported */ tty_reset_shell_mode (); - noecho (); #endif /* !HAVE_SLANG */ + tty_noecho (); tty_keypad (FALSE); - endwin (); + tty_reset_screen (); do_exit_ca_mode (); tty_raw_mode (); if (console_flag) diff --git a/src/layout.c b/src/layout.c index d49e468b2..5b364ba00 100644 --- a/src/layout.c +++ b/src/layout.c @@ -722,7 +722,7 @@ change_screen_size (void) #ifndef NCURSES_VERSION tty_noraw_mode (); - endwin (); + tty_reset_screen (); #endif low_level_change_screen_size (); check_split (); diff --git a/src/main.c b/src/main.c index da9a65551..dc95d8f9c 100644 --- a/src/main.c +++ b/src/main.c @@ -2371,10 +2371,7 @@ main (int argc, char *argv[]) flush_extension_file (); /* does only free memory */ - endwin (); -#ifdef HAVE_SLANG - slang_shutdown (); -#endif + tty_shutdown (); if (console_flag && !(quit & SUBSHELL_EXIT)) handle_console (CONSOLE_RESTORE); diff --git a/src/tty/tty-ncurses.c b/src/tty/tty-ncurses.c index a839796c7..23b1f0da3 100644 --- a/src/tty/tty-ncurses.c +++ b/src/tty/tty-ncurses.c @@ -92,6 +92,12 @@ init_curses (void) } } +void +tty_shutdown (void) +{ + endwin (); +} + void tty_reset_prog_mode (void) { @@ -116,6 +122,18 @@ tty_noraw_mode (void) noraw (); } +void +tty_noecho (void) +{ + noecho (); +} + +int +tty_flush_input (void) +{ + return flushinp (); +} + void tty_keypad (gboolean set) { @@ -134,6 +152,12 @@ tty_baudrate (void) return baudrate(); } +int +tty_reset_screen (void) +{ + return endwin (); +} + void tty_touch_screen (void) { diff --git a/src/tty/tty-slang.c b/src/tty/tty-slang.c index 3ce206337..99ed6a844 100644 --- a/src/tty/tty-slang.c +++ b/src/tty/tty-slang.c @@ -217,6 +217,16 @@ load_terminfo_keys (void) /*** public functions **************************************************/ +void +init_curses (void) +{ + SLsmg_init_smg (); + do_enter_ca_mode (); + tty_init_colors (); + tty_keypad (TRUE); + tty_nodelay (FALSE); +} + void init_slang (void) { @@ -269,6 +279,26 @@ init_slang (void) SLtt_Blink_Mode = 0; } +void +tty_shutdown (void) +{ + char *op_cap; + + SLsmg_reset_smg (); + tty_reset_shell_mode (); + do_exit_ca_mode (); + SLang_reset_tty (); + + /* Load the op capability to reset the colors to those that were + * active when the program was started up + */ + op_cap = SLtt_tgetstr ((char *) "op"); + if (op_cap != NULL){ + fputs (op_cap, stdout); + fflush (stdout); + } +} + /* Done each time we come back from done mode */ void tty_reset_prog_mode (void) @@ -296,6 +326,17 @@ tty_noraw_mode (void) { } +void +tty_noecho (void) +{ +} + +int +tty_flush_input (void) +{ + return 0; /* OK */ +} + void tty_keypad (gboolean set) { @@ -320,35 +361,6 @@ tty_baudrate (void) return SLang_TT_Baud_Rate; } -void -slang_shutdown (void) -{ - char *op_cap; - - tty_reset_shell_mode (); - do_exit_ca_mode (); - SLang_reset_tty (); - - /* Load the op capability to reset the colors to those that were - * active when the program was started up - */ - op_cap = SLtt_tgetstr ((char *) "op"); - if (op_cap != NULL) { - fputs (op_cap, stdout); - fflush (stdout); - } -} - -void -init_curses (void) -{ - SLsmg_init_smg (); - do_enter_ca_mode (); - tty_init_colors (); - tty_keypad (TRUE); - tty_nodelay (FALSE); -} - void hline (int ch, int len) { @@ -412,6 +424,13 @@ getch (void) return c; } +int +tty_reset_screen (void) +{ + SLsmg_reset_smg (); + return 0; /* OK */ +} + void tty_touch_screen (void) { diff --git a/src/tty/tty-slang.h b/src/tty/tty-slang.h index 56d4a6603..47b86363f 100644 --- a/src/tty/tty-slang.h +++ b/src/tty/tty-slang.h @@ -26,22 +26,15 @@ enum { #define ACS_URCORNER SLSMG_URCORN_CHAR #define ACS_LRCORNER SLSMG_LRCORN_CHAR -#define noecho() - -#define ungetch(x) SLang_ungetkey (x) -#define flushinp() - void init_slang (void); void init_curses (void); void hline (int ch, int len); void vline (int ch, int len); int getch (void); -void slang_shutdown (void); #define printw SLsmg_printf #define COLS SLtt_Screen_Cols #define LINES SLtt_Screen_Rows -#define endwin() SLsmg_reset_smg () #define SLsmg_draw_double_box(r, c, dr, dc) SLsmg_draw_box ((r), (c), (dr), (dc)) diff --git a/src/tty/tty.h b/src/tty/tty.h index eeed33650..fc10fce64 100644 --- a/src/tty/tty.h +++ b/src/tty/tty.h @@ -32,10 +32,15 @@ extern void tty_reset_shell_mode (void); extern void tty_raw_mode (void); extern void tty_noraw_mode (void); +extern void tty_noecho (void); +extern int tty_flush_input (void); + extern void tty_keypad (gboolean set); extern void tty_nodelay (gboolean set); extern int tty_baudrate (void); +extern void tty_shutdown (void); + /* {{{ Output }}} */ /* @@ -44,6 +49,7 @@ extern int tty_baudrate (void); While SLang provides such a feature, ncurses does not. */ +extern int tty_reset_screen (void); extern void tty_touch_screen (void); extern void tty_gotoyx(int y, int x);