diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /src/nvim/ui.c | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'src/nvim/ui.c')
-rw-r--r-- | src/nvim/ui.c | 136 |
1 files changed, 85 insertions, 51 deletions
diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 9f1cb87eb0..36f34bc75a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include <assert.h> #include <limits.h> #include <stdbool.h> @@ -11,10 +8,11 @@ #include "klib/kvec.h" #include "nvim/api/private/helpers.h" +#include "nvim/api/private/validate.h" #include "nvim/api/ui.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" -#include "nvim/buffer_defs.h" +#include "nvim/buffer.h" #include "nvim/cursor_shape.h" #include "nvim/drawscreen.h" #include "nvim/ex_getln.h" @@ -25,17 +23,19 @@ #include "nvim/highlight_defs.h" #include "nvim/log.h" #include "nvim/lua/executor.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/time.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/ui.h" #include "nvim/ui_client.h" #include "nvim/ui_compositor.h" -#include "nvim/vim.h" #include "nvim/window.h" +#include "nvim/winfloat.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.c.generated.h" @@ -62,32 +62,32 @@ static int pending_has_mouse = -1; static Array call_buf = ARRAY_DICT_INIT; -#if MIN_LOG_LEVEL > LOGLVL_DBG -# define UI_LOG(funname) -#else +#ifdef NVIM_LOG_DEBUG static size_t uilog_seen = 0; -static char uilog_last_event[1024] = { 0 }; +static const char *uilog_last_event = NULL; -# ifndef EXITFREE -# define entered_free_all_mem false +static void ui_log(const char *funname) +{ +# ifdef EXITFREE + if (entered_free_all_mem) { + return; // do nothing, we cannot log now + } # endif -# define UI_LOG(funname) \ - do { \ - if (entered_free_all_mem) { \ - /* do nothing, we cannot log now */ \ - } else if (strequal(uilog_last_event, STR(funname))) { \ - uilog_seen++; \ - } else { \ - if (uilog_seen > 0) { \ - logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, \ - "%s (+%zu times...)", uilog_last_event, uilog_seen); \ - } \ - logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, STR(funname)); \ - uilog_seen = 0; \ - xstrlcpy(uilog_last_event, STR(funname), sizeof(uilog_last_event)); \ - } \ - } while (0) + if (uilog_last_event == funname) { + uilog_seen++; + } else { + if (uilog_seen > 0) { + logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, + "%s (+%zu times...)", uilog_last_event, uilog_seen); + } + logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, "%s", funname); + uilog_seen = 0; + uilog_last_event = funname; + } +} +#else +# define ui_log(funname) #endif // UI_CALL invokes a function on all registered UI instances. @@ -104,7 +104,7 @@ static char uilog_last_event[1024] = { 0 }; } \ } \ if (any_call) { \ - UI_LOG(funname); \ + ui_log(STR(funname)); \ } \ } while (0) @@ -129,10 +129,11 @@ void ui_free_all_mem(void) map_foreach_value(&ui_event_cbs, event_cb, { free_ui_event_callback(event_cb); }) - pmap_destroy(uint32_t)(&ui_event_cbs); + map_destroy(uint32_t, &ui_event_cbs); } #endif +/// Returns true if any `rgb=true` UI is attached. bool ui_rgb_attached(void) { if (!headless_mode && p_tgc) { @@ -146,6 +147,18 @@ bool ui_rgb_attached(void) return false; } +/// Returns true if a GUI is attached. +bool ui_gui_attached(void) +{ + for (size_t i = 0; i < ui_count; i++) { + bool tui = uis[i]->stdin_tty || uis[i]->stdout_tty; + if (!tui) { + return true; + } + } + return false; +} + /// Returns true if any UI requested `override=true`. bool ui_override(void) { @@ -215,7 +228,7 @@ void ui_refresh(void) p_lz = save_p_lz; if (ext_widgets[kUIMessages]) { - set_option_value("cmdheight", 0L, NULL, 0); + set_option_value("cmdheight", NUMBER_OPTVAL(0), 0); command_height(); } ui_mode_info_set(); @@ -318,7 +331,17 @@ void vim_beep(unsigned val) // comes from. if (vim_strchr(p_debug, 'e') != NULL) { msg_source(HL_ATTR(HLF_W)); - msg_attr(_("Beep!"), HL_ATTR(HLF_W)); + msg(_("Beep!"), HL_ATTR(HLF_W)); + } +} + +/// Trigger UIEnter for all attached UIs. +/// Used on startup after VimEnter. +void do_autocmd_uienter_all(void) +{ + for (size_t i = 0; i < ui_count; i++) { + UIData *data = uis[i]->data; + do_autocmd_uienter(data->channel_id, true); } } @@ -334,6 +357,7 @@ void ui_attach_impl(UI *ui, uint64_t chanid) uis[ui_count++] = ui; ui_refresh_options(); + resettitle(); for (UIExtension i = kUIGlobalCount; (int)i < kUIExtCount; i++) { ui_set_ext_option(ui, i, ui->ui_ext[i]); @@ -419,13 +443,13 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, (const sattr_T *)grid->attrs + off); // 'writedelay': flush & delay each time. - if (p_wd && !(rdb_flags & RDB_COMPOSITOR)) { + if (p_wd && (rdb_flags & RDB_LINE)) { // If 'writedelay' is active, set the cursor to indicate what was drawn. ui_call_grid_cursor_goto(grid->handle, row, MIN(clearcol, (int)grid->cols - 1)); ui_call_flush(); - uint64_t wd = (uint64_t)labs(p_wd); - os_microdelay(wd * 1000U, true); + uint64_t wd = (uint64_t)llabs(p_wd); + os_sleep(wd); pending_cursor_update = true; // restore the cursor later } } @@ -472,11 +496,6 @@ int ui_current_col(void) return cursor_col; } -handle_T ui_cursor_grid(void) -{ - return cursor_grid_handle; -} - void ui_flush(void) { assert(!ui_client_channel_id); @@ -510,6 +529,10 @@ void ui_flush(void) pending_has_mouse = has_mouse; } ui_call_flush(); + + if (p_wd && (rdb_flags & RDB_FLUSH)) { + os_sleep((uint64_t)llabs(p_wd)); + } } /// Check if 'mouse' is active for the current mode @@ -598,6 +621,17 @@ Array ui_array(void) PUT(info, "height", INTEGER_OBJ(ui->height)); PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb)); PUT(info, "override", BOOLEAN_OBJ(ui->override)); + + // TUI fields. (`stdin_fd` is intentionally omitted.) + PUT(info, "term_name", CSTR_TO_OBJ(ui->term_name)); + + // term_background is deprecated. Populate with an empty string + PUT(info, "term_background", CSTR_TO_OBJ("")); + + PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); + PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); + PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); + for (UIExtension j = 0; j < kUIExtCount; j++) { if (ui_ext_names[j][0] != '_' || ui->ui_ext[j]) { PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j])); @@ -609,7 +643,7 @@ Array ui_array(void) return all_uis; } -void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error) +void ui_grid_resize(handle_T grid_handle, int width, int height, Error *err) { if (grid_handle == DEFAULT_GRID_HANDLE) { screen_resize(width, height); @@ -617,11 +651,9 @@ void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error) } win_T *wp = get_win_by_grid_handle(grid_handle); - if (wp == NULL) { - api_set_error(error, kErrorTypeValidation, - "No window with the given handle"); + VALIDATE_INT((wp != NULL), "window handle", (int64_t)grid_handle, { return; - } + }); if (wp->w_floating) { if (width != wp->w_width || height != wp->w_height) { @@ -656,6 +688,8 @@ void ui_call_event(char *name, Array args) if (!handled) { UI_CALL(true, event, ui, name, args); } + + ui_log(name); } void ui_cb_update_ext(void) @@ -689,9 +723,9 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) event_cb->ext_widgets[kUICmdline] = true; } - UIEventCallback **item = (UIEventCallback **)pmap_ref(uint32_t)(&ui_event_cbs, ns_id, true); + ptr_t *item = pmap_put_ref(uint32_t)(&ui_event_cbs, ns_id, NULL, NULL); if (*item) { - free_ui_event_callback(*item); + free_ui_event_callback((UIEventCallback *)(*item)); } *item = event_cb; @@ -701,9 +735,9 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) void ui_remove_cb(uint32_t ns_id) { - if (pmap_has(uint32_t)(&ui_event_cbs, ns_id)) { - free_ui_event_callback(pmap_get(uint32_t)(&ui_event_cbs, ns_id)); - pmap_del(uint32_t)(&ui_event_cbs, ns_id); + if (map_has(uint32_t, &ui_event_cbs, ns_id)) { + UIEventCallback *item = pmap_del(uint32_t)(&ui_event_cbs, ns_id, NULL); + free_ui_event_callback(item); } ui_cb_update_ext(); ui_refresh(); |