Skip to content

Commit

Permalink
ui: try to fix job control issues with certain shells
Browse files Browse the repository at this point in the history
Make sure that curses and libtermkey don't fight over
the terminal state. Also send use SIGTSTP instead of
SIGSTOP.

Previously certain shells (e.g. csh, dash) would get
stuck after the editor process was suspended for the
second time.

Not completely sure whether this is correct, but it
seems to work in my limited tests.
  • Loading branch information
martanne committed Mar 22, 2017
1 parent c9a259b commit fc0efcc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 7 additions & 2 deletions ui-terminal-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <stdio.h>
#include <curses.h>

#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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
10 changes: 7 additions & 3 deletions ui-terminal-vt100.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <stdio.h>
#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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions ui-terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fc0efcc

Please sign in to comment.