mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.1.0742: getcmdprompt() implementation can be improved
Problem: getcmdprompt() implementation can be improved
Solution: Improve and simplify it (h-east)
closes: vim/vim#15743
25876a6cdd
Co-authored-by: h-east <h.east.727@gmail.com>
This commit is contained in:
@@ -813,8 +813,6 @@ static void f_confirm(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
const char *message = tv_get_string_chk(&argvars[0]);
|
||||
if (message == NULL) {
|
||||
error = true;
|
||||
} else {
|
||||
set_prompt(message);
|
||||
}
|
||||
if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||
buttons = tv_get_string_buf_chk(&argvars[1], buf);
|
||||
|
@@ -4132,26 +4132,13 @@ void f_getcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0;
|
||||
}
|
||||
|
||||
static char current_prompt[CMDBUFFSIZE + 1] = "";
|
||||
|
||||
/// Get current command line prompt.
|
||||
static char *get_prompt(void)
|
||||
{
|
||||
return current_prompt;
|
||||
}
|
||||
|
||||
/// Set current command line prompt.
|
||||
void set_prompt(const char *str)
|
||||
{
|
||||
xstrlcpy(current_prompt, str, sizeof(current_prompt));
|
||||
}
|
||||
|
||||
/// "getcmdprompt()" function
|
||||
void f_getcmdprompt(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
CmdlineInfo *p = get_ccline_ptr();
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = p != NULL ? xstrdup(get_prompt()) : NULL;
|
||||
rettv->vval.v_string = p != NULL && p->cmdprompt != NULL
|
||||
? xstrdup(p->cmdprompt) : NULL;
|
||||
}
|
||||
|
||||
/// "getcmdscreenpos()" function
|
||||
@@ -4752,8 +4739,6 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const
|
||||
const bool cmd_silent_save = cmd_silent;
|
||||
|
||||
cmd_silent = false; // Want to see the prompt.
|
||||
set_prompt(prompt);
|
||||
|
||||
// Only the part of the message after the last NL is considered as
|
||||
// prompt for the command line, unlsess cmdline is externalized
|
||||
const char *p = prompt;
|
||||
|
@@ -1567,6 +1567,17 @@ func Test_getcmdtype_getcmdprompt()
|
||||
call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
|
||||
call assert_equal('Answer?', g:cmdprompt)
|
||||
call assert_equal('', getcmdprompt())
|
||||
call feedkeys(":\<CR>\<ESC>", "xt")
|
||||
call assert_equal('', g:cmdprompt)
|
||||
call assert_equal('', getcmdprompt())
|
||||
|
||||
let str = "C" .. repeat("c", 1023) .. "xyz"
|
||||
call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
|
||||
call assert_equal(str, g:cmdprompt)
|
||||
|
||||
call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
|
||||
call assert_equal('Ans?', g:cmdprompt)
|
||||
call assert_equal('', getcmdprompt())
|
||||
|
||||
augroup test_CmdlineEnter
|
||||
au!
|
||||
|
Reference in New Issue
Block a user