mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ext_cmdline: use standard external ui functions
This commit is contained in:
parent
b7a8a76f6e
commit
550651c130
@ -260,23 +260,13 @@ a dictionary with these (optional) keys:
|
|||||||
colors.
|
colors.
|
||||||
Set to false to use terminal color codes (at
|
Set to false to use terminal color codes (at
|
||||||
most 256 different colors).
|
most 256 different colors).
|
||||||
|
|
||||||
`ext_popupmenu` Externalize the popupmenu. |ui-ext-popupmenu|
|
`ext_popupmenu` Externalize the popupmenu. |ui-ext-popupmenu|
|
||||||
`ext_tabline` Externalize the tabline. |ui-ext-tabline|
|
`ext_tabline` Externalize the tabline. |ui-ext-tabline|
|
||||||
|
`ext_cmdline` Externalize the cmdline. |ui-ext-cmdline|
|
||||||
Externalized widgets will not be drawn by
|
Externalized widgets will not be drawn by
|
||||||
Nvim; only high-level data will be published
|
Nvim; only high-level data will be published
|
||||||
in new UI event kinds.
|
in new UI event kinds.
|
||||||
|
|
||||||
`popupmenu_external`: Instead of drawing the completion popupmenu on
|
|
||||||
the grid, Nvim will send higher-level events to
|
|
||||||
the ui and let it draw the popupmenu.
|
|
||||||
Defaults to false.
|
|
||||||
cmdline_external: Instead of drawing the cmdline on
|
|
||||||
the grid, Nvim will send higher-level events to
|
|
||||||
the ui and let it draw the cmdline.
|
|
||||||
Defaults to false.
|
|
||||||
|
|
||||||
|
|
||||||
Nvim will then send msgpack-rpc notifications, with the method name "redraw"
|
Nvim will then send msgpack-rpc notifications, with the method name "redraw"
|
||||||
and a single argument, an array of screen updates (described below). These
|
and a single argument, an array of screen updates (described below). These
|
||||||
should be processed in order. Preferably the user should only be able to see
|
should be processed in order. Preferably the user should only be able to see
|
||||||
@ -452,20 +442,14 @@ states might be represented as separate modes.
|
|||||||
curtab: Current Tabpage
|
curtab: Current Tabpage
|
||||||
tabs: List of Dicts [{ "tab": Tabpage, "name": String }, ...]
|
tabs: List of Dicts [{ "tab": Tabpage, "name": String }, ...]
|
||||||
|
|
||||||
|
*ui-ext-cmdline*
|
||||||
["cmdline_enter"]
|
["cmdline_enter"]
|
||||||
Enter the cmdline.
|
Enter the cmdline.
|
||||||
|
|
||||||
["cmdline_leave"]
|
["cmdline_leave"]
|
||||||
Leave the cmdline.
|
Leave the cmdline.
|
||||||
|
|
||||||
["cmdline_firstc", firstc]
|
["cmdline_show", content, pos, firstc, prompt]
|
||||||
The first character of the command, which could be : / ? etc. With
|
|
||||||
the firstc, you know wheither it's a command or a search.
|
|
||||||
|
|
||||||
["cmdline_prompt", prompt]
|
|
||||||
The prompt of the cmdline.
|
|
||||||
|
|
||||||
["cmdline", content, pos]
|
|
||||||
When cmdline_external is set to true, nvim will not draw the cmdline
|
When cmdline_external is set to true, nvim will not draw the cmdline
|
||||||
on the grad, instead nvim will send ui events of the cmdline content
|
on the grad, instead nvim will send ui events of the cmdline content
|
||||||
and cursor position to the remote ui. The content is the full content
|
and cursor position to the remote ui. The content is the full content
|
||||||
|
@ -11147,15 +11147,12 @@ void get_user_input(const typval_T *const argvars,
|
|||||||
|
|
||||||
cmd_silent = false; // Want to see the prompt.
|
cmd_silent = false; // Want to see the prompt.
|
||||||
// Only the part of the message after the last NL is considered as
|
// Only the part of the message after the last NL is considered as
|
||||||
// prompt for the command line.
|
// prompt for the command line, unlsess cmdline is externalized
|
||||||
const char *p = strrchr(prompt, '\n');
|
const char *p = prompt;
|
||||||
if (ui_is_external(kUICmdline)) {
|
if (!ui_is_external(kUICmdline)) {
|
||||||
p = prompt;
|
const char *lastnl = strrchr(prompt, '\n');
|
||||||
} else {
|
if (lastnl != NULL) {
|
||||||
if (p == NULL) {
|
p = lastnl+1;
|
||||||
p = prompt;
|
|
||||||
} else {
|
|
||||||
p++;
|
|
||||||
msg_start();
|
msg_start();
|
||||||
msg_clr_eos();
|
msg_clr_eos();
|
||||||
msg_puts_attr_len(prompt, p - prompt, echo_attr);
|
msg_puts_attr_len(prompt, p - prompt, echo_attr);
|
||||||
|
@ -185,8 +185,6 @@ static int cmd_showtail; /* Only show path tail in lists ? */
|
|||||||
|
|
||||||
static int new_cmdpos; /* position set by set_cmdline_pos() */
|
static int new_cmdpos; /* position set by set_cmdline_pos() */
|
||||||
|
|
||||||
static bool cmdline_external = false;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Type used by call_user_expand_func
|
* Type used by call_user_expand_func
|
||||||
*/
|
*/
|
||||||
@ -806,7 +804,7 @@ static int command_line_execute(VimState *state, int key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cmd_silent) {
|
if (!cmd_silent) {
|
||||||
if (!cmdline_external) {
|
if (!ui_is_external(kUICmdline)) {
|
||||||
ui_cursor_goto(msg_row, 0);
|
ui_cursor_goto(msg_row, 0);
|
||||||
}
|
}
|
||||||
ui_flush();
|
ui_flush();
|
||||||
@ -1832,12 +1830,12 @@ getcmdline (
|
|||||||
int indent // indent for inside conditionals
|
int indent // indent for inside conditionals
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (cmdline_external) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
ui_event("cmdline_enter", args);
|
ui_event("cmdline_enter", args);
|
||||||
}
|
}
|
||||||
char_u *p = command_line_enter(firstc, count, indent);
|
char_u *p = command_line_enter(firstc, count, indent);
|
||||||
if (cmdline_external) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
ui_event("cmdline_leave", args);
|
ui_event("cmdline_leave", args);
|
||||||
}
|
}
|
||||||
@ -2602,11 +2600,8 @@ static void draw_cmdline(int start, int len)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmdline_external) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
ui_ext_cmdline_show();
|
||||||
ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
|
|
||||||
ADD(args, INTEGER_OBJ(ccline.cmdpos));
|
|
||||||
ui_event("cmdline", args);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2725,6 +2720,32 @@ draw_cmdline_no_arabicshape:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_ext_cmdline_char(int c, int shift)
|
||||||
|
{
|
||||||
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
ADD(args, STRING_OBJ(cstr_to_string((char *)(&c))));
|
||||||
|
ADD(args, INTEGER_OBJ(shift));
|
||||||
|
ui_event("cmdline_char", args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ui_ext_cmdline_show(void)
|
||||||
|
{
|
||||||
|
Array args = ARRAY_DICT_INIT;
|
||||||
|
ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
|
||||||
|
ADD(args, INTEGER_OBJ(ccline.cmdpos));
|
||||||
|
if (ccline.cmdfirstc != NUL) {
|
||||||
|
ADD(args, STRING_OBJ(cstr_to_string((char *)(&ccline.cmdfirstc))));
|
||||||
|
} else {
|
||||||
|
ADD(args, STRING_OBJ(cstr_to_string("")));
|
||||||
|
}
|
||||||
|
if (ccline.cmdprompt != NULL) {
|
||||||
|
ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt))));
|
||||||
|
} else {
|
||||||
|
ADD(args, STRING_OBJ(cstr_to_string("")));
|
||||||
|
}
|
||||||
|
ui_event("cmdline_show", args);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put a character on the command line. Shifts the following text to the
|
* Put a character on the command line. Shifts the following text to the
|
||||||
* right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
|
* right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
|
||||||
@ -2732,29 +2753,17 @@ draw_cmdline_no_arabicshape:
|
|||||||
*/
|
*/
|
||||||
void putcmdline(int c, int shift)
|
void putcmdline(int c, int shift)
|
||||||
{
|
{
|
||||||
if (cmd_silent)
|
if (cmd_silent) {
|
||||||
return;
|
return;
|
||||||
if (!cmdline_external) {
|
}
|
||||||
|
if (!ui_is_external(kUICmdline)) {
|
||||||
msg_no_more = TRUE;
|
msg_no_more = TRUE;
|
||||||
msg_putchar(c);
|
msg_putchar(c);
|
||||||
if (shift)
|
if (shift)
|
||||||
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
||||||
msg_no_more = FALSE;
|
msg_no_more = FALSE;
|
||||||
} else {
|
} else {
|
||||||
char_u *p;
|
ui_ext_cmdline_char(c, shift);
|
||||||
if (ccline.cmdpos == ccline.cmdlen || shift) {
|
|
||||||
p = vim_strnsave(ccline.cmdbuff, ccline.cmdlen + 1);
|
|
||||||
} else {
|
|
||||||
p = vim_strsave(ccline.cmdbuff);
|
|
||||||
}
|
|
||||||
p[ccline.cmdpos] = c;
|
|
||||||
if (shift)
|
|
||||||
STRCPY(p + ccline.cmdpos + 1, ccline.cmdbuff + ccline.cmdpos);
|
|
||||||
Array args = ARRAY_DICT_INIT;
|
|
||||||
ADD(args, STRING_OBJ(cstr_to_string((char *)(p))));
|
|
||||||
ADD(args, INTEGER_OBJ(ccline.cmdpos));
|
|
||||||
ui_event("cmdline", args);
|
|
||||||
xfree(p);
|
|
||||||
}
|
}
|
||||||
cursorcmd();
|
cursorcmd();
|
||||||
ui_cursor_shape();
|
ui_cursor_shape();
|
||||||
@ -3104,27 +3113,19 @@ static void redrawcmdprompt(void)
|
|||||||
|
|
||||||
if (cmd_silent)
|
if (cmd_silent)
|
||||||
return;
|
return;
|
||||||
|
if (ui_is_external(kUICmdline)) {
|
||||||
|
ui_ext_cmdline_show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (ccline.cmdfirstc != NUL) {
|
if (ccline.cmdfirstc != NUL) {
|
||||||
if (cmdline_external) {
|
msg_putchar(ccline.cmdfirstc);
|
||||||
Array args = ARRAY_DICT_INIT;
|
|
||||||
ADD(args, STRING_OBJ(cstr_to_string((char *)(&ccline.cmdfirstc))));
|
|
||||||
ui_event("cmdline_firstc", args);
|
|
||||||
} else {
|
|
||||||
msg_putchar(ccline.cmdfirstc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (ccline.cmdprompt != NULL) {
|
if (ccline.cmdprompt != NULL) {
|
||||||
if (cmdline_external) {
|
msg_puts_attr((const char *)ccline.cmdprompt, ccline.cmdattr);
|
||||||
Array args = ARRAY_DICT_INIT;
|
ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
|
||||||
ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt))));
|
// do the reverse of set_cmdspos()
|
||||||
ui_event("cmdline_prompt", args);
|
if (ccline.cmdfirstc != NUL) {
|
||||||
} else {
|
ccline.cmdindent--;
|
||||||
msg_puts_attr((const char *)ccline.cmdprompt, ccline.cmdattr);
|
|
||||||
ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
|
|
||||||
// do the reverse of set_cmdspos()
|
|
||||||
if (ccline.cmdfirstc != NUL) {
|
|
||||||
ccline.cmdindent--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = ccline.cmdindent; i > 0; i--) {
|
for (i = ccline.cmdindent; i > 0; i--) {
|
||||||
@ -3141,7 +3142,7 @@ void redrawcmd(void)
|
|||||||
if (cmd_silent)
|
if (cmd_silent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cmdline_external) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
draw_cmdline(0, ccline.cmdlen);
|
draw_cmdline(0, ccline.cmdlen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3189,7 +3190,7 @@ static void cursorcmd(void)
|
|||||||
if (cmd_silent)
|
if (cmd_silent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cmdline_external) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
ADD(args, INTEGER_OBJ(ccline.cmdpos));
|
ADD(args, INTEGER_OBJ(ccline.cmdpos));
|
||||||
ui_event("cmdline_pos", args);
|
ui_event("cmdline_pos", args);
|
||||||
@ -3213,7 +3214,7 @@ static void cursorcmd(void)
|
|||||||
|
|
||||||
void gotocmdline(int clr)
|
void gotocmdline(int clr)
|
||||||
{
|
{
|
||||||
if (cmdline_external) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg_start();
|
msg_start();
|
||||||
@ -6044,12 +6045,3 @@ static void set_search_match(pos_T *t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdline_set_external(bool external)
|
|
||||||
{
|
|
||||||
cmdline_external = external;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cmdline_get_external(void)
|
|
||||||
{
|
|
||||||
return cmdline_external;
|
|
||||||
}
|
|
||||||
|
@ -281,7 +281,6 @@ void ui_refresh(void)
|
|||||||
|
|
||||||
int save_p_lz = p_lz;
|
int save_p_lz = p_lz;
|
||||||
p_lz = false; // convince redrawing() to return true ...
|
p_lz = false; // convince redrawing() to return true ...
|
||||||
cmdline_set_external(cmdline_external);
|
|
||||||
screen_resize(width, height);
|
screen_resize(width, height);
|
||||||
p_lz = save_p_lz;
|
p_lz = save_p_lz;
|
||||||
|
|
||||||
|
@ -7,23 +7,21 @@ if helpers.pending_win32(pending) then return end
|
|||||||
describe('External command line completion', function()
|
describe('External command line completion', function()
|
||||||
local screen
|
local screen
|
||||||
local shown = false
|
local shown = false
|
||||||
local firstc, prompt, content, pos
|
local firstc, prompt, content, pos, char, shift
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
clear()
|
||||||
screen = Screen.new(25, 5)
|
screen = Screen.new(25, 5)
|
||||||
screen:attach({rgb=true, cmdline_external=true})
|
screen:attach({rgb=true, ext_cmdline=true})
|
||||||
screen:set_on_event_handler(function(name, data)
|
screen:set_on_event_handler(function(name, data)
|
||||||
if name == "cmdline_enter" then
|
if name == "cmdline_enter" then
|
||||||
shown = true
|
shown = true
|
||||||
elseif name == "cmdline_leave" then
|
elseif name == "cmdline_leave" then
|
||||||
shown = false
|
shown = false
|
||||||
elseif name == "cmdline_firstc" then
|
elseif name == "cmdline_show" then
|
||||||
firstc = data[1]
|
content, pos, firstc, prompt = unpack(data)
|
||||||
elseif name == "cmdline_prompt" then
|
elseif name == "cmdline_char" then
|
||||||
prompt = data[1]
|
char, shift = unpack(data)
|
||||||
elseif name == "cmdline" then
|
|
||||||
content, pos = unpack(data)
|
|
||||||
elseif name == "cmdline_pos" then
|
elseif name == "cmdline_pos" then
|
||||||
pos = data[1]
|
pos = data[1]
|
||||||
end
|
end
|
||||||
@ -120,6 +118,8 @@ describe('External command line completion', function()
|
|||||||
|
|
|
|
||||||
]], nil, nil, function()
|
]], nil, nil, function()
|
||||||
eq("3", content)
|
eq("3", content)
|
||||||
|
eq("\"", char)
|
||||||
|
eq(1, shift)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user