From 439c39a2cfb0712eb68ad76354b1fd7e92bb71fe Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 23 Feb 2017 05:33:14 +0000 Subject: ext_cmdline: allow external ui to draw cmdline --- src/nvim/ex_getln.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++------ src/nvim/ui.c | 2 ++ 2 files changed, 73 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 54e5bcb9ff..87bf46d4d0 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -185,6 +185,8 @@ 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 */ @@ -281,7 +283,9 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) if (!cmd_silent) { s->i = msg_scrolled; msg_scrolled = 0; // avoid wait_return message - gotocmdline(true); + if (!cmdline_external) { + gotocmdline(true); + } msg_scrolled += s->i; redrawcmdprompt(); // draw prompt or indent set_cmdspos(); @@ -1828,7 +1832,16 @@ getcmdline ( int indent // indent for inside conditionals ) { - return command_line_enter(firstc, count, indent); + if (cmdline_external) { + Array args = ARRAY_DICT_INIT; + ui_event("cmdline_enter", args); + } + char_u *p = command_line_enter(firstc, count, indent); + if (cmdline_external) { + Array args = ARRAY_DICT_INIT; + ui_event("cmdline_leave", args); + } + return p; } /// Get a command line with a prompt @@ -2589,6 +2602,14 @@ 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); + return; + } + if (cmdline_star > 0) { for (int i = 0; i < len; i++) { msg_putchar('*'); @@ -2713,11 +2734,28 @@ void putcmdline(int c, int shift) { if (cmd_silent) return; - msg_no_more = TRUE; - msg_putchar(c); - if (shift) - draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); - msg_no_more = FALSE; + if (!cmdline_external) { + 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); + } cursorcmd(); ui_cursor_shape(); } @@ -3066,8 +3104,15 @@ static void redrawcmdprompt(void) if (cmd_silent) return; - if (ccline.cmdfirstc != NUL) - msg_putchar(ccline.cmdfirstc); + 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); + } + } if (ccline.cmdprompt != NULL) { msg_puts_attr((const char *)ccline.cmdprompt, ccline.cmdattr); ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; @@ -3087,6 +3132,11 @@ void redrawcmd(void) if (cmd_silent) return; + if (cmdline_external) { + draw_cmdline(0, ccline.cmdlen); + return; + } + /* when 'incsearch' is set there may be no command line while redrawing */ if (ccline.cmdbuff == NULL) { ui_cursor_goto(cmdline_row, 0); @@ -3130,6 +3180,13 @@ static void cursorcmd(void) if (cmd_silent) return; + if (cmdline_external) { + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(ccline.cmdpos)); + ui_event("cmdline_pos", args); + return; + } + if (cmdmsg_rl) { msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; @@ -5974,3 +6031,8 @@ static void set_search_match(pos_T *t) coladvance((colnr_T)MAXCOL); } } + +void cmdline_set_external(bool external) +{ + cmdline_external = external; +} diff --git a/src/nvim/ui.c b/src/nvim/ui.c index afe7a51d43..0fa4034ff6 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -30,6 +30,7 @@ #include "nvim/os/input.h" #include "nvim/os/signal.h" #include "nvim/popupmnu.h" +#include "nvim/ex_getln.h" #include "nvim/screen.h" #include "nvim/syntax.h" #include "nvim/window.h" @@ -280,6 +281,7 @@ 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; -- cgit From 6e90bc7200c87f0af448a8cf0998715db9175f15 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 23 Feb 2017 09:53:12 +0000 Subject: ext_cmdline: Added cmdline prompt --- src/nvim/eval.c | 18 +++++++++++------- src/nvim/ex_getln.c | 21 ++++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index aab777955c..72b97cbab9 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -11149,15 +11149,19 @@ void get_user_input(const typval_T *const argvars, // 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 (p == NULL) { + if (ui_is_external(kUICmdline)) { p = prompt; } else { - p++; - msg_start(); - msg_clr_eos(); - msg_puts_attr_len(prompt, p - prompt, echo_attr); - msg_didout = false; - msg_starthere(); + if (p == NULL) { + p = prompt; + } else { + p++; + msg_start(); + msg_clr_eos(); + msg_puts_attr_len(prompt, p - prompt, echo_attr); + msg_didout = false; + msg_starthere(); + } } cmdline_row = msg_row; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 87bf46d4d0..a05331d13a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3114,11 +3114,17 @@ static void redrawcmdprompt(void) } } if (ccline.cmdprompt != NULL) { - 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; + 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; + } } else for (i = ccline.cmdindent; i > 0; --i) msg_putchar(' '); @@ -6036,3 +6042,8 @@ void cmdline_set_external(bool external) { cmdline_external = external; } + +bool cmdline_get_external(void) +{ + return cmdline_external; +} -- cgit From 26fd70bd18283701a2ade11407694485cd0f7e35 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 24 Feb 2017 07:26:39 +0000 Subject: ext_cmdline: add tests --- src/nvim/ex_getln.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a05331d13a..18d6b26595 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -283,9 +283,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) if (!cmd_silent) { s->i = msg_scrolled; msg_scrolled = 0; // avoid wait_return message - if (!cmdline_external) { - gotocmdline(true); - } + gotocmdline(true); msg_scrolled += s->i; redrawcmdprompt(); // draw prompt or indent set_cmdspos(); @@ -808,7 +806,9 @@ static int command_line_execute(VimState *state, int key) } if (!cmd_silent) { - ui_cursor_goto(msg_row, 0); + if (!cmdline_external) { + ui_cursor_goto(msg_row, 0); + } ui_flush(); } return 0; @@ -3210,6 +3210,9 @@ static void cursorcmd(void) void gotocmdline(int clr) { + if (cmdline_external) { + return; + } msg_start(); if (cmdmsg_rl) msg_col = Columns - 1; -- cgit From b7a8a76f6e3b2de1cfdf32e3ccc66d87ab8e5cad Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 27 Feb 2017 02:56:38 +0000 Subject: ext_cmdline: lint --- src/nvim/ex_getln.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 18d6b26595..0fae6c9810 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3121,13 +3121,16 @@ static void redrawcmdprompt(void) } 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; + // do the reverse of set_cmdspos() + if (ccline.cmdfirstc != NUL) { + ccline.cmdindent--; + } } - } else - for (i = ccline.cmdindent; i > 0; --i) + } else { + for (i = ccline.cmdindent; i > 0; i--) { msg_putchar(' '); + } + } } /* -- cgit From 550651c130c014e6c668644273db31dd96be475e Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 28 Apr 2017 06:51:16 +0100 Subject: ext_cmdline: use standard external ui functions --- src/nvim/eval.c | 15 +++----- src/nvim/ex_getln.c | 104 ++++++++++++++++++++++++---------------------------- src/nvim/ui.c | 1 - 3 files changed, 54 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 72b97cbab9..3c9614dfcd 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0fae6c9810..8c9e081c89 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -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; -} diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 0fa4034ff6..6b09f6e6db 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -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; -- cgit From daec81ab5179c7ce8e3813af556b1e2f05fc59c6 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 28 Apr 2017 07:49:45 +0100 Subject: ext_cmdline: change the content format --- src/nvim/ex_getln.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 8c9e081c89..12f3f53c81 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2731,7 +2731,12 @@ void ui_ext_cmdline_char(int c, int shift) void ui_ext_cmdline_show(void) { Array args = ARRAY_DICT_INIT; - ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); + Array content = ARRAY_DICT_INIT; + Array text = ARRAY_DICT_INIT; + ADD(text, STRING_OBJ(cstr_to_string("Normal"))); + ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); + ADD(content, ARRAY_OBJ(text)); + ADD(args, ARRAY_OBJ(content)); ADD(args, INTEGER_OBJ(ccline.cmdpos)); if (ccline.cmdfirstc != NUL) { ADD(args, STRING_OBJ(cstr_to_string((char *)(&ccline.cmdfirstc)))); -- cgit From e164ba41c8460d4e5b2e7e2b929d8479a0310738 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 11 May 2017 04:48:59 +0100 Subject: ext_cmdline: fix firstc, change cmdline_leave to cmdline_hide --- src/nvim/ex_getln.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 12f3f53c81..34547c59c9 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1837,7 +1837,7 @@ getcmdline ( char_u *p = command_line_enter(firstc, count, indent); if (ui_is_external(kUICmdline)) { Array args = ARRAY_DICT_INIT; - ui_event("cmdline_leave", args); + ui_event("cmdline_hide", args); } return p; } @@ -2738,16 +2738,13 @@ void ui_ext_cmdline_show(void) ADD(content, ARRAY_OBJ(text)); ADD(args, ARRAY_OBJ(content)); 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(""))); - } + char *firstc = (char []) { (char)ccline.cmdfirstc }; + String str = (String) { + .data = xmemdupz(firstc, 1), + .size = 1 + }; + ADD(args, STRING_OBJ(str)); + ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt)))); ui_event("cmdline_show", args); } -- cgit From ab85999eb7c53e9d2b5bca5f8896ea11cb1df13e Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 11 May 2017 07:11:21 +0100 Subject: ext_cmdline: change to use ui_call --- src/nvim/api/ui_events.in.h | 11 +++++++++++ src/nvim/ex_getln.c | 27 +++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 1b5d17584f..093251bb00 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -68,4 +68,15 @@ void popupmenu_select(Integer selected) void tabline_update(Tabpage current, Array tabs) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_enter(void) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_show(Array content, Integer pos, String firstc, String prompt) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_pos(Integer pos) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_char(String c, Integer shift) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_hide(void) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; + #endif // NVIM_API_UI_EVENTS_IN_H diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 34547c59c9..0223d9e936 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1831,13 +1831,11 @@ getcmdline ( ) { if (ui_is_external(kUICmdline)) { - Array args = ARRAY_DICT_INIT; - ui_event("cmdline_enter", args); + ui_call_cmdline_enter(); } char_u *p = command_line_enter(firstc, count, indent); if (ui_is_external(kUICmdline)) { - Array args = ARRAY_DICT_INIT; - ui_event("cmdline_hide", args); + ui_call_cmdline_hide(); } return p; } @@ -2720,32 +2718,19 @@ 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; Array content = ARRAY_DICT_INIT; Array text = ARRAY_DICT_INIT; ADD(text, STRING_OBJ(cstr_to_string("Normal"))); ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); ADD(content, ARRAY_OBJ(text)); - ADD(args, ARRAY_OBJ(content)); - ADD(args, INTEGER_OBJ(ccline.cmdpos)); char *firstc = (char []) { (char)ccline.cmdfirstc }; String str = (String) { .data = xmemdupz(firstc, 1), .size = 1 }; - ADD(args, STRING_OBJ(str)); - ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt)))); - ui_event("cmdline_show", args); + ui_call_cmdline_show(content, ccline.cmdpos, str, cstr_to_string((char *)(ccline.cmdprompt))); } /* @@ -2765,7 +2750,7 @@ void putcmdline(int c, int shift) draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); msg_no_more = FALSE; } else { - ui_ext_cmdline_char(c, shift); + ui_call_cmdline_char(cstr_to_string((char *)(&c)), shift); } cursorcmd(); ui_cursor_shape(); @@ -3193,9 +3178,7 @@ static void cursorcmd(void) return; if (ui_is_external(kUICmdline)) { - Array args = ARRAY_DICT_INIT; - ADD(args, INTEGER_OBJ(ccline.cmdpos)); - ui_event("cmdline_pos", args); + ui_call_cmdline_pos(ccline.cmdpos); return; } -- cgit From 866dadaf753ba3733feb8c22d7da47af757bd35c Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Thu, 11 May 2017 07:51:10 +0100 Subject: ext_cmdline: added cmdline level add cchar_to_string --- src/nvim/api/private/helpers.c | 16 ++++++++++++++++ src/nvim/api/ui_events.in.h | 11 ++++------- src/nvim/ex_getln.c | 40 ++++++++++++++++++---------------------- 3 files changed, 38 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index e736e29e2d..f00fbf69ea 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -667,6 +667,22 @@ tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err) 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). /// The resulting string is also NUL-terminated, to facilitate interoperating /// with code using C strings. diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 093251bb00..17eefbe1d6 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -66,17 +66,14 @@ void popupmenu_hide(void) void popupmenu_select(Integer selected) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void tabline_update(Tabpage current, Array tabs) - FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; - -void cmdline_enter(void) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_show(Array content, Integer pos, String firstc, String prompt) +void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_pos(Integer pos) +void cmdline_pos(Integer pos, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_char(String c, Integer shift) +void cmdline_char(String c, Integer shift, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_hide(void) +void cmdline_hide(Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; #endif // NVIM_API_UI_EVENTS_IN_H diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0223d9e936..548459a8ce 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -91,6 +91,7 @@ struct cmdline_info { int input_fn; // when TRUE Invoked for input() function unsigned prompt_id; ///< Prompt number, used to disable coloring on errors. Callback highlight_callback; ///< Callback used for coloring user input. + int level; // current cmdline level }; /// Last value of prompt_id, incremented when doing new prompt 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; } + // TODO(bfredl): can these be combined? ccline.prompt_id = last_prompt_id++; + ccline.level++; ccline.overstrike = false; // always start in insert mode clearpos(&s->match_end); 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. ccline.cmdbuff = NULL; + + if (ui_is_external(kUICmdline)) { + ui_call_cmdline_hide(ccline.level); + } + ccline.level--; return p; } } @@ -1830,14 +1838,7 @@ getcmdline ( int indent // indent for inside conditionals ) { - if (ui_is_external(kUICmdline)) { - ui_call_cmdline_enter(); - } - char_u *p = command_line_enter(firstc, count, indent); - if (ui_is_external(kUICmdline)) { - ui_call_cmdline_hide(); - } - return p; + return command_line_enter(firstc, count, indent); } /// Get a command line with a prompt @@ -2720,17 +2721,12 @@ draw_cmdline_no_arabicshape: void ui_ext_cmdline_show(void) { - Array content = ARRAY_DICT_INIT; - Array text = ARRAY_DICT_INIT; - ADD(text, STRING_OBJ(cstr_to_string("Normal"))); - ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); - ADD(content, ARRAY_OBJ(text)); - char *firstc = (char []) { (char)ccline.cmdfirstc }; - String str = (String) { - .data = xmemdupz(firstc, 1), - .size = 1 - }; - ui_call_cmdline_show(content, ccline.cmdpos, str, cstr_to_string((char *)(ccline.cmdprompt))); + Array content = ARRAY_DICT_INIT; + Array text = ARRAY_DICT_INIT; + ADD(text, STRING_OBJ(cstr_to_string("Normal"))); + ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); + ADD(content, ARRAY_OBJ(text)); + ui_call_cmdline_show(content, ccline.cmdpos, cchar_to_string((char)ccline.cmdfirstc), cstr_to_string((char *)(ccline.cmdprompt)), ccline.level); } /* @@ -2750,7 +2746,7 @@ void putcmdline(int c, int shift) draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); msg_no_more = FALSE; } else { - ui_call_cmdline_char(cstr_to_string((char *)(&c)), shift); + ui_call_cmdline_char(cchar_to_string((char)(c)), shift, ccline.level); } cursorcmd(); ui_cursor_shape(); @@ -3178,7 +3174,7 @@ static void cursorcmd(void) return; if (ui_is_external(kUICmdline)) { - ui_call_cmdline_pos(ccline.cmdpos); + ui_call_cmdline_pos(ccline.cmdpos, ccline.level); return; } @@ -3200,7 +3196,7 @@ static void cursorcmd(void) void gotocmdline(int clr) { if (ui_is_external(kUICmdline)) { - return; + return; } msg_start(); if (cmdmsg_rl) -- cgit From 461ae698242458bffbf5fb68de89fe8b2a3defd2 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 26 Jun 2017 11:19:40 +0100 Subject: ext_cmdline: Add function block support --- src/nvim/api/ui_events.in.h | 4 ++++ src/nvim/eval.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 17eefbe1d6..5602dc6df3 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -75,5 +75,9 @@ void cmdline_char(String c, Integer shift, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_hide(Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_function_show(void) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_function_hide(void) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; #endif // NVIM_API_UI_EVENTS_IN_H diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 3c9614dfcd..d5ff01e922 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -19816,6 +19816,10 @@ void ex_function(exarg_T *eap) goto errret_2; } + if (ui_is_external(kUICmdline)) { + ui_call_cmdline_function_show(); + } + // find extra arguments "range", "dict", "abort" and "closure" for (;; ) { p = skipwhite(p); @@ -19868,7 +19872,9 @@ void ex_function(exarg_T *eap) if (!eap->skip && did_emsg) goto erret; - msg_putchar('\n'); /* don't overwrite the function name */ + if (!ui_is_external(kUICmdline)) { + msg_putchar('\n'); /* don't overwrite the function name */ + } cmdline_row = msg_row; } @@ -20194,6 +20200,9 @@ ret_free: xfree(name); did_emsg |= saved_did_emsg; need_wait_return |= saved_wait_return; + if (ui_is_external(kUICmdline)) { + ui_call_cmdline_function_hide(); + } } /// Get a function name, translating "" and "". -- cgit From fb389a6b4b1e6fedb559dc2e5845dd138e8ff264 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 26 Jun 2017 15:27:49 +0100 Subject: ext_cmdline: added indent --- src/nvim/api/ui_events.in.h | 2 +- src/nvim/ex_getln.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 5602dc6df3..700d99dc6b 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -67,7 +67,7 @@ void popupmenu_select(Integer selected) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void tabline_update(Tabpage current, Array tabs) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer level) +void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer indent, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_pos(Integer pos, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 548459a8ce..6f941e66ef 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2726,7 +2726,11 @@ void ui_ext_cmdline_show(void) ADD(text, STRING_OBJ(cstr_to_string("Normal"))); ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); ADD(content, ARRAY_OBJ(text)); - ui_call_cmdline_show(content, ccline.cmdpos, cchar_to_string((char)ccline.cmdfirstc), cstr_to_string((char *)(ccline.cmdprompt)), ccline.level); + ui_call_cmdline_show(content, ccline.cmdpos, + cchar_to_string((char)ccline.cmdfirstc), + cstr_to_string((char *)(ccline.cmdprompt)), + ccline.cmdindent, + ccline.level); } /* -- cgit From 5ad591ef2d0ef184f78c728b1774c2a55fe2e581 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Tue, 27 Jun 2017 02:20:27 +0100 Subject: ext_cmdline: lint --- src/nvim/api/ui_events.in.h | 17 +++++++++-------- src/nvim/eval.c | 2 +- src/nvim/ex_getln.c | 7 ++++--- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 700d99dc6b..bb1084c838 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -66,18 +66,19 @@ void popupmenu_hide(void) void popupmenu_select(Integer selected) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void tabline_update(Tabpage current, Array tabs) - FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer indent, Integer level) - 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 indent, Integer level) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; 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_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_hide(Integer level) - FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_function_show(void) - FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_function_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 diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d5ff01e922..5f655cdc7b 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -19873,7 +19873,7 @@ void ex_function(exarg_T *eap) goto erret; if (!ui_is_external(kUICmdline)) { - msg_putchar('\n'); /* don't overwrite the function name */ + msg_putchar('\n'); // don't overwrite the function name } cmdline_row = msg_row; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6f941e66ef..93c060b4b7 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2744,11 +2744,12 @@ void putcmdline(int c, int shift) return; } if (!ui_is_external(kUICmdline)) { - msg_no_more = TRUE; + msg_no_more = true; msg_putchar(c); - if (shift) + if (shift) { draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); - msg_no_more = FALSE; + } + msg_no_more = false; } else { ui_call_cmdline_char(cchar_to_string((char)(c)), shift, ccline.level); } -- cgit From 22402fb99d05191cf140293cfb5f67902e78a8a8 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 12:19:29 +0200 Subject: ext_cmdline: add support for highlighting --- src/nvim/api/private/helpers.c | 17 +++++++++++++++++ src/nvim/ex_getln.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index f00fbf69ea..2944925a9c 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -703,6 +703,23 @@ String cstr_to_string(const char *str) }; } +/// Copies buffer to an allocated String. +/// The resulting string is also NUL-terminated, to facilitate interoperating +/// with code using C strings. +/// +/// @param buf the buffer to copy +/// @param size length of the buffer +/// @return the resulting String, if the input string was NULL, an +/// empty String is returned +String cbuf_to_string(const char *buf, size_t size) + FUNC_ATTR_NONNULL_ALL +{ + return (String) { + .data = xmemdupz(buf, size), + .size = size + }; +} + /// Creates a String using the given C string. Unlike /// cstr_to_string this function DOES NOT copy the C string. /// diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 93c060b4b7..624a108bd4 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2372,6 +2372,7 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline, FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { bool printed_errmsg = false; + #define PRINT_ERRMSG(...) \ do { \ msg_putchar('\n'); \ @@ -2405,7 +2406,7 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline, static unsigned prev_prompt_id = UINT_MAX; static int prev_prompt_errors = 0; - Callback color_cb = { .type = kCallbackNone }; + Callback color_cb = CALLBACK_NONE; bool can_free_cb = false; TryState tstate; Error err = ERROR_INIT; @@ -2722,10 +2723,30 @@ draw_cmdline_no_arabicshape: void ui_ext_cmdline_show(void) { Array content = ARRAY_DICT_INIT; - Array text = ARRAY_DICT_INIT; - ADD(text, STRING_OBJ(cstr_to_string("Normal"))); - ADD(text, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); - ADD(content, ARRAY_OBJ(text)); + if (kv_size(last_ccline_colors.colors)) { + for (size_t i = 0; i < kv_size(last_ccline_colors.colors); i++) { + CmdlineColorChunk chunk = kv_A(last_ccline_colors.colors, i); + Array item = ARRAY_DICT_INIT; + + if (chunk.attr) { + attrentry_T *aep = syn_cterm_attr2entry(chunk.attr); + // TODO(bfredl): this desicion could be delayed by making attr_code a + // recognized type + HlAttrs rgb_attrs = attrentry2hlattrs(aep, true); + ADD(item, DICTIONARY_OBJ(hlattrs2dict(rgb_attrs))); + } else { + ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); + } + ADD(item, STRING_OBJ(cbuf_to_string((char *)ccline.cmdbuff + chunk.start, + chunk.end-chunk.start))); + ADD(content, ARRAY_OBJ(item)); + } + } else { + Array item = ARRAY_DICT_INIT; + ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); + ADD(item, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); + ADD(content, ARRAY_OBJ(item)); + } ui_call_cmdline_show(content, ccline.cmdpos, cchar_to_string((char)ccline.cmdfirstc), cstr_to_string((char *)(ccline.cmdprompt)), -- cgit From ddfc077da468450d1fab81fe3b3f594bb6ebf6dd Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 13:36:02 +0200 Subject: ext_cmdline: disable some redraws --- src/nvim/ex_getln.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 624a108bd4..0e620e59d8 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1144,7 +1144,7 @@ static int command_line_handle_key(CommandLineState *s) xfree(ccline.cmdbuff); // no commandline to return ccline.cmdbuff = NULL; - if (!cmd_silent) { + if (!cmd_silent && !ui_is_external(kUICmdline)) { if (cmdmsg_rl) { msg_col = Columns; } else { @@ -1596,9 +1596,14 @@ static int command_line_handle_key(CommandLineState *s) s->do_abbr = false; // don't do abbreviation now // may need to remove ^ when composing char was typed if (enc_utf8 && utf_iscomposing(s->c) && !cmd_silent) { - draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); - msg_putchar(' '); - cursorcmd(); + if (ui_is_external(kUICmdline)) { + // TODO(bfredl): why not make unputcmdline also work with true? + unputcmdline(); + } else { + draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); + msg_putchar(' '); + cursorcmd(); + } } break; @@ -2778,22 +2783,19 @@ void putcmdline(int c, int shift) ui_cursor_shape(); } -/* - * Undo a putcmdline(c, FALSE). - */ +/// Undo a putcmdline(c, FALSE). void unputcmdline(void) { - if (cmd_silent) + if (cmd_silent) { return; - msg_no_more = TRUE; - if (ccline.cmdlen == ccline.cmdpos) + } + msg_no_more = true; + if (ccline.cmdlen == ccline.cmdpos && !ui_is_external(kUICmdline)) { msg_putchar(' '); - else if (has_mbyte) - draw_cmdline(ccline.cmdpos, - (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); - else - draw_cmdline(ccline.cmdpos, 1); - msg_no_more = FALSE; + } else { + draw_cmdline(ccline.cmdpos, mb_ptr2len(ccline.cmdbuff + ccline.cmdpos)); + } + msg_no_more = false; cursorcmd(); ui_cursor_shape(); } -- cgit From a68817f56517a31943806bd0b5a0030cdd35e182 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 13:57:58 +0200 Subject: ext_cmdline: extend "function" to generic "block" mechanism --- src/nvim/api/ui_events.in.h | 7 +++++-- src/nvim/eval.c | 13 +++++++++---- src/nvim/ex_getln.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index bb1084c838..764078c6bd 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -67,6 +67,7 @@ void popupmenu_select(Integer selected) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void tabline_update(Tabpage current, Array tabs) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; + void cmdline_show(Array content, Integer pos, String firstc, String prompt, Integer indent, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; @@ -76,9 +77,11 @@ void cmdline_char(String c, Integer shift, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_hide(Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_function_show(void) +void cmdline_block_show(Array lines) + FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; +void cmdline_block_append(Array lines) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_function_hide(void) +void cmdline_block_hide(void) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; #endif // NVIM_API_UI_EVENTS_IN_H diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5f655cdc7b..50044718b6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -19643,6 +19643,7 @@ void ex_function(exarg_T *eap) int todo; hashitem_T *hi; int sourcing_lnum_off; + bool show_block = false; /* * ":function" without argument: list functions. @@ -19816,8 +19817,9 @@ void ex_function(exarg_T *eap) goto errret_2; } - if (ui_is_external(kUICmdline)) { - ui_call_cmdline_function_show(); + if (KeyTyped && ui_is_external(kUICmdline)) { + show_block = true; + ui_ext_cmdline_block_append(0, (const char *)eap->cmd); } // find extra arguments "range", "dict", "abort" and "closure" @@ -19908,6 +19910,9 @@ void ex_function(exarg_T *eap) EMSG(_("E126: Missing :endfunction")); goto erret; } + if (show_block) { + ui_ext_cmdline_block_append(indent, (const char *)theline); + } /* Detect line continuation: sourcing_lnum increased more than one. */ if (sourcing_lnum > sourcing_lnum_off + 1) @@ -20200,8 +20205,8 @@ ret_free: xfree(name); did_emsg |= saved_did_emsg; need_wait_return |= saved_wait_return; - if (ui_is_external(kUICmdline)) { - ui_call_cmdline_function_hide(); + if (show_block) { + ui_ext_cmdline_block_leave(); } } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0e620e59d8..50cccc8d10 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -186,6 +186,8 @@ static int cmd_showtail; /* Only show path tail in lists ? */ static int new_cmdpos; /* position set by set_cmdline_pos() */ +static Array cmdline_block; ///< currently displayed block of context + /* * Type used by call_user_expand_func */ @@ -2759,6 +2761,32 @@ void ui_ext_cmdline_show(void) ccline.level); } +void ui_ext_cmdline_block_append(int indent, const char *line) +{ + char *buf = xmallocz(indent + strlen(line)); + memset(buf, ' ', indent); + memcpy(buf+indent, line, strlen(line)); + + Array item = ARRAY_DICT_INIT; + ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); + ADD(item, STRING_OBJ(cstr_as_string(buf))); + Array content = ARRAY_DICT_INIT; + ADD(content, ARRAY_OBJ(item)); + ADD(cmdline_block, ARRAY_OBJ(content)); + if (cmdline_block.size > 1) { + ui_call_cmdline_block_append(copy_array(content)); + } else { + ui_call_cmdline_block_show(copy_array(cmdline_block)); + } +} + +void ui_ext_cmdline_block_leave(void) +{ + api_free_array(cmdline_block); + ui_call_cmdline_block_hide(); +} + + /* * 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. -- cgit From f2aaa4ae8b84f74666b4379b391f333f34868a45 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 16 Aug 2017 15:38:12 +0200 Subject: ext_cmdline: rename cmdline_char to cmdline_special_char --- src/nvim/api/ui_events.in.h | 2 +- src/nvim/ex_getln.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h index 764078c6bd..65357d008a 100644 --- a/src/nvim/api/ui_events.in.h +++ b/src/nvim/api/ui_events.in.h @@ -73,7 +73,7 @@ void cmdline_show(Array content, Integer pos, String firstc, String prompt, FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_pos(Integer pos, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; -void cmdline_char(String c, Integer shift, Integer level) +void cmdline_special_char(String c, Boolean shift, Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; void cmdline_hide(Integer level) FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 50cccc8d10..b9cf7b977c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2805,7 +2805,8 @@ void putcmdline(int c, int shift) } msg_no_more = false; } else { - ui_call_cmdline_char(cchar_to_string((char)(c)), shift, ccline.level); + ui_call_cmdline_special_char(cchar_to_string((char)(c)), shift, + ccline.level); } cursorcmd(); ui_cursor_shape(); -- cgit From 2050e6604632e190a04d52829f4469f1ef7f7018 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 20 Aug 2017 16:30:09 +0200 Subject: ext_cmdline: turn nested cmdlines into a linked list --- src/nvim/ex_getln.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b9cf7b977c..2ac9ecdc2b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -92,6 +92,7 @@ struct cmdline_info { unsigned prompt_id; ///< Prompt number, used to disable coloring on errors. Callback highlight_callback; ///< Callback used for coloring user input. int level; // current cmdline level + struct cmdline_info *prev_ccline; ///< pointer to saved cmdline state }; /// Last value of prompt_id, incremented when doing new prompt static unsigned last_prompt_id = 0; @@ -2958,9 +2959,6 @@ void put_on_cmdline(char_u *str, int len, int redraw) msg_check(); } -static struct cmdline_info prev_ccline; -static int prev_ccline_used = FALSE; - /* * Save ccline, because obtaining the "=" register may execute "normal :cmd" * and overwrite it. But get_cmdline_str() may need it, thus make it @@ -2968,12 +2966,8 @@ static int prev_ccline_used = FALSE; */ static void save_cmdline(struct cmdline_info *ccp) { - if (!prev_ccline_used) { - memset(&prev_ccline, 0, sizeof(struct cmdline_info)); - prev_ccline_used = TRUE; - } - *ccp = prev_ccline; - prev_ccline = ccline; + *ccp = ccline; + ccline.prev_ccline = ccp; ccline.cmdbuff = NULL; ccline.cmdprompt = NULL; ccline.xpc = NULL; @@ -2984,8 +2978,7 @@ static void save_cmdline(struct cmdline_info *ccp) */ static void restore_cmdline(struct cmdline_info *ccp) { - ccline = prev_ccline; - prev_ccline = *ccp; + ccline = *ccp; } /* @@ -5312,13 +5305,15 @@ int get_history_idx(int histype) */ static struct cmdline_info *get_ccline_ptr(void) { - if ((State & CMDLINE) == 0) + if ((State & CMDLINE) == 0) { return NULL; - if (ccline.cmdbuff != NULL) + } else if (ccline.cmdbuff != NULL) { return &ccline; - if (prev_ccline_used && prev_ccline.cmdbuff != NULL) - return &prev_ccline; - return NULL; + } else if (ccline.prev_ccline && ccline.prev_ccline->cmdbuff != NULL) { + return ccline.prev_ccline; + } else { + return NULL; + } } /* -- cgit From bed0a3a8428027af32602ccb169e81767c55e257 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 20 Aug 2017 17:47:42 +0200 Subject: ext_cmdline: implement redraw! --- src/nvim/ex_getln.c | 166 +++++++++++++++++++++++++++++++--------------------- src/nvim/screen.c | 5 +- 2 files changed, 102 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2ac9ecdc2b..933aea7b93 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -67,6 +67,30 @@ #include "nvim/api/private/helpers.h" #include "nvim/highlight_defs.h" +/// Command-line colors: one chunk +/// +/// Defines a region which has the same highlighting. +typedef struct { + int start; ///< Colored chunk start. + int end; ///< Colored chunk end (exclusive, > start). + int attr; ///< Highlight attr. +} CmdlineColorChunk; + +/// Command-line colors +/// +/// Holds data about all colors. +typedef kvec_t(CmdlineColorChunk) CmdlineColors; + +/// Command-line coloring +/// +/// Holds both what are the colors and what have been colored. Latter is used to +/// suppress unnecessary calls to coloring callbacks. +typedef struct { + unsigned prompt_id; ///< ID of the prompt which was colored last. + char *cmdbuff; ///< What exactly was colored last time or NULL. + CmdlineColors colors; ///< Last colors. +} ColoredCmdline; + /* * Variables shared between getcmdline(), redrawcmdline() and others. * These need to be saved when using CTRL-R |, that's why they are in a @@ -91,8 +115,11 @@ struct cmdline_info { int input_fn; // when TRUE Invoked for input() function unsigned prompt_id; ///< Prompt number, used to disable coloring on errors. Callback highlight_callback; ///< Callback used for coloring user input. + ColoredCmdline last_colors; ///< Last cmdline colors int level; // current cmdline level struct cmdline_info *prev_ccline; ///< pointer to saved cmdline state + char special_char; ///< last putcmdline char (used for redraws) + bool special_shift; ///< shift of last putcmdline char }; /// Last value of prompt_id, incremented when doing new prompt static unsigned last_prompt_id = 0; @@ -145,36 +172,6 @@ typedef struct command_line_state { struct cmdline_info save_ccline; } CommandLineState; -/// Command-line colors: one chunk -/// -/// Defines a region which has the same highlighting. -typedef struct { - int start; ///< Colored chunk start. - int end; ///< Colored chunk end (exclusive, > start). - int attr; ///< Highlight attr. -} CmdlineColorChunk; - -/// Command-line colors -/// -/// Holds data about all colors. -typedef kvec_t(CmdlineColorChunk) CmdlineColors; - -/// Command-line coloring -/// -/// Holds both what are the colors and what have been colored. Latter is used to -/// suppress unnecessary calls to coloring callbacks. -typedef struct { - unsigned prompt_id; ///< ID of the prompt which was colored last. - char *cmdbuff; ///< What exactly was colored last time or NULL. - CmdlineColors colors; ///< Last colors. -} ColoredCmdline; - -/// Last command-line colors. -ColoredCmdline last_ccline_colors = { - .cmdbuff = NULL, - .colors = KV_INITIAL_VALUE -}; - typedef struct cmdline_info CmdlineInfo; /* The current cmdline_info. It is initialized in getcmdline() and after that @@ -242,7 +239,6 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) cmd_hkmap = 0; } - // TODO(bfredl): can these be combined? ccline.prompt_id = last_prompt_id++; ccline.level++; ccline.overstrike = false; // always start in insert mode @@ -264,6 +260,9 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) ccline.cmdlen = ccline.cmdpos = 0; ccline.cmdbuff[0] = NUL; + ccline.last_colors = (ColoredCmdline){ .cmdbuff = NULL, + .colors = KV_INITIAL_VALUE }; + // autoindent for :insert and :append if (s->firstc <= 0) { memset(ccline.cmdbuff, ' ', s->indent); @@ -414,6 +413,8 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) setmouse(); ui_cursor_shape(); // may show different cursor shape xfree(s->save_p_icm); + xfree(ccline.last_colors.cmdbuff); + kv_destroy(ccline.last_colors.colors); { char_u *p = ccline.cmdbuff; @@ -2364,8 +2365,7 @@ enum { MAX_CB_ERRORS = 1 }; /// Should use built-in command parser or user-specified one. Currently only the /// latter is supported. /// -/// @param[in] colored_ccline Command-line to color. -/// @param[out] ret_ccline_colors What should be colored. Also holds a cache: +/// @param[in,out] colored_ccline Command-line to color. Also holds a cache: /// if ->prompt_id and ->cmdbuff values happen /// to be equal to those from colored_cmdline it /// will just do nothing, assuming that ->colors @@ -2375,8 +2375,7 @@ enum { MAX_CB_ERRORS = 1 }; /// /// @return true if draw_cmdline may proceed, false if it does not need anything /// to do. -static bool color_cmdline(const CmdlineInfo *const colored_ccline, - ColoredCmdline *const ret_ccline_colors) +static bool color_cmdline(CmdlineInfo *colored_ccline) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { bool printed_errmsg = false; @@ -2389,19 +2388,21 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline, } while (0) bool ret = true; + ColoredCmdline *ccline_colors = &colored_ccline->last_colors; + // Check whether result of the previous call is still valid. - if (ret_ccline_colors->prompt_id == colored_ccline->prompt_id - && ret_ccline_colors->cmdbuff != NULL - && STRCMP(ret_ccline_colors->cmdbuff, colored_ccline->cmdbuff) == 0) { + if (ccline_colors->prompt_id == colored_ccline->prompt_id + && ccline_colors->cmdbuff != NULL + && STRCMP(ccline_colors->cmdbuff, colored_ccline->cmdbuff) == 0) { return ret; } - kv_size(ret_ccline_colors->colors) = 0; + kv_size(ccline_colors->colors) = 0; if (colored_ccline->cmdbuff == NULL || *colored_ccline->cmdbuff == NUL) { // Nothing to do, exiting. - xfree(ret_ccline_colors->cmdbuff); - ret_ccline_colors->cmdbuff = NULL; + xfree(ccline_colors->cmdbuff); + ccline_colors->cmdbuff = NULL; return ret; } @@ -2523,7 +2524,7 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline, goto color_cmdline_error; } if (start != prev_end) { - kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { + kv_push(ccline_colors->colors, ((CmdlineColorChunk) { .start = prev_end, .end = start, .attr = 0, @@ -2552,14 +2553,14 @@ static bool color_cmdline(const CmdlineInfo *const colored_ccline, } const int id = syn_name2id((char_u *)group); const int attr = (id == 0 ? 0 : syn_id2attr(id)); - kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { + kv_push(ccline_colors->colors, ((CmdlineColorChunk) { .start = start, .end = end, .attr = attr, })); } if (prev_end < colored_ccline->cmdlen) { - kv_push(ret_ccline_colors->colors, ((CmdlineColorChunk) { + kv_push(ccline_colors->colors, ((CmdlineColorChunk) { .start = prev_end, .end = colored_ccline->cmdlen, .attr = 0, @@ -2571,14 +2572,14 @@ color_cmdline_end: if (can_free_cb) { callback_free(&color_cb); } - xfree(ret_ccline_colors->cmdbuff); + xfree(ccline_colors->cmdbuff); // Note: errors “output” is cached just as well as regular results. - ret_ccline_colors->prompt_id = colored_ccline->prompt_id; + ccline_colors->prompt_id = colored_ccline->prompt_id; if (arg_allocated) { - ret_ccline_colors->cmdbuff = (char *)arg.vval.v_string; + ccline_colors->cmdbuff = (char *)arg.vval.v_string; } else { - ret_ccline_colors->cmdbuff = xmemdupz((const char *)colored_ccline->cmdbuff, - (size_t)colored_ccline->cmdlen); + ccline_colors->cmdbuff = xmemdupz((const char *)colored_ccline->cmdbuff, + (size_t)colored_ccline->cmdlen); } tv_clear(&tv); return ret; @@ -2591,7 +2592,7 @@ color_cmdline_error: (void)printed_errmsg; prev_prompt_errors++; - kv_size(ret_ccline_colors->colors) = 0; + kv_size(ccline_colors->colors) = 0; redrawcmdline(); ret = false; goto color_cmdline_end; @@ -2604,12 +2605,13 @@ color_cmdline_error: */ static void draw_cmdline(int start, int len) { - if (!color_cmdline(&ccline, &last_ccline_colors)) { + if (!color_cmdline(&ccline)) { return; } if (ui_is_external(kUICmdline)) { - ui_ext_cmdline_show(); + ccline.special_char = NUL; + ui_ext_cmdline_show(&ccline); return; } @@ -2711,9 +2713,9 @@ static void draw_cmdline(int start, int len) msg_outtrans_len(arshape_buf, newlen); } else { draw_cmdline_no_arabicshape: - if (kv_size(last_ccline_colors.colors)) { - for (size_t i = 0; i < kv_size(last_ccline_colors.colors); i++) { - CmdlineColorChunk chunk = kv_A(last_ccline_colors.colors, i); + if (kv_size(ccline.last_colors.colors)) { + for (size_t i = 0; i < kv_size(ccline.last_colors.colors); i++) { + CmdlineColorChunk chunk = kv_A(ccline.last_colors.colors, i); if (chunk.end <= start) { continue; } @@ -2728,12 +2730,12 @@ draw_cmdline_no_arabicshape: } } -void ui_ext_cmdline_show(void) +static void ui_ext_cmdline_show(CmdlineInfo *line) { Array content = ARRAY_DICT_INIT; - if (kv_size(last_ccline_colors.colors)) { - for (size_t i = 0; i < kv_size(last_ccline_colors.colors); i++) { - CmdlineColorChunk chunk = kv_A(last_ccline_colors.colors, i); + if (kv_size(line->last_colors.colors)) { + for (size_t i = 0; i < kv_size(line->last_colors.colors); i++) { + CmdlineColorChunk chunk = kv_A(line->last_colors.colors, i); Array item = ARRAY_DICT_INIT; if (chunk.attr) { @@ -2745,21 +2747,26 @@ void ui_ext_cmdline_show(void) } else { ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); } - ADD(item, STRING_OBJ(cbuf_to_string((char *)ccline.cmdbuff + chunk.start, + ADD(item, STRING_OBJ(cbuf_to_string((char *)line->cmdbuff + chunk.start, chunk.end-chunk.start))); ADD(content, ARRAY_OBJ(item)); } } else { Array item = ARRAY_DICT_INIT; ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); - ADD(item, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff)))); + ADD(item, STRING_OBJ(cstr_to_string((char *)(line->cmdbuff)))); ADD(content, ARRAY_OBJ(item)); } - ui_call_cmdline_show(content, ccline.cmdpos, - cchar_to_string((char)ccline.cmdfirstc), - cstr_to_string((char *)(ccline.cmdprompt)), - ccline.cmdindent, - ccline.level); + ui_call_cmdline_show(content, line->cmdpos, + cchar_to_string((char)line->cmdfirstc), + cstr_to_string((char *)(line->cmdprompt)), + line->cmdindent, + line->level); + if (line->special_char) { + ui_call_cmdline_special_char(cchar_to_string((char)(line->special_char)), + line->special_shift, + line->level); + } } void ui_ext_cmdline_block_append(int indent, const char *line) @@ -2787,6 +2794,28 @@ void ui_ext_cmdline_block_leave(void) ui_call_cmdline_block_hide(); } +/// Extra redrawing needed for redraw! and on ui_attach +/// assumes "redrawcmdline()" will already be invoked +void cmdline_screen_cleared(void) +{ + if (!ui_is_external(kUICmdline)) { + return; + } + + if (cmdline_block.size) { + ui_call_cmdline_block_show(copy_array(cmdline_block)); + } + + int prev_level = ccline.level-1; + CmdlineInfo *prev_ccline = ccline.prev_ccline; + while (prev_level > 0 && prev_ccline) { + if (prev_ccline->level == prev_level) { + ui_ext_cmdline_show(prev_ccline); + prev_level--; + } + prev_ccline = prev_ccline->prev_ccline; + } +} /* * Put a character on the command line. Shifts the following text to the @@ -2806,6 +2835,8 @@ void putcmdline(int c, int shift) } msg_no_more = false; } else { + ccline.special_char = c; + ccline.special_shift = shift; ui_call_cmdline_special_char(cchar_to_string((char)(c)), shift, ccline.level); } @@ -2971,6 +3002,7 @@ static void save_cmdline(struct cmdline_info *ccp) ccline.cmdbuff = NULL; ccline.cmdprompt = NULL; ccline.xpc = NULL; + ccline.special_char = NUL; } /* @@ -3147,7 +3179,7 @@ static void redrawcmdprompt(void) if (cmd_silent) return; if (ui_is_external(kUICmdline)) { - ui_ext_cmdline_show(); + ui_ext_cmdline_show(&ccline); return; } if (ccline.cmdfirstc != NUL) { diff --git a/src/nvim/screen.c b/src/nvim/screen.c index f5730cf70a..0f47103a84 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -345,8 +345,9 @@ void update_screen(int type) if (need_highlight_changed) highlight_changed(); - if (type == CLEAR) { /* first clear screen */ - screenclear(); /* will reset clear_cmdline */ + if (type == CLEAR) { // first clear screen + screenclear(); // will reset clear_cmdline + cmdline_screen_cleared(); // clear external cmdline state type = NOT_VALID; } -- cgit From 91d8e26bc7471378b8005b8843182dc1af90d81a Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 27 Aug 2017 09:57:30 +0200 Subject: ext_cmdline: interact with cmdline window --- src/nvim/ex_getln.c | 10 +++++++++- src/nvim/globals.h | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 933aea7b93..bcc8d598db 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2810,7 +2810,10 @@ void cmdline_screen_cleared(void) CmdlineInfo *prev_ccline = ccline.prev_ccline; while (prev_level > 0 && prev_ccline) { if (prev_ccline->level == prev_level) { - ui_ext_cmdline_show(prev_ccline); + // don't redraw a cmdline already shown in the cmdline window + if (prev_level != cmdwin_level) { + ui_ext_cmdline_show(prev_ccline); + } prev_level--; } prev_ccline = prev_ccline->prev_ccline; @@ -5781,6 +5784,7 @@ static int ex_window(void) return K_IGNORE; } cmdwin_type = get_cmdline_type(); + cmdwin_level = ccline.level; // Create empty command-line buffer. buf_open_scratch(0, "[Command Line]"); @@ -5833,6 +5837,9 @@ static int ex_window(void) curwin->w_cursor.col = ccline.cmdpos; changed_line_abv_curs(); invalidate_botline(); + if (ui_is_external(kUICmdline)) { + ui_call_cmdline_hide(ccline.level); + } redraw_later(SOME_VALID); // Save the command line info, can be used recursively. @@ -5875,6 +5882,7 @@ static int ex_window(void) // Restore the command line info. restore_cmdline(&save_ccline); cmdwin_type = 0; + cmdwin_level = 0; exmode_active = save_exmode; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 300e506854..f24286360a 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -981,9 +981,10 @@ EXTERN int fill_diff INIT(= '-'); EXTERN int km_stopsel INIT(= FALSE); EXTERN int km_startsel INIT(= FALSE); -EXTERN int cedit_key INIT(= -1); /* key value of 'cedit' option */ -EXTERN int cmdwin_type INIT(= 0); /* type of cmdline window or 0 */ -EXTERN int cmdwin_result INIT(= 0); /* result of cmdline window or 0 */ +EXTERN int cedit_key INIT(= -1); ///< key value of 'cedit' option +EXTERN int cmdwin_type INIT(= 0); ///< type of cmdline window or 0 +EXTERN int cmdwin_result INIT(= 0); ///< result of cmdline window or 0 +EXTERN int cmdwin_level INIT(= 0); ///< cmdline level of cmdline window or 0 EXTERN char_u no_lines_msg[] INIT(= N_("--No lines in buffer--")); -- cgit From 445f25998c66ee7e4dc5bbfeed4108818e439b92 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 30 Aug 2017 08:51:39 +0200 Subject: ext_cmdline: fix inputsecret() --- src/nvim/ex_getln.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index bcc8d598db..e79476ab53 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2733,7 +2733,18 @@ draw_cmdline_no_arabicshape: static void ui_ext_cmdline_show(CmdlineInfo *line) { Array content = ARRAY_DICT_INIT; - if (kv_size(line->last_colors.colors)) { + if (cmdline_star) { + size_t len = 0; + for (char_u *p = ccline.cmdbuff; *p; mb_ptr_adv(p)) { + len++; + } + char *buf = xmallocz(len); + memset(buf, '*', len); + Array item = ARRAY_DICT_INIT; + ADD(item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); + ADD(item, STRING_OBJ(((String) { .data = buf, .size = len }))); + ADD(content, ARRAY_OBJ(item)); + } else if (kv_size(line->last_colors.colors)) { for (size_t i = 0; i < kv_size(line->last_colors.colors); i++) { CmdlineColorChunk chunk = kv_A(line->last_colors.colors, i); Array item = ARRAY_DICT_INIT; -- cgit From 8526902790680b9eea5462c19bd7d45caa40f16d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 28 Oct 2017 23:49:41 +0200 Subject: doc/ui.txt --- src/nvim/globals.h | 2 +- src/nvim/ui.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/globals.h b/src/nvim/globals.h index f24286360a..0f3e132bc0 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -984,7 +984,7 @@ EXTERN int km_startsel INIT(= FALSE); EXTERN int cedit_key INIT(= -1); ///< key value of 'cedit' option EXTERN int cmdwin_type INIT(= 0); ///< type of cmdline window or 0 EXTERN int cmdwin_result INIT(= 0); ///< result of cmdline window or 0 -EXTERN int cmdwin_level INIT(= 0); ///< cmdline level of cmdline window or 0 +EXTERN int cmdwin_level INIT(= 0); ///< cmdline recursion level EXTERN char_u no_lines_msg[] INIT(= N_("--No lines in buffer--")); diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 6b09f6e6db..afe7a51d43 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -30,7 +30,6 @@ #include "nvim/os/input.h" #include "nvim/os/signal.h" #include "nvim/popupmnu.h" -#include "nvim/ex_getln.h" #include "nvim/screen.h" #include "nvim/syntax.h" #include "nvim/window.h" -- cgit