From: Timo Korvola Date: Tue, 20 Feb 2018 21:33:42 +0000 (+0200) Subject: Suspend on ^Z. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=07a05dcc4632de4803dab79997482a5c8fc885b0;p=liskon_frotz.git Suspend on ^Z. In raw mode ^Z is just another character. It is easier to handle than in cbreak because it can be done in normal execution without having to replace the curses SIGTSTP handler. --- diff --git a/src/curses/ux_frotz.h b/src/curses/ux_frotz.h index 9834928..6126981 100644 --- a/src/curses/ux_frotz.h +++ b/src/curses/ux_frotz.h @@ -92,6 +92,7 @@ bool unix_init_pictures(void); /* ux_pic.c */ // void unix_save_screen(int); /* ux_screen.c */ // void unix_do_scrollback(void); /* ux_screen.c */ void unix_resize_display(void); /* ux_screen.c */ +void unix_suspend_program(void); /* ux_screen.c */ void unix_get_terminal_size(void); /* ux_init.c */ diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index 9268e30..db9fa9c 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -281,6 +281,11 @@ static int unix_read_char(int extkeys) case MOD_CTRL ^ 'U': c = ZC_DEL_TO_BOL; break; case MOD_CTRL ^ 'W': c = ZC_DEL_WORD; break; + /* In raw mode we need to take care of this as well. */ + case MOD_CTRL ^ 'Z': + unix_suspend_program(); + continue; + /* use ^Q to immediately exit. */ case MOD_CTRL ^ 'Q': os_quit(); diff --git a/src/curses/ux_screen.c b/src/curses/ux_screen.c index 31368e4..fb482a0 100644 --- a/src/curses/ux_screen.c +++ b/src/curses/ux_screen.c @@ -25,6 +25,8 @@ #include #include +#include + #ifdef USE_NCURSES_H #include #else @@ -136,11 +138,7 @@ void os_scroll_area (int top, int left, int bottom, int right, int units) }/* os_scroll_area */ -/** - * Resize the display and redraw. Retain the old screen starting from the - * top left. Call resize_screen, which may repaint more accurately. - */ -void unix_resize_display(void) +static void save_screen(void) { if ((saved_screen = newpad(h_screen_rows, h_screen_cols)) && overwrite(stdscr, saved_screen) == ERR) { @@ -152,21 +150,46 @@ void unix_resize_display(void) getyx(stdscr, y, x); wmove(saved_screen, y, x); } +} - endwin(); - refresh(); - unix_get_terminal_size(); +static void resize_restore_screen(void) +{ + unix_get_terminal_size(); resize_screen(); - if (zmp != NULL) { - restart_header(); - } + if (zmp != NULL) + restart_header(); if (saved_screen) { delwin(saved_screen); saved_screen = NULL; } +} + + + +/** + * Resize the display and redraw. Retain the old screen starting from the + * top left. Call resize_screen, which may repaint more accurately. + */ +void unix_resize_display(void) +{ + save_screen(); + endwin(); + refresh(); + resize_restore_screen(); }/* unix_redraw_display */ +/** + * Suspend ourselves. Save the screen and raise SIGTSTP. + * Upon continuing restore the screen as in unix_resize_display; the terminal + * size may have changed while we were stopped. + */ +void unix_suspend_program(void) +{ + save_screen(); + raise(SIGTSTP); + resize_restore_screen(); +} /** * Repaint a window.