From d9562b264f00d015c0bcd75bd8fa3e4cece9eddb Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Fri, 10 Mar 2017 14:10:40 +0330 Subject: [PATCH] vi: for ex messages use "---" filetype --- led.c | 22 +++++++++++++++++++--- vi.c | 2 +- vi.h | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/led.c b/led.c index bfc3fc0..9d673dd 100644 --- a/led.c +++ b/led.c @@ -1,3 +1,4 @@ +/* line editing and drawing */ #include #include #include @@ -33,6 +34,7 @@ static int led_offdir(char **chrs, int *pos, int i) return 0; } +/* highlight text in reverse direction */ static void led_markrev(int n, char **chrs, int *pos, int *att) { int i = 0, j; @@ -51,7 +53,8 @@ static void led_markrev(int n, char **chrs, int *pos, int *att) } } -static char *led_render(char *s0, int cbeg, int cend) +/* render and highlight a line */ +static char *led_render(char *s0, int cbeg, int cend, char *syn) { int n; int *pos; /* pos[i]: the screen position of the i-th character */ @@ -75,7 +78,7 @@ static char *led_render(char *s0, int cbeg, int cend) for (j = 0; j < curwid; j++) off[led_posctx(ctx, pos[i] + j, cbeg, cend)] = i; } - att = syn_highlight(ex_filetype(), s0); + att = syn_highlight(syn, s0); led_markrev(n, chrs, pos, att); out = sbuf_make(); i = cbeg; @@ -107,9 +110,20 @@ static char *led_render(char *s0, int cbeg, int cend) return sbuf_done(out); } +/* print a line on the screen */ void led_print(char *s, int row) { - char *r = led_render(s, xleft, xleft + xcols); + char *r = led_render(s, xleft, xleft + xcols, ex_filetype()); + term_pos(row, 0); + term_kill(); + term_str(r); + free(r); +} + +/* print a line on the screen; for ex messages */ +void led_printmsg(char *s, int row) +{ + char *r = led_render(s, xleft, xleft + xcols, "---"); term_pos(row, 0); term_kill(); term_str(r); @@ -199,6 +213,7 @@ static char *led_readchar(int c, char *kmap) return kmap_map(kmap, c); } +/* read a character from the terminal */ char *led_read(char **kmap) { int c = term_read(); @@ -218,6 +233,7 @@ char *led_read(char **kmap) return NULL; } +/* read a line from the terminal */ static char *led_line(char *pref, char *post, char *ai, int ai_max, int *key, char **kmap) { struct sbuf *sb; diff --git a/vi.c b/vi.c index 28a837b..a910c41 100644 --- a/vi.c +++ b/vi.c @@ -45,7 +45,7 @@ static void vi_drawmsg(void) { int oleft = xleft; xleft = 0; - led_print(vi_msg, xrows); + led_printmsg(vi_msg, xrows); vi_msg[0] = '\0'; xleft = oleft; } diff --git a/vi.h b/vi.h index e7b62f2..0576db6 100644 --- a/vi.h +++ b/vi.h @@ -133,6 +133,7 @@ char *led_prompt(char *pref, char *post, char **kmap); char *led_input(char *pref, char *post, char **kmap); char *led_read(char **kmap); void led_print(char *msg, int row); +void led_printmsg(char *s, int row); int led_pos(char *s, int pos); /* ex commands */ -- 2.11.4.GIT