diff options
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r-- | src/nvim/terminal.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 104cc47cda..bd7b9fc58f 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -63,6 +63,7 @@ #include "nvim/map.h" #include "nvim/misc1.h" #include "nvim/move.h" +#include "nvim/main.h" #include "nvim/state.h" #include "nvim/ex_docmd.h" #include "nvim/ex_cmds.h" @@ -126,7 +127,7 @@ struct terminal { // we can't store a direct reference to the buffer because the // refresh_timer_cb may be called after the buffer was freed, and there's // no way to know if the memory was reused. - uint64_t buf_handle; + handle_T buf_handle; // program exited bool closed, destroy; // some vterm properties @@ -163,9 +164,9 @@ static VTermColor default_vt_bg_rgb; void terminal_init(void) { invalidated_terminals = pmap_new(ptr_t)(); - time_watcher_init(&loop, &refresh_timer, NULL); + time_watcher_init(&main_loop, &refresh_timer, NULL); // refresh_timer_cb will redraw the screen which can call vimscript - refresh_timer.events = queue_new_child(loop.events); + refresh_timer.events = multiqueue_new_child(main_loop.events); // initialize a rgb->color index map for cterm attributes(VTermScreenCell // only has RGB information and we need color indexes for terminal UIs) @@ -200,7 +201,7 @@ void terminal_init(void) void terminal_teardown(void) { time_watcher_stop(&refresh_timer); - queue_free(refresh_timer.events); + multiqueue_free(refresh_timer.events); time_watcher_close(&refresh_timer, NULL); pmap_free(ptr_t)(invalidated_terminals); map_free(int, int)(color_indexes); @@ -240,6 +241,7 @@ Terminal *terminal_open(TerminalOptions opts) set_option_value((uint8_t *)"wrap", false, NULL, OPT_LOCAL); set_option_value((uint8_t *)"number", false, NULL, OPT_LOCAL); set_option_value((uint8_t *)"relativenumber", false, NULL, OPT_LOCAL); + buf_set_term_title(curbuf, (char *)curbuf->b_ffname); RESET_BINDING(curwin); // Apply TermOpen autocmds so the user can configure the terminal apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf); @@ -347,15 +349,6 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) height = (uint16_t)curheight; } - // The new width/height are the minimum for all windows that display the - // terminal in the current tab. - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (!wp->w_closing && wp->w_buffer->terminal == term) { - width = (uint16_t)MIN(width, (uint16_t)(wp->w_width - win_col_off(wp))); - height = (uint16_t)MIN(height, (uint16_t)wp->w_height); - } - } - if (curheight == height && curwidth == width) { return; } @@ -373,10 +366,10 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) void terminal_enter(void) { buf_T *buf = curbuf; + assert(buf->terminal); // Should only be called when curbuf has a terminal. TerminalState state, *s = &state; memset(s, 0, sizeof(TerminalState)); s->term = buf->terminal; - assert(s->term && "should only be called when curbuf has a terminal"); // Ensure the terminal is properly sized. terminal_resize(s->term, 0, 0); @@ -452,7 +445,7 @@ static int terminal_execute(VimState *state, int key) case K_EVENT: // We cannot let an event free the terminal yet. It is still needed. s->term->refcount++; - queue_process_events(loop.events); + multiqueue_process_events(main_loop.events); s->term->refcount--; if (s->term->buf_handle == 0) { s->close = true; @@ -626,6 +619,18 @@ static int term_movecursor(VTermPos new, VTermPos old, int visible, return 1; } +static void buf_set_term_title(buf_T *buf, char *title) + FUNC_ATTR_NONNULL_ALL +{ + Error err; + dict_set_value(buf->b_vars, + cstr_as_string("term_title"), + STRING_OBJ(cstr_as_string(title)), + false, + false, + &err); +} + static int term_settermprop(VTermProp prop, VTermValue *val, void *data) { Terminal *term = data; @@ -641,12 +646,7 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data) case VTERM_PROP_TITLE: { buf_T *buf = handle_get_buffer(term->buf_handle); - Error err; - api_free_object(dict_set_value(buf->b_vars, - cstr_as_string("term_title"), - STRING_OBJ(cstr_as_string(val->string)), - false, - &err)); + buf_set_term_title(buf, val->string); break; } @@ -955,7 +955,6 @@ static void invalidate_terminal(Terminal *term, int start_row, int end_row) static void refresh_terminal(Terminal *term) { - // TODO(SplinterOfChaos): Find the condition that makes term->buf invalid. buf_T *buf = handle_get_buffer(term->buf_handle); bool valid = true; if (!buf || !(valid = buf_valid(buf))) { @@ -1082,7 +1081,8 @@ static void redraw(bool restore_cursor) restore_cursor = true; } - int save_row, save_col; + int save_row = 0; + int save_col = 0; if (restore_cursor) { // save the current row/col to restore after updating screen when not // focused @@ -1158,15 +1158,15 @@ static bool is_focused(Terminal *term) return State & TERM_FOCUS && curbuf->terminal == term; } -#define GET_CONFIG_VALUE(k, o) \ - do { \ - Error err; \ - /* Only called from terminal_open where curbuf->terminal is the */ \ - /* context */ \ - o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \ - if (o.type == kObjectTypeNil) { \ - o = dict_get_value(&globvardict, cstr_as_string(k), &err); \ - } \ +#define GET_CONFIG_VALUE(k, o) \ + do { \ + Error err; \ + /* Only called from terminal_open where curbuf->terminal is the */ \ + /* context */ \ + o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \ + if (o.type == kObjectTypeNil) { \ + o = dict_get_value(&globvardict, cstr_as_string(k), &err); \ + } \ } while (0) static char *get_config_string(char *key) |