Skip to content

Commit

Permalink
fix(tui): more work in the TUI
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Dec 15, 2022
1 parent 1fcb181 commit d77dcde
Show file tree
Hide file tree
Showing 27 changed files with 401 additions and 374 deletions.
14 changes: 12 additions & 2 deletions runtime/doc/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,19 @@ nvim_del_var({name}) *nvim_del_var()*
Parameters: ~
{name} Variable name

nvim_echo({chunks}, {history}, {opts}) *nvim_echo()*
nvim_echo({chunks}, {history}, {*opts}) *nvim_echo()*
Echo a message.

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

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

nvim_ui_set_focus({gained}) *nvim_ui_set_focus()*
Tells the nvim server if focus was gained by the GUI or not.

Attributes: ~
|RPC| only

nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()*
TODO: Documentation

Expand Down
9 changes: 9 additions & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,22 @@ The following new APIs or features were added.

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

|--remote-ui| option was added to connect to a remote instance and display
in it in a |TUI| in the local terminal. This can be used run a headless nvim
instance in the background and display its UI on demand, which previously
only was possible usiing a external UI implementation.

==============================================================================
CHANGED FEATURES *news-changes*

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

'exrc' is no longer marked deprecated.

• the |TUI| is changed to run in a separate process (previously, a separate
thread was used). This is not supposed to be a visible change to the user,
but might be the cause of subtle changes of behavior and bugs.

==============================================================================
REMOVED FEATURES *news-removed*

Expand Down
4 changes: 4 additions & 0 deletions runtime/doc/remote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ The following command line arguments are available:
*--remote-expr*
--remote-expr {expr} Evaluate {expr} in server and print the result
on stdout.
*--remote-ui*
--remote-ui {expr} Display the UI of the server in the terminal.
Fully interactive: keyboard and mouse input
are forwarded to the server.
*--server*
--server {addr} Connect to the named pipe or socket at the
given address for executing remote commands.
Expand Down
5 changes: 5 additions & 0 deletions src/nvim/api/keysets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ return {
"global_link";
"fallback";
"blend";
"fg_indexed";
"bg_indexed";
};
highlight_cterm = {
"bold";
Expand Down Expand Up @@ -219,5 +221,8 @@ return {
cmd_opts = {
"output";
};
echo_opts = {
"verbose";
};
}

25 changes: 20 additions & 5 deletions src/nvim/api/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,22 +726,31 @@ void nvim_set_vvar(String name, Object value, Error *err)
/// text chunk with specified highlight. `hl_group` element
/// can be omitted for no highlight.
/// @param history if true, add to |message-history|.
/// @param opts Optional parameters. Reserved for future use.
void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err)
/// @param opts Optional parameters.
/// - verbose: Message was printed as a result of 'verbose' option
/// if Nvim was invoked with -V3log_file, the message will be
/// redirected to the log_file and surpressed from direct output.
void nvim_echo(Array chunks, Boolean history, Dict(echo_opts) *opts, Error *err)
FUNC_API_SINCE(7)
{
HlMessage hl_msg = parse_hl_msg(chunks, err);
if (ERROR_SET(err)) {
goto error;
}

if (opts.size > 0) {
api_set_error(err, kErrorTypeValidation, "opts dict isn't empty");
goto error;
bool verbose = api_object_to_bool(opts->verbose, "verbose", false, err);

if (verbose) {
verbose_enter();
}

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

if (verbose) {
verbose_leave();
verbose_stop(); // flush now
}

if (history) {
// history takes ownership
return;
Expand Down Expand Up @@ -1204,6 +1213,12 @@ Boolean nvim_paste(String data, Boolean crlf, Integer phase, Error *err)
draining = false;
}

// TODO(bfredl): ugly, maybe only when notification?
if (ERROR_SET(err)) {
semsg("paste: %s", err->msg);
api_clear_error(err);
}

return !cancel;
}

Expand Down
11 changes: 11 additions & 0 deletions src/nvim/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,17 @@ char *transstr(const char *const s, bool untab)
return buf;
}

size_t kv_transstr(StringBuilder *str, const char *const s, bool untab)
{
// Compute the length of the result, taking account of unprintable
// multi-byte characters.
const size_t len = transstr_len(s, untab);
kv_ensure_space(*str, len + 1);
transstr_buf(s, str->items + str->size, len + 1, untab);
str->size += len; // do not include NUL byte
return len;
}

/// Convert the string "str[orglen]" to do ignore-case comparing.
/// Use the current locale.
///
Expand Down
1 change: 1 addition & 0 deletions src/nvim/charset.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "nvim/eval/typval.h"
#include "nvim/option_defs.h"
#include "nvim/pos.h"
#include "nvim/strings.h"
#include "nvim/types.h"

/// Return the folded-case equivalent of the given character
Expand Down
3 changes: 1 addition & 2 deletions src/nvim/event/libuv_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ int libuv_process_spawn(LibuvProcess *uvproc)
uvproc->uvstdio[1].flags = UV_IGNORE;
uvproc->uvstdio[2].flags = UV_IGNORE;

