vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 4e66ee13ad99c29b47414195e1a983dda72a4f70 parent bc5ab38504921842811180bb0ce054e69a2e520b Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 28 Apr 2017 20:14:18 +0200 ui: ignore whitespace when parsing style options Diffstat:
| M | ui-terminal.c | | | 16 | ++++++++++------ |
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/ui-terminal.c b/ui-terminal.c @@ -154,12 +154,16 @@ static bool ui_style_define(UiWin *w, int id, const char *style) { if (!style) return true; CellStyle cell_style = tui->styles[win->id * UI_STYLE_MAX + UI_STYLE_DEFAULT]; - char *style_copy = strdup(style), *option = style_copy, *next, *p; + char *style_copy = strdup(style), *option = style_copy; while (option) { - if ((next = strchr(option, ','))) + while (*option == ' ') + option++; + char *next = strchr(option, ','); + if (next) *next++ = '\0'; - if ((p = strchr(option, ':'))) - *p++ = '\0'; + char *value = strchr(option, ':'); + if (value) + for (*value++ = '\0'; *value == ' '; value++); if (!strcasecmp(option, "reverse")) { cell_style.attr |= CELL_ATTR_REVERSE; } else if (!strcasecmp(option, "bold")) { @@ -179,9 +183,9 @@ static bool ui_style_define(UiWin *w, int id, const char *style) { } else if (!strcasecmp(option, "notblink")) { cell_style.attr &= ~CELL_ATTR_BLINK; } else if (!strcasecmp(option, "fore")) { - color_fromstring(win->ui, &cell_style.fg, p); + color_fromstring(win->ui, &cell_style.fg, value); } else if (!strcasecmp(option, "back")) { - color_fromstring(win->ui, &cell_style.bg, p); + color_fromstring(win->ui, &cell_style.bg, value); } option = next; }