ext_cmdline: use standard external ui functions

This commit is contained in:
Dongdong Zhou 2017-04-28 06:51:16 +01:00 committed by Björn Linse
parent b7a8a76f6e
commit 550651c130
5 changed files with 65 additions and 93 deletions

View File

@ -260,23 +260,13 @@ a dictionary with these (optional) keys:
colors.
Set to false to use terminal color codes (at
most 256 different colors).
`ext_popupmenu` Externalize the popupmenu. |ui-ext-popupmenu|
`ext_tabline` Externalize the tabline. |ui-ext-tabline|
`ext_cmdline` Externalize the cmdline. |ui-ext-cmdline|
Externalized widgets will not be drawn by
Nvim; only high-level data will be published
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"
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
@ -452,20 +442,14 @@ states might be represented as separate modes.
curtab: Current Tabpage
tabs: List of Dicts [{ "tab": Tabpage, "name": String }, ...]
*ui-ext-cmdline*
["cmdline_enter"]
Enter the cmdline.
["cmdline_leave"]
Leave the cmdline.
["cmdline_firstc", firstc]
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]
["cmdline_show", content, pos, firstc, prompt]
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
and cursor position to the remote ui. The content is the full content

View File

@ -11147,15 +11147,12 @@ void get_user_input(const typval_T *const argvars,
cmd_silent = false; // Want to see the prompt.
// Only the part of the message after the last NL is considered as
// prompt for the command line.
const char *p = strrchr(prompt, '\n');
if (ui_is_external(kUICmdline)) {
p = prompt;
} else {
if (p == NULL) {
p = prompt;
} else {
p++;
// prompt for the command line, unlsess cmdline is externalized
const char *p = prompt;
if (!ui_is_external(kUICmdline)) {
const char *lastnl = strrchr(prompt, '\n');
if (lastnl != NULL) {
p = lastnl+1;
msg_start();
msg_clr_eos();
msg_puts_attr_len(prompt, p - prompt, echo_attr);

View File

@ -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 bool cmdline_external = false;
/*
* Type used by call_user_expand_func
*/
@ -806,7 +804,7 @@ static int command_line_execute(VimState *state, int key)
}
if (!cmd_silent) {
if (!cmdline_external) {
if (!ui_is_external(kUICmdline)) {
ui_cursor_goto(msg_row, 0);
}
ui_flush();
@ -1832,12 +1830,12 @@ getcmdline (
int indent // indent for inside conditionals
)
{
if (cmdline_external) {
if (ui_is_external(kUICmdline)) {
Array args = ARRAY_DICT_INIT;
ui_event("cmdline_enter", args);
}
char_u *p = command_line_enter(firstc, count, indent);
if (cmdline_external) {
if (ui_is_external(kUICmdline)) {
Array args = ARRAY_DICT_INIT;
ui_event("cmdline_leave", args);
}
@ -2602,11 +2600,8 @@ static void draw_cmdline(int start, int len)
return;
}
if (cmdline_external) {
Array args = ARRAY_DICT_INIT;
ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
ADD(args, INTEGER_OBJ(ccline.cmdpos));
ui_event("cmdline", args);
if (ui_is_external(kUICmdline)) {
ui_ext_cmdline_show();
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
* 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)
{
if (cmd_silent)
if (cmd_silent) {
return;
if (!cmdline_external) {
}
if (!ui_is_external(kUICmdline)) {
msg_no_more = TRUE;
msg_putchar(c);
if (shift)
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
msg_no_more = FALSE;
} else {
char_u *p;
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);
ui_ext_cmdline_char(c, shift);
}
cursorcmd();
ui_cursor_shape();
@ -3104,27 +3113,19 @@ static void redrawcmdprompt(void)
if (cmd_silent)
return;
if (ui_is_external(kUICmdline)) {
ui_ext_cmdline_show();
return;
}
if (ccline.cmdfirstc != NUL) {
if (cmdline_external) {
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);
}
msg_putchar(ccline.cmdfirstc);
}
if (ccline.cmdprompt != NULL) {
if (cmdline_external) {
Array args = ARRAY_DICT_INIT;
ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt))));
ui_event("cmdline_prompt", args);
} else {
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--;
}
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 {
for (i = ccline.cmdindent; i > 0; i--) {
@ -3141,7 +3142,7 @@ void redrawcmd(void)
if (cmd_silent)
return;
if (cmdline_external) {
if (ui_is_external(kUICmdline)) {
draw_cmdline(0, ccline.cmdlen);
return;
}
@ -3189,7 +3190,7 @@ static void cursorcmd(void)
if (cmd_silent)
return;
if (cmdline_external) {
if (ui_is_external(kUICmdline)) {
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(ccline.cmdpos));
ui_event("cmdline_pos", args);
@ -3213,7 +3214,7 @@ static void cursorcmd(void)
void gotocmdline(int clr)
{
if (cmdline_external) {
if (ui_is_external(kUICmdline)) {
return;
}
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;
}

View File

@ -281,7 +281,6 @@ void ui_refresh(void)
int save_p_lz = p_lz;
p_lz = false; // convince redrawing() to return true ...
cmdline_set_external(cmdline_external);
screen_resize(width, height);
p_lz = save_p_lz;

View File

@ -7,23 +7,21 @@ if helpers.pending_win32(pending) then return end
describe('External command line completion', function()
local screen
local shown = false
local firstc, prompt, content, pos
local firstc, prompt, content, pos, char, shift
before_each(function()
clear()
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)
if name == "cmdline_enter" then
shown = true
elseif name == "cmdline_leave" then
shown = false
elseif name == "cmdline_firstc" then
firstc = data[1]
elseif name == "cmdline_prompt" then
prompt = data[1]
elseif name == "cmdline" then
content, pos = unpack(data)
elseif name == "cmdline_show" then
content, pos, firstc, prompt = unpack(data)
elseif name == "cmdline_char" then
char, shift = unpack(data)
elseif name == "cmdline_pos" then
pos = data[1]
end
@ -120,6 +118,8 @@ describe('External command line completion', function()
|
]], nil, nil, function()
eq("3", content)
eq("\"", char)
eq(1, shift)
end)
end)