Skip to content

Commit d77dcde

Browse files
committed
fix(tui): more work in the TUI
1 parent 1fcb181 commit d77dcde

27 files changed

+401
-374
lines changed

runtime/doc/api.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,15 +717,19 @@ nvim_del_var({name}) *nvim_del_var()*
717717
Parameters: ~
718718
{name} Variable name
719719

720-
nvim_echo({chunks}, {history}, {opts}) *nvim_echo()*
720+
nvim_echo({chunks}, {history}, {*opts}) *nvim_echo()*
721721
Echo a message.
722722

723723
Parameters: ~
724724
{chunks} A list of [text, hl_group] arrays, each representing a text
725725
chunk with specified highlight. `hl_group` element can be
726726
omitted for no highlight.
727727
{history} if true, add to |message-history|.
728-
{opts} Optional parameters. Reserved for future use.
728+
{opts} Optional parameters.
729+
• verbose: Message was printed as a result of 'verbose'
730+
option if Nvim was invoked with -V3log_file, the message
731+
will be redirected to the log_file and surpressed from
732+
direct output.
729733

730734
nvim_err_write({str}) *nvim_err_write()*
731735
Writes a message to the Vim error buffer. Does not append "\n", the
@@ -3467,6 +3471,12 @@ nvim_ui_pum_set_height({height}) *nvim_ui_pum_set_height()*
34673471
Parameters: ~
34683472
{height} Popupmenu height, must be greater than zero.
34693473

3474+
nvim_ui_set_focus({gained}) *nvim_ui_set_focus()*
3475+
Tells the nvim server if focus was gained by the GUI or not.
3476+
3477+
Attributes: ~
3478+
|RPC| only
3479+
34703480
nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()*
34713481
TODO: Documentation
34723482

runtime/doc/news.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,22 @@ The following new APIs or features were added.
8989

9090
See https://github.com/neovim/neovim/pull/14537.
9191

92+
|--remote-ui| option was added to connect to a remote instance and display
93+
in it in a |TUI| in the local terminal. This can be used run a headless nvim
94+
instance in the background and display its UI on demand, which previously
95+
only was possible usiing a external UI implementation.
96+
9297
==============================================================================
9398
CHANGED FEATURES *news-changes*
9499

95100
The following changes to existing APIs or features add new behavior.
96101

97102
'exrc' is no longer marked deprecated.
98103

104+
• the |TUI| is changed to run in a separate process (previously, a separate
105+
thread was used). This is not supposed to be a visible change to the user,
106+
but might be the cause of subtle changes of behavior and bugs.
107+
99108
==============================================================================
100109
REMOVED FEATURES *news-removed*
101110

runtime/doc/remote.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ The following command line arguments are available:
5252
*--remote-expr*
5353
--remote-expr {expr} Evaluate {expr} in server and print the result
5454
on stdout.
55+
*--remote-ui*
56+
--remote-ui {expr} Display the UI of the server in the terminal.
57+
Fully interactive: keyboard and mouse input
58+
are forwarded to the server.
5559
*--server*
5660
--server {addr} Connect to the named pipe or socket at the
5761
given address for executing remote commands.

