diff --git a/ui-terminal-curses.c b/ui-terminal-curses.c index 849c617c2..0d39306a8 100644 --- a/ui-terminal-curses.c +++ b/ui-terminal-curses.c @@ -2,6 +2,8 @@ #include #include +#define UI_TERMKEY_FLAGS (TERMKEY_FLAG_UTF8|TERMKEY_FLAG_NOTERMIOS) + #define ui_term_backend_init ui_curses_init #define ui_term_backend_blit ui_curses_blit #define ui_term_backend_clear ui_curses_clear @@ -12,7 +14,7 @@ #define ui_term_backend_new ui_curses_new #define ui_term_backend_resume ui_curses_resume #define ui_term_backend_suspend ui_curses_suspend -#define ui_term_backend_free ui_curses_suspend +#define ui_term_backend_free ui_curses_free #define CELL_COLOR_BLACK COLOR_BLACK #define CELL_COLOR_RED COLOR_RED @@ -281,6 +283,9 @@ static void ui_curses_resume(UiTerm *term) { } static void ui_curses_suspend(UiTerm *term) { if (change_colors == 1) undo_palette(); - endwin(); } +static void ui_curses_free(UiTerm *term) { + ui_curses_suspend(term); + endwin(); +} diff --git a/ui-terminal-vt100.c b/ui-terminal-vt100.c index 309261a7b..b584276eb 100644 --- a/ui-terminal-vt100.c +++ b/ui-terminal-vt100.c @@ -39,6 +39,8 @@ #include #include "buffer.h" +#define UI_TERMKEY_FLAGS TERMKEY_FLAG_UTF8 + #define ui_term_backend_init ui_vt100_init #define ui_term_backend_blit ui_vt100_blit #define ui_term_backend_clear ui_vt100_clear @@ -92,7 +94,7 @@ static void output_literal(const char *data) { } static void screen_alternate(bool alternate) { - output_literal(alternate ? "\x1b[?1049h" : "\x1b[0m" "\x1b[?1049l"); + output_literal(alternate ? "\x1b[?1049h" : "\x1b[0m" "\x1b[?1049l" "\x1b[0m" ); } static void cursor_visible(bool visible) { @@ -183,14 +185,16 @@ static int ui_vt100_colors(Ui *ui) { return (term && strstr(term, "-256color")) ? 256 : 16; } -static void ui_vt100_suspend(UiTerm *term) { +static void ui_vt100_suspend(UiTerm *tui) { + termkey_stop(tui->termkey); cursor_visible(true); screen_alternate(false); } -static void ui_vt100_resume(UiTerm *term) { +static void ui_vt100_resume(UiTerm *tui) { screen_alternate(true); cursor_visible(false); + termkey_start(tui->termkey); } static bool ui_vt100_init(UiTerm *tui, char *term) { diff --git a/ui-terminal.c b/ui-terminal.c index 4b4a60b37..e79078599 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -563,7 +563,7 @@ static void ui_info_hide(Ui *ui) { } static TermKey *ui_termkey_new(int fd) { - TermKey *termkey = termkey_new(fd, TERMKEY_FLAG_UTF8); + TermKey *termkey = termkey_new(fd, UI_TERMKEY_FLAGS); if (termkey) termkey_set_canonflags(termkey, TERMKEY_CANON_DELBS); return termkey; @@ -589,13 +589,11 @@ static TermKey *ui_termkey_get(Ui *ui) { static void ui_suspend(Ui *ui) { UiTerm *tui = (UiTerm*)ui; ui_term_backend_suspend(tui); - termkey_stop(tui->termkey); - kill(0, SIGSTOP); + kill(0, SIGTSTP); } static void ui_resume(Ui *ui) { UiTerm *tui = (UiTerm*)ui; - termkey_start(tui->termkey); ui_term_backend_resume(tui); } @@ -650,7 +648,7 @@ static bool ui_init(Ui *ui, Vis *vis) { if (errno == EBADF && !isatty(STDIN_FILENO)) { errno = 0; if (!(tui->termkey = ui_termkey_reopen(ui, STDIN_FILENO)) && errno == ENXIO) - tui->termkey = termkey_new_abstract(term, TERMKEY_FLAG_UTF8); + tui->termkey = termkey_new_abstract(term, UI_TERMKEY_FLAGS); } if (!tui->termkey) goto err;