aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDongdong Zhou <dzhou121@gmail.com>2017-02-23 05:33:14 +0000
committerBjörn Linse <bjorn.linse@gmail.com>2017-10-26 09:35:12 +0200
commit439c39a2cfb0712eb68ad76354b1fd7e92bb71fe (patch)
treec8418962db8b412fd293f6f25c583ad4a8688e54 /src
parentf0c2f82e90046487a8c12c10ca6c8da23470ef09 (diff)
downloadrneovim-439c39a2cfb0712eb68ad76354b1fd7e92bb71fe.tar.gz
rneovim-439c39a2cfb0712eb68ad76354b1fd7e92bb71fe.tar.bz2
rneovim-439c39a2cfb0712eb68ad76354b1fd7e92bb71fe.zip
ext_cmdline: allow external ui to draw cmdline
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_getln.c80
-rw-r--r--src/nvim/ui.c2
2 files changed, 73 insertions, 9 deletions
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;