diff options
Diffstat (limited to 'src/nvim/main.c')
-rw-r--r-- | src/nvim/main.c | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 9e14e911ff..422495519a 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -97,6 +97,10 @@ #include "nvim/msgpack_rpc/helpers.h" #include "nvim/msgpack_rpc/server.h" #include "nvim/os/signal.h" +#ifndef MSWIN +# include "nvim/os/pty_process_unix.h" +#endif +#include "nvim/tui/tui.h" // values for "window_layout" enum { @@ -137,6 +141,7 @@ void event_init(void) // early msgpack-rpc initialization msgpack_rpc_helpers_init(); + // Initialize input events input_init(); signal_init(); // finish mspgack-rpc initialization @@ -291,7 +296,13 @@ int main(int argc, char **argv) } } - server_init(params.listen_addr); + bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); + // bool is_remote_client = false; // TODO: rename to specifically for --remote-ui + // + if (!(is_remote_client || use_builtin_ui)) { + server_init(params.listen_addr); + } + if (params.remote) { remote_request(¶ms, params.remote, params.server_addr, argc, argv); } @@ -352,7 +363,7 @@ int main(int argc, char **argv) // Wait for UIs to set up Nvim or show early messages // and prompts (--cmd, swapfile dialog, …). bool use_remote_ui = (embedded_mode && !headless_mode); - bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); + TUI_process = is_remote_client || use_builtin_ui; if (use_remote_ui || use_builtin_ui) { TIME_MSG("waiting for UI"); if (use_remote_ui) { @@ -376,6 +387,31 @@ int main(int argc, char **argv) abort(); // unreachable } + // Setting up the remote connection. + // This has to be always after ui_builtin_start or + // after the start of atleast one GUI + // as size of "uis[]" must be greater than 1 + if (TUI_process) { + input_stop(); // Stop reading input, let the UI take over. + uint64_t rv = ui_client_start(params.argc, params.argv, + (params.edit_type == EDIT_STDIN + && !recoverymode)); + if (!rv) { + // cannot continue without a channel + // TODO: use ui_call_stop() ? + tui_exit_safe(ui_get_by_index(1)); + ELOG("RPC: ", NULL, -1, true, + "Could not establish connection with address : %s", params.server_addr); + os_msg("Could not establish connection with remote server\n"); + getout(1); + } + // TODO: fuuu, deduplicate with ui_client_channel_id block above + ui_client_channel_id = rv; + ui_client_execute(ui_client_channel_id); + abort(); // unreachable + } + + // Default mappings (incl. menus) Error err = ERROR_INIT; Object o = NLUA_EXEC_STATIC("return vim._init_default_mappings()", @@ -384,6 +420,7 @@ int main(int argc, char **argv) api_clear_error(&err); assert(o.type == kObjectTypeNil); api_free_object(o); + TIME_MSG("init default mappings"); init_default_autocmds(); @@ -624,6 +661,9 @@ void os_exit(int r) free_all_mem(); #endif + if (TUI_process && !is_remote_client) { + r = (int)server_process_exit_status; + } exit(r); } @@ -1376,6 +1416,13 @@ scripterror: // Handle "foo | nvim". EDIT_FILE may be overwritten now. #6299 if (edit_stdin(had_stdin_file, parmp)) { parmp->edit_type = EDIT_STDIN; + // TODO: copy + bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); + if (use_builtin_ui && !is_remote_client) { + // must be set only in builtin TUI + // TODO + //implicit_readstdin = true; + } } TIME_MSG("parsing arguments"); @@ -2149,6 +2196,7 @@ static void usage(void) os_msg(_(" --embed Use stdin/stdout as a msgpack-rpc channel\n")); os_msg(_(" --headless Don't start a user interface\n")); os_msg(_(" --listen <address> Serve RPC API from this address\n")); + os_msg(_(" --connect <address> Specify Nvim server to connect to\n")); os_msg(_(" --noplugin Don't load plugins\n")); os_msg(_(" --remote[-subcommand] Execute commands remotely on a server\n")); os_msg(_(" --server <address> Specify RPC server to send commands to\n")); |