From 9e391f5e3b2baaee0bf73e5273daf84be8a76ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 9 Oct 2015 10:31:25 +0200 Subject: ui: refactor syntax style definitions Styles can now be specified as strings which will make them easier to specify from outside the editor. The following style attributes can be given in a comma separated list: bold italics underlined fore:color back:color where color is either a hex value of the form #aabbcc or one of the predefined colors: black red green yellow blue magenta cyan white --- view.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'view.c') diff --git a/view.c b/view.c index b8b1dd6..df8aa93 100644 --- a/view.c +++ b/view.c @@ -167,8 +167,7 @@ static bool view_addch(View *view, Cell *cell) { cell->len = w == 0 ? 1 : 0; int t = w == 0 ? SYNTAX_SYMBOL_TAB : SYNTAX_SYMBOL_TAB_FILL; strncpy(cell->data, view->symbols[t]->symbol, sizeof(cell->data)-1); - if (view->symbols[t]->color) - cell->attr = view->symbols[t]->color->attr; + cell->attr = view->symbols[t]->style; view->line->cells[view->col] = *cell; view->line->len += cell->len; view->line->width += cell->width; @@ -187,8 +186,7 @@ static bool view_addch(View *view, Cell *cell) { } strncpy(cell->data, view->symbols[SYNTAX_SYMBOL_EOL]->symbol, sizeof(cell->data)-1); - if (view->symbols[SYNTAX_SYMBOL_EOL]->color) - cell->attr = view->symbols[SYNTAX_SYMBOL_EOL]->color->attr; + cell->attr = view->symbols[SYNTAX_SYMBOL_EOL]->style; view->line->cells[view->col] = *cell; view->line->len += cell->len; @@ -215,8 +213,7 @@ static bool view_addch(View *view, Cell *cell) { if (cell->data[0] == ' ') { strncpy(cell->data, view->symbols[SYNTAX_SYMBOL_SPACE]->symbol, sizeof(cell->data)-1); - if (view->symbols[SYNTAX_SYMBOL_SPACE]->color) - cell->attr = view->symbols[SYNTAX_SYMBOL_SPACE]->color->attr; + cell->attr = view->symbols[SYNTAX_SYMBOL_SPACE]->style; } @@ -405,7 +402,7 @@ void view_draw(View *view) { if (text + match[i][0].rm_so <= cur && cur < text + match[i][0].rm_eo) { /* within matched expression */ matched = &match[i][0]; - attrs = rule->color->attr; + attrs = rule->style; break; /* first match views */ } } @@ -466,8 +463,7 @@ void view_draw(View *view) { for (Line *l = view->lastline->next; l; l = l->next) { strncpy(l->cells[0].data, view->symbols[SYNTAX_SYMBOL_EOF]->symbol, sizeof(l->cells[0].data)); - if (view->symbols[SYNTAX_SYMBOL_EOF]->color) - l->cells[0].attr =view->symbols[SYNTAX_SYMBOL_EOF]->color->attr; + l->cells[0].attr = view->symbols[SYNTAX_SYMBOL_EOF]->style; for (int x = 1; x < view->width; x++) l->cells[x] = cell_blank; l->width = 1; @@ -844,6 +840,11 @@ void view_syntax_set(View *view, Syntax *syntax) { else view->symbols[i] = &symbols_none[i]; } + if (syntax) { + for (const char **style = syntax->styles; *style; style++) { + view->ui->syntax_style(view->ui, style - syntax->styles, *style); + } + } } Syntax *view_syntax_get(View *view) { -- cgit v1.2.3