mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ext_cmdline: added cmdline level
add cchar_to_string
This commit is contained in:
parent
ab85999eb7
commit
866dadaf75
@ -667,6 +667,22 @@ tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allocates a String consisting of a single char. Does not support multibyte
|
||||||
|
/// characters. The resulting string is also NUL-terminated, to facilitate
|
||||||
|
/// interoperating with code using C strings.
|
||||||
|
///
|
||||||
|
/// @param char the char to convert
|
||||||
|
/// @return the resulting String, if the input char was NUL, an
|
||||||
|
/// empty String is returned
|
||||||
|
String cchar_to_string(char c)
|
||||||
|
{
|
||||||
|
char buf[] = { c, NUL };
|
||||||
|
return (String) {
|
||||||
|
.data = xmemdupz(buf, 1),
|
||||||
|
.size = (c != NUL) ? 1 : 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Copies a C string into a String (binary safe string, characters + length).
|
/// Copies a C string into a String (binary safe string, characters + length).
|
||||||
/// The resulting string is also NUL-terminated, to facilitate interoperating
|
/// The resulting string is also NUL-terminated, to facilitate interoperating
|
||||||
/// with code using C strings.
|
/// with code using C strings.
|
||||||
|
@ -67,16 +67,13 @@ void popupmenu_select(Integer selected)
|
|||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void tabline_update(Tabpage current, Array tabs)
|
void tabline_update(Tabpage current, Array tabs)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
|
void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer level)
|
||||||
void cmdline_enter(void)
|
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void cmdline_show(Array content, Integer pos, String firstc, String prompt)
|
void cmdline_pos(Integer pos, Integer level)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void cmdline_pos(Integer pos)
|
void cmdline_char(String c, Integer shift, Integer level)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
void cmdline_char(String c, Integer shift)
|
void cmdline_hide(Integer level)
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
|
||||||
void cmdline_hide(void)
|
|
||||||
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
|
||||||
|
|
||||||
#endif // NVIM_API_UI_EVENTS_IN_H
|
#endif // NVIM_API_UI_EVENTS_IN_H
|
||||||
|
@ -91,6 +91,7 @@ struct cmdline_info {
|
|||||||
int input_fn; // when TRUE Invoked for input() function
|
int input_fn; // when TRUE Invoked for input() function
|
||||||
unsigned prompt_id; ///< Prompt number, used to disable coloring on errors.
|
unsigned prompt_id; ///< Prompt number, used to disable coloring on errors.
|
||||||
Callback highlight_callback; ///< Callback used for coloring user input.
|
Callback highlight_callback; ///< Callback used for coloring user input.
|
||||||
|
int level; // current cmdline level
|
||||||
};
|
};
|
||||||
/// Last value of prompt_id, incremented when doing new prompt
|
/// Last value of prompt_id, incremented when doing new prompt
|
||||||
static unsigned last_prompt_id = 0;
|
static unsigned last_prompt_id = 0;
|
||||||
@ -238,7 +239,9 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
|
|||||||
cmd_hkmap = 0;
|
cmd_hkmap = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(bfredl): can these be combined?
|
||||||
ccline.prompt_id = last_prompt_id++;
|
ccline.prompt_id = last_prompt_id++;
|
||||||
|
ccline.level++;
|
||||||
ccline.overstrike = false; // always start in insert mode
|
ccline.overstrike = false; // always start in insert mode
|
||||||
clearpos(&s->match_end);
|
clearpos(&s->match_end);
|
||||||
s->save_cursor = curwin->w_cursor; // may be restored later
|
s->save_cursor = curwin->w_cursor; // may be restored later
|
||||||
@ -414,6 +417,11 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
|
|||||||
|
|
||||||
// Make ccline empty, getcmdline() may try to use it.
|
// Make ccline empty, getcmdline() may try to use it.
|
||||||
ccline.cmdbuff = NULL;
|
ccline.cmdbuff = NULL;
|
||||||
|
|
||||||
|
if (ui_is_external(kUICmdline)) {
|
||||||
|
ui_call_cmdline_hide(ccline.level);
|
||||||
|
}
|
||||||
|
ccline.level--;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1830,14 +1838,7 @@ getcmdline (
|
|||||||
int indent // indent for inside conditionals
|
int indent // indent for inside conditionals
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (ui_is_external(kUICmdline)) {
|
return command_line_enter(firstc, count, indent);
|
||||||
ui_call_cmdline_enter();
|
|
||||||
}
|
|
||||||
char_u *p = command_line_enter(firstc, count, indent);
|
|
||||||
if (ui_is_external(kUICmdline)) {
|
|
||||||
ui_call_cmdline_hide();
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a command line with a prompt
|
/// Get a command line with a prompt
|
||||||
@ -2725,12 +2726,7 @@ void ui_ext_cmdline_show(void)
|
|||||||
ADD(text, STRING_OBJ(cstr_to_string("Normal")));
|
ADD(text, STRING_OBJ(cstr_to_string("Normal")));
|
||||||
ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
|
ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
|
||||||
ADD(content, ARRAY_OBJ(text));
|
ADD(content, ARRAY_OBJ(text));
|
||||||
char *firstc = (char []) { (char)ccline.cmdfirstc };
|
ui_call_cmdline_show(content, ccline.cmdpos, cchar_to_string((char)ccline.cmdfirstc), cstr_to_string((char *)(ccline.cmdprompt)), ccline.level);
|
||||||
String str = (String) {
|
|
||||||
.data = xmemdupz(firstc, 1),
|
|
||||||
.size = 1
|
|
||||||
};
|
|
||||||
ui_call_cmdline_show(content, ccline.cmdpos, str, cstr_to_string((char *)(ccline.cmdprompt)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2750,7 +2746,7 @@ void putcmdline(int c, int 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 {
|
||||||
ui_call_cmdline_char(cstr_to_string((char *)(&c)), shift);
|
ui_call_cmdline_char(cchar_to_string((char)(c)), shift, ccline.level);
|
||||||
}
|
}
|
||||||
cursorcmd();
|
cursorcmd();
|
||||||
ui_cursor_shape();
|
ui_cursor_shape();
|
||||||
@ -3178,7 +3174,7 @@ static void cursorcmd(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (ui_is_external(kUICmdline)) {
|
if (ui_is_external(kUICmdline)) {
|
||||||
ui_call_cmdline_pos(ccline.cmdpos);
|
ui_call_cmdline_pos(ccline.cmdpos, ccline.level);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,19 +7,19 @@ 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, char, shift
|
local firstc, prompt, content, pos, char, shift, level, current_hide_level
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear()
|
clear()
|
||||||
screen = Screen.new(25, 5)
|
screen = Screen.new(25, 5)
|
||||||
screen:attach({rgb=true, ext_cmdline=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_hide" then
|
||||||
shown = true
|
|
||||||
elseif name == "cmdline_hide" then
|
|
||||||
shown = false
|
shown = false
|
||||||
|
current_hide_level = data[1]
|
||||||
elseif name == "cmdline_show" then
|
elseif name == "cmdline_show" then
|
||||||
content, pos, firstc, prompt = unpack(data)
|
shown = true
|
||||||
|
content, pos, firstc, prompt, level = unpack(data)
|
||||||
elseif name == "cmdline_char" then
|
elseif name == "cmdline_char" then
|
||||||
char, shift = unpack(data)
|
char, shift = unpack(data)
|
||||||
elseif name == "cmdline_pos" then
|
elseif name == "cmdline_pos" then
|
||||||
@ -107,9 +107,34 @@ describe('External command line completion', function()
|
|||||||
eq("input", prompt)
|
eq("input", prompt)
|
||||||
eq({{'Normal', 'default'}}, content)
|
eq({{'Normal', 'default'}}, content)
|
||||||
end)
|
end)
|
||||||
|
feed('<cr>')
|
||||||
|
|
||||||
|
feed(':')
|
||||||
|
screen:expect([[
|
||||||
|
^ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
|
|
||||||
|
]], nil, nil, function()
|
||||||
|
eq(1, level)
|
||||||
|
end)
|
||||||
|
|
||||||
|
feed('<C-R>=1+2')
|
||||||
|
screen:expect([[
|
||||||
|
^ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
|
|
||||||
|
]], nil, nil, function()
|
||||||
|
eq({{'Normal', '1+2'}}, content)
|
||||||
|
eq("\"", char)
|
||||||
|
eq(1, shift)
|
||||||
|
eq(2, level)
|
||||||
|
end)
|
||||||
|
|
||||||
feed('<cr>')
|
feed('<cr>')
|
||||||
feed(':<C-R>=1+2<cr>')
|
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ |
|
^ |
|
||||||
~ |
|
~ |
|
||||||
@ -118,8 +143,19 @@ describe('External command line completion', function()
|
|||||||
|
|
|
|
||||||
]], nil, nil, function()
|
]], nil, nil, function()
|
||||||
eq({{'Normal', '3'}}, content)
|
eq({{'Normal', '3'}}, content)
|
||||||
eq("\"", char)
|
eq(2, current_hide_level)
|
||||||
eq(1, shift)
|
eq(1, level)
|
||||||
|
end)
|
||||||
|
|
||||||
|
feed('<esc>')
|
||||||
|
screen:expect([[
|
||||||
|
^ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
~ |
|
||||||
|
|
|
||||||
|
]], nil, nil, function()
|
||||||
|
eq(1, current_hide_level)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user