Skip to content

Commit

Permalink
Merge #7720 'tui: rework deferred-termcodes implementation'
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk committed Dec 13, 2017
2 parents 7164f61 + ed92ece commit 6ff13d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/nvim/os/pty_process_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
ELOG("forkpty failed: %s", strerror(errno));
return status;
} else if (pid == 0) {
init_child(ptyproc);
abort();
init_child(ptyproc); // never returns
}

// make sure the master file descriptor is non blocking
Expand Down Expand Up @@ -163,14 +162,15 @@ static void init_child(PtyProcess *ptyproc) FUNC_ATTR_NONNULL_ALL

Process *proc = (Process *)ptyproc;
if (proc->cwd && os_chdir(proc->cwd) != 0) {
fprintf(stderr, "chdir failed: %s\n", strerror(errno));
ELOG("chdir failed: %s", strerror(errno));
return;
}

char *prog = ptyproc->process.argv[0];
setenv("TERM", ptyproc->term_name ? ptyproc->term_name : "ansi", 1);
execvp(prog, ptyproc->process.argv);
fprintf(stderr, "execvp failed: %s: %s\n", strerror(errno), prog);
ELOG("execvp failed: %s: %s", strerror(errno), prog);
_exit(122); // 122 is EXEC_FAILED in the Vim source.
}

static void init_termios(struct termios *termios) FUNC_ATTR_NONNULL_ALL
Expand Down
3 changes: 2 additions & 1 deletion src/nvim/os/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endif

#include "nvim/ascii.h"
#include "nvim/log.h"
#include "nvim/vim.h"
#include "nvim/globals.h"
#include "nvim/memline.h"
Expand Down Expand Up @@ -162,7 +163,7 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
}
break;
default:
fprintf(stderr, "Invalid signal %d", signum);
ELOG("invalid signal: %d", signum);
break;
}
}
42 changes: 21 additions & 21 deletions src/nvim/tui/tui.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct {
UIBridgeData *bridge;
Loop *loop;
bool stop;
uv_timer_t after_startup_timer;
unibi_var_t params[9];
char buf[OUTBUF_SIZE];
size_t bufpos;
Expand Down Expand Up @@ -169,24 +170,6 @@ static size_t unibi_pre_fmt_str(TUIData *data, unsigned int unibi_index,
return unibi_run(str, data->params, buf, len);
}

/// Emits some termcodes after Nvim startup, which were observed to slowdown
/// rendering during startup in tmux 2.3 (+focus-events). #7649
static void terminfo_after_startup_event(void **argv)
{
UI *ui = argv[0];
bool defer = argv[1] != NULL; // clever(?) boolean without malloc() dance.
TUIData *data = ui->data;
if (defer) { // We're on the main-loop. Now forward to the TUI loop.
loop_schedule(data->loop,
event_create(terminfo_after_startup_event, 2, ui, NULL));
return;
}
// Enable bracketed paste
unibi_out_ext(ui, data->unibi_ext.enable_bracketed_paste);
// Enable focus reporting
unibi_out_ext(ui, data->unibi_ext.enable_focus_reporting);
}

static void termname_set_event(void **argv)
{
char *termname = argv[0];
Expand Down Expand Up @@ -266,6 +249,9 @@ static void terminfo_start(UI *ui)
unibi_out(ui, unibi_enter_ca_mode);
unibi_out(ui, unibi_keypad_xmit);
unibi_out(ui, unibi_clear_screen);
// Enable bracketed paste
unibi_out_ext(ui, data->unibi_ext.enable_bracketed_paste);

uv_loop_init(&data->write_loop);
if (data->out_isatty) {
uv_tty_init(&data->write_loop, &data->output_handle.tty, data->out_fd, 0);
Expand All @@ -278,9 +264,6 @@ static void terminfo_start(UI *ui)
uv_pipe_init(&data->write_loop, &data->output_handle.pipe, 0);
uv_pipe_open(&data->output_handle.pipe, data->out_fd);
}

loop_schedule(&main_loop,
event_create(terminfo_after_startup_event, 2, ui, ui));
}

static void terminfo_stop(UI *ui)
Expand Down Expand Up @@ -308,6 +291,18 @@ static void terminfo_stop(UI *ui)
unibi_destroy(data->ut);
}

static void after_startup_timer_cb(uv_timer_t *handle)
FUNC_ATTR_NONNULL_ALL
{
UI *ui = handle->data;
TUIData *data = ui->data;
uv_timer_stop(&data->after_startup_timer);

// Emit this after Nvim startup, not during. This works around a tmux
// 2.3 bug(?) which caused slow drawing during startup. #7649
unibi_out_ext(ui, data->unibi_ext.enable_focus_reporting);
}

static void tui_terminal_start(UI *ui)
{
TUIData *data = ui->data;
Expand All @@ -317,6 +312,8 @@ static void tui_terminal_start(UI *ui)
update_size(ui);
signal_watcher_start(&data->winch_handle, sigwinch_cb, SIGWINCH);
term_input_start(&data->input);

uv_timer_start(&data->after_startup_timer, after_startup_timer_cb, 500, 0);
}

static void tui_terminal_stop(UI *ui)
Expand Down Expand Up @@ -350,6 +347,8 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
#ifdef UNIX
signal_watcher_start(&data->cont_handle, sigcont_cb, SIGCONT);
#endif
uv_timer_init(&data->loop->uv, &data->after_startup_timer);
data->after_startup_timer.data = ui;

#if TERMKEY_VERSION_MAJOR > 0 || TERMKEY_VERSION_MINOR > 18
data->input.tk_ti_hook_fn = tui_tk_ti_getstr;
Expand All @@ -368,6 +367,7 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
loop_poll_events(&tui_loop, -1); // tui_loop.events is never processed
}

uv_close((uv_handle_t *)&data->after_startup_timer, NULL);
ui_bridge_stopped(bridge);
term_input_destroy(&data->input);
signal_watcher_stop(&data->cont_handle);
Expand Down
2 changes: 0 additions & 2 deletions src/nvim/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ struct ui_t {
bool ui_ext[UI_WIDGETS]; ///< Externalized widgets
int width, height;
void *data;

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ui_events.generated.h"
#endif

void (*event)(UI *ui, char *name, Array args, bool *args_consumed);
void (*stop)(UI *ui);
};
Expand Down

0 comments on commit 6ff13d7

Please sign in to comment.