diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:39:54 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 22:39:54 +0000 |
commit | 21cb7d04c387e4198ca8098a884c78b56ffcf4c2 (patch) | |
tree | 84fe5690df1551f0bb2bdfe1a13aacd29ebc1de7 /src/nvim/ui_client.c | |
parent | d9c904f85a23a496df4eb6be42aa43f007b22d50 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-colorcolchar.tar.gz rneovim-colorcolchar.tar.bz2 rneovim-colorcolchar.zip |
Merge remote-tracking branch 'upstream/master' into colorcolcharcolorcolchar
Diffstat (limited to 'src/nvim/ui_client.c')
-rw-r--r-- | src/nvim/ui_client.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 378c0e4831..30f44d182d 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -1,28 +1,34 @@ -// 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 +/// Nvim's own UI client, which attaches to a child or remote Nvim server. #include <stdbool.h> #include <stdint.h> #include <stdlib.h> +#include "nvim/api/keysets_defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/channel.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" #include "nvim/event/loop.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/log.h" #include "nvim/main.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/os/os_defs.h" #include "nvim/tui/tui.h" #include "nvim/ui.h" #include "nvim/ui_client.h" +#ifdef MSWIN +# include "nvim/os/os_win_console.h" +#endif + static TUIData *tui = NULL; +static bool ui_client_is_remote = false; // uncrustify:off #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -30,14 +36,13 @@ static TUIData *tui = NULL; # include "ui_events_client.generated.h" #endif // uncrustify:on -// uint64_t ui_client_start_server(int argc, char **argv) { varnumber_T exit_status; char **args = xmalloc(((size_t)(2 + argc)) * sizeof(char *)); int args_idx = 0; - args[args_idx++] = xstrdup((const char *)get_vim_var_str(VV_PROGPATH)); + args[args_idx++] = xstrdup(argv[0]); args[args_idx++] = xstrdup("--embed"); for (int i = 1; i < argc; i++) { args[args_idx++] = xstrdup(argv[i]); @@ -47,8 +52,8 @@ uint64_t ui_client_start_server(int argc, char **argv) CallbackReader on_err = CALLBACK_READER_INIT; on_err.fwd_err = true; - Channel *channel = channel_job_start(args, CALLBACK_READER_INIT, - on_err, CALLBACK_NONE, + Channel *channel = channel_job_start(args, get_vim_var_str(VV_PROGPATH), + CALLBACK_READER_INIT, on_err, CALLBACK_NONE, false, true, true, false, kChannelStdinPipe, NULL, 0, 0, NULL, &exit_status); @@ -66,13 +71,8 @@ uint64_t ui_client_start_server(int argc, char **argv) return channel->id; } -void ui_client_run(bool remote_ui) - FUNC_ATTR_NORETURN +void ui_client_attach(int width, int height, char *term) { - int width, height; - char *term; - tui = tui_start(&width, &height, &term); - MAXSIZE_TEMP_ARRAY(args, 3); ADD_C(args, INTEGER_OBJ(width)); ADD_C(args, INTEGER_OBJ(height)); @@ -82,24 +82,39 @@ void ui_client_run(bool remote_ui) PUT_C(opts, "ext_linegrid", BOOLEAN_OBJ(true)); PUT_C(opts, "ext_termcolors", BOOLEAN_OBJ(true)); if (term) { - PUT(opts, "term_name", STRING_OBJ(cstr_to_string(term))); - } - if (ui_client_bg_response != kNone) { - bool is_dark = (ui_client_bg_response == kTrue); - PUT_C(opts, "term_background", STRING_OBJ(cstr_as_string(is_dark ? "dark" : "light"))); + PUT_C(opts, "term_name", CSTR_AS_OBJ(term)); } + PUT_C(opts, "term_colors", INTEGER_OBJ(t_colors)); - if (!remote_ui) { + if (!ui_client_is_remote) { PUT_C(opts, "stdin_tty", BOOLEAN_OBJ(stdin_isatty)); PUT_C(opts, "stdout_tty", BOOLEAN_OBJ(stdout_isatty)); if (ui_client_forward_stdin) { PUT_C(opts, "stdin_fd", INTEGER_OBJ(UI_CLIENT_STDIN_FD)); + ui_client_forward_stdin = false; // stdin shouldn't be forwarded again #22292 } } ADD_C(args, DICTIONARY_OBJ(opts)); rpc_send_event(ui_client_channel_id, "nvim_ui_attach", args); ui_client_attached = true; +} + +void ui_client_detach(void) +{ + rpc_send_event(ui_client_channel_id, "nvim_ui_detach", (Array)ARRAY_DICT_INIT); + ui_client_attached = false; +} + +void ui_client_run(bool remote_ui) + FUNC_ATTR_NORETURN +{ + ui_client_is_remote = remote_ui; + int width, height; + char *term; + tui_start(&tui, &width, &height, &term); + + ui_client_attach(width, height, term); // os_exit() will be invoked when the client channel detaches while (true) { @@ -109,7 +124,9 @@ void ui_client_run(bool remote_ui) void ui_client_stop(void) { - tui_stop(tui); + if (!tui_is_stopped(tui)) { + tui_stop(tui); + } } void ui_client_set_size(int width, int height) @@ -134,7 +151,7 @@ UIClientHandler ui_client_get_redraw_handler(const char *name, size_t name_len, /// Placeholder for _sync_ requests with 'redraw' method name /// -/// async 'redraw' events, which are expected when nvim acts as an ui client. +/// async 'redraw' events, which are expected when nvim acts as a ui client. /// get handled in msgpack_rpc/unpacker.c and directly dispatched to handlers /// of specific ui events, like ui_client_event_grid_resize and so on. Object handle_ui_client_redraw(uint64_t channel_id, Array args, Arena *arena, Error *error) @@ -189,9 +206,7 @@ void ui_client_event_raw_line(GridLineEvent *g) int grid = g->args[0], row = g->args[1], startcol = g->args[2]; Integer endcol = startcol + g->coloff; Integer clearcol = endcol + g->clear_width; - - // TODO(hlpr98): Accommodate other LineFlags when included in grid_line - LineFlags lineflags = 0; + LineFlags lineflags = g->wrap ? kLineFlagWrap : 0; tui_raw_line(tui, grid, row, startcol, endcol, clearcol, g->cur_attr, lineflags, (const schar_T *)grid_line_buf_char, grid_line_buf_attr); |