diff options
Diffstat (limited to 'src/nvim/ui_client.c')
-rw-r--r-- | src/nvim/ui_client.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index b5c8dff412..30f44d182d 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -1,27 +1,32 @@ -// 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; @@ -31,14 +36,13 @@ static bool ui_client_is_remote = false; # 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]); @@ -48,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); @@ -78,18 +82,16 @@ void ui_client_attach(int width, int height, char *term) PUT_C(opts, "ext_linegrid", BOOLEAN_OBJ(true)); PUT_C(opts, "ext_termcolors", BOOLEAN_OBJ(true)); if (term) { - PUT_C(opts, "term_name", STRING_OBJ(cstr_as_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 (!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)); @@ -110,7 +112,7 @@ void ui_client_run(bool remote_ui) ui_client_is_remote = remote_ui; int width, height; char *term; - tui = tui_start(&width, &height, &term); + tui_start(&tui, &width, &height, &term); ui_client_attach(width, height, term); @@ -122,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) @@ -147,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) @@ -202,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); |