src/nvim/api/keysets.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ return {
126126
"global_link";
127127
"fallback";
128128
"blend";
129+
"fg_indexed";
130+
"bg_indexed";
129131
};
130132
highlight_cterm = {
131133
"bold";
@@ -219,5 +221,8 @@ return {
219221
cmd_opts = {
220222
"output";
221223
};
224+
echo_opts = {
225+
"verbose";
226+
};
222227
}
223228

src/nvim/api/vim.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,22 +726,31 @@ void nvim_set_vvar(String name, Object value, Error *err)
726726
/// text chunk with specified highlight. `hl_group` element
727727
/// can be omitted for no highlight.
728728
/// @param history if true, add to |message-history|.
729-
/// @param opts Optional parameters. Reserved for future use.
730-
void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err)
729+
/// @param opts Optional parameters.
730+
/// - verbose: Message was printed as a result of 'verbose' option
731+
/// if Nvim was invoked with -V3log_file, the message will be
732+
/// redirected to the log_file and surpressed from direct output.
733+
void nvim_echo(Array chunks, Boolean history, Dict(echo_opts) *opts, Error *err)
731734
FUNC_API_SINCE(7)
732735
{
733736
HlMessage hl_msg = parse_hl_msg(chunks, err);
734737
if (ERROR_SET(err)) {
735738
goto error;
736739
}
737740

738-
if (opts.size > 0) {
739-
api_set_error(err, kErrorTypeValidation, "opts dict isn't empty");
740-
goto error;
741+
bool verbose = api_object_to_bool(opts->verbose, "verbose", false, err);
742+
743+
if (verbose) {
744+
verbose_enter();
741745
}
742746

743747
msg_multiattr(hl_msg, history ? "echomsg" : "echo", history);
744748

749+
if (verbose) {
750+
verbose_leave();
751+
verbose_stop(); // flush now
752+
}
753+
745754
if (history) {
746755
// history takes ownership
747756
return;
@@ -1204,6 +1213,12 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
12041213
draining = false;
12051214
}
12061215

1216+
// TODO(bfredl): ugly, maybe only when notification?
1217+
if (ERROR_SET(err)) {
1218+
semsg("paste: %s", err->msg);
1219+
api_clear_error(err);
1220+
}
1221+
12071222
return !cancel;
12081223
}
12091224

src/nvim/charset.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,17 @@ char *transstr(const char *const s, bool untab)
418418
return buf;
419419
}
420420

421+
size_t kv_transstr(StringBuilder *str, const char *const s, bool untab)
422+
{
423+
// Compute the length of the result, taking account of unprintable
424+
// multi-byte characters.
425+
const size_t len = transstr_len(s, untab);
426+
kv_ensure_space(*str, len + 1);
427+
transstr_buf(s, str->items + str->size, len + 1, untab);
428+
str->size += len; // do not include NUL byte
429+
return len;
430+
}
431+
421432
/// Convert the string "str[orglen]" to do ignore-case comparing.
422433
/// Use the current locale.
423434
///

src/nvim/charset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nvim/eval/typval.h"
88
#include "nvim/option_defs.h"
99
#include "nvim/pos.h"
10+
#include "nvim/strings.h"
1011
#include "nvim/types.h"
1112

1213
/// Return the folded-case equivalent of the given character

src/nvim/event/libuv_process.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ int libuv_process_spawn(LibuvProcess *uvproc)
4747
uvproc->uvstdio[1].flags = UV_IGNORE;
4848
uvproc->uvstdio[2].flags = UV_IGNORE;
4949

50-
// TODO: this should just be single flag!
51-
if (TUI_process && !is_remote_client && !stdin_isatty) {
50+
if (ui_client_embed && !stdin_isatty) {
5251
uvproc->uvopts.stdio_count = 4;
5352
uvproc->uvstdio[3].data.fd = 0;
5453
uvproc->uvstdio[3].flags = UV_INHERIT_FD;

src/nvim/event/process.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ static void on_process_exit(Process *proc)
404404
ILOG("exited: pid=%d status=%d stoptime=%" PRIu64, proc->pid, proc->status,
405405
proc->stopped_time);
406406

407-
if (TUI_process && !is_remote_client) {
408-
// Set only in "builtin" TUI
407+
if (ui_client_embed) {
409408
server_process_exit_status = proc->status;
410409
}
411410
// Process has terminated, but there could still be data to be read from the

src/nvim/generators/gen_api_dispatch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ for i = 1, #functions do
363363
-- if the function recieves the array args, pass it the second argument
364364
output:write('args, ')
365365
end
366-
output:write(call_args)
366+
output:write(call_args)
367367
else
368368
output:write('channel_id')
369369
if fn.receives_array_args then

0 commit comments

Comments
 (0)