// TODO: this should just be single flag!
if (TUI_process && !is_remote_client && !stdin_isatty) {
if (ui_client_embed && !stdin_isatty) {
uvproc->uvopts.stdio_count = 4;
uvproc->uvstdio[3].data.fd = 0;
uvproc->uvstdio[3].flags = UV_INHERIT_FD;
Expand Down
3 changes: 1 addition & 2 deletions src/nvim/event/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ static void on_process_exit(Process *proc)
ILOG("exited: pid=%d status=%d stoptime=%" PRIu64, proc->pid, proc->status,
proc->stopped_time);

if (TUI_process && !is_remote_client) {
// Set only in "builtin" TUI
if (ui_client_embed) {
server_process_exit_status = proc->status;
}
// Process has terminated, but there could still be data to be read from the
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/generators/gen_api_dispatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ for i = 1, #functions do
-- if the function recieves the array args, pass it the second argument
output:write('args, ')
end
output:write(call_args)
output:write(call_args)
else
output:write('channel_id')
if fn.receives_array_args then
Expand Down
22 changes: 13 additions & 9 deletions src/nvim/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,21 @@ EXTERN sctx_T current_sctx INIT(= { 0, 0, 0 });
// ID of the current channel making a client API call
EXTERN uint64_t current_channel_id INIT(= 0);

// ID of the client channel. Used by ui client
// ID of the ui client channel. Used by ui client
EXTERN uint64_t ui_client_channel_id INIT(= 0);

/// whether we are connecting to a remote neovim instance
EXTERN bool ui_client_remote INIT(= false);
/// whether we are embedding a neovim server as child process
EXTERN bool ui_client_embed INIT(= false);

EXTERN char *termname_local INIT(= "null");

/// This process is a TUI process (run the tui rather than executing the main loop)
EXTERN bool tui_process INIT(= false);

EXTERN long server_process_exit_status INIT(= false); // Used by TUI process

EXTERN bool did_source_packages INIT(= false);

// Scope information for the code that indirectly triggered the current
Expand Down Expand Up @@ -846,14 +858,6 @@ EXTERN linenr_T printer_page_num;
EXTERN bool typebuf_was_filled INIT(= false); // received text from client
// or from feedkeys()

EXTERN bool is_remote_client INIT(= false); // Initially the TUI is not
// a remote client

EXTERN bool TUI_process INIT(= false); // This is the TUI process


EXTERN long server_process_exit_status INIT(= false); // Used by TUI process

#ifdef BACKSLASH_IN_FILENAME
EXTERN char psepc INIT(= '\\'); // normal path separator character
EXTERN char psepcN INIT(= '/'); // abnormal path separator character
Expand Down
26 changes: 15 additions & 11 deletions src/nvim/highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,22 +933,26 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
CHECK_FLAG(dict, mask, italic, , HL_ITALIC);
CHECK_FLAG(dict, mask, reverse, , HL_INVERSE);
CHECK_FLAG(dict, mask, strikethrough, , HL_STRIKETHROUGH);
if (use_rgb) {
CHECK_FLAG(dict, mask, fg_indexed, , HL_FG_INDEXED);
CHECK_FLAG(dict, mask, bg_indexed, , HL_BG_INDEXED);
}
CHECK_FLAG(dict, mask, nocombine, , HL_NOCOMBINE);
CHECK_FLAG(dict, mask, default, _, HL_DEFAULT);

if (HAS_KEY(dict->fg)) {
fg = object_to_color(dict->fg, "fg", true, err);
fg = object_to_color(dict->fg, "fg", use_rgb, err);
} else if (HAS_KEY(dict->foreground)) {
fg = object_to_color(dict->foreground, "foreground", true, err);
fg = object_to_color(dict->foreground, "foreground", use_rgb, err);
}
if (ERROR_SET(err)) {
return hlattrs;
}

if (HAS_KEY(dict->bg)) {
bg = object_to_color(dict->bg, "bg", true, err);
bg = object_to_color(dict->bg, "bg", use_rgb, err);
} else if (HAS_KEY(dict->background)) {
bg = object_to_color(dict->background, "background", true, err);
bg = object_to_color(dict->background, "background", use_rgb, err);
}
if (ERROR_SET(err)) {
return hlattrs;
Expand Down Expand Up @@ -1035,11 +1039,11 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
}
}

// apply gui mask as default for cterm mask
if (!cterm_mask_provided) {
cterm_mask = mask;
}
if (use_rgb) {
// apply gui mask as default for cterm mask
if (!cterm_mask_provided) {
cterm_mask = mask;
}
hlattrs.rgb_ae_attr = mask;
hlattrs.rgb_bg_color = bg;
hlattrs.rgb_fg_color = fg;
Expand All @@ -1049,9 +1053,9 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
hlattrs.cterm_fg_color = ctermfg == -1 ? 0 : ctermfg + 1;
hlattrs.cterm_ae_attr = cterm_mask;
} else {
hlattrs.cterm_bg_color = ctermbg == -1 ? 0 : ctermbg + 1;
hlattrs.cterm_fg_color = ctermfg == -1 ? 0 : ctermfg + 1;
hlattrs.cterm_ae_attr = cterm_mask;
hlattrs.cterm_bg_color = bg == -1 ? 0 : bg + 1;
hlattrs.cterm_fg_color = fg == -1 ? 0 : fg + 1;
hlattrs.cterm_ae_attr = mask;
}

return hlattrs;
Expand Down
Loading

0 comments on commit d77dcde

Please sign in to comment.