aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h24
-rw-r--r--editor.c8
-rw-r--r--editor.h5
-rw-r--r--ui-curses.c19
-rw-r--r--ui-curses.h22
-rw-r--r--ui.h1
-rw-r--r--view.c10
-rw-r--r--view.h3
-rw-r--r--vis.c4
9 files changed, 60 insertions, 36 deletions
diff --git a/config.def.h b/config.def.h
index 916831e..3007b60 100644
--- a/config.def.h
+++ b/config.def.h
@@ -830,18 +830,18 @@ enum {
};
static Color colors[] = {
- [COLOR_NOHILIT] = { .fg = -1, .bg = -1, .attr = A_NORMAL },
- [COLOR_SYNTAX0] = { .fg = COLOR_RED, .bg = -1, .attr = A_BOLD },
- [COLOR_SYNTAX1] = { .fg = COLOR_GREEN, .bg = -1, .attr = A_BOLD },
- [COLOR_SYNTAX2] = { .fg = COLOR_GREEN, .bg = -1, .attr = A_NORMAL },
- [COLOR_SYNTAX3] = { .fg = COLOR_MAGENTA, .bg = -1, .attr = A_BOLD },
- [COLOR_SYNTAX4] = { .fg = COLOR_MAGENTA, .bg = -1, .attr = A_NORMAL },
- [COLOR_SYNTAX5] = { .fg = COLOR_BLUE, .bg = -1, .attr = A_BOLD },
- [COLOR_SYNTAX6] = { .fg = COLOR_RED, .bg = -1, .attr = A_NORMAL },
- [COLOR_SYNTAX7] = { .fg = COLOR_BLUE, .bg = -1, .attr = A_NORMAL },
- [COLOR_SYNTAX8] = { .fg = COLOR_CYAN, .bg = -1, .attr = A_NORMAL },
- [COLOR_SYNTAX9] = { .fg = COLOR_YELLOW, .bg = -1, .attr = A_NORMAL },
- { /* empty last element, array terminator */ }
+ [COLOR_NOHILIT] = { .fg = UI_COLOR_DEFAULT, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ [COLOR_SYNTAX0] = { .fg = UI_COLOR_RED, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_BOLD },
+ [COLOR_SYNTAX1] = { .fg = UI_COLOR_GREEN, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_BOLD },
+ [COLOR_SYNTAX2] = { .fg = UI_COLOR_GREEN, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ [COLOR_SYNTAX3] = { .fg = UI_COLOR_MAGENTA, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_BOLD },
+ [COLOR_SYNTAX4] = { .fg = UI_COLOR_MAGENTA, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ [COLOR_SYNTAX5] = { .fg = UI_COLOR_BLUE, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_BOLD },
+ [COLOR_SYNTAX6] = { .fg = UI_COLOR_RED, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ [COLOR_SYNTAX7] = { .fg = UI_COLOR_BLUE, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ [COLOR_SYNTAX8] = { .fg = UI_COLOR_CYAN, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ [COLOR_SYNTAX9] = { .fg = UI_COLOR_YELLOW, .bg = UI_COLOR_DEFAULT, .attr = UI_ATTR_NORMAL },
+ { /* empty last element, array terminator */ }
};
/* Syntax color definitions per file type. Each rule consists of a regular
diff --git a/editor.c b/editor.c
index 8628458..fac598c 100644
--- a/editor.c
+++ b/editor.c
@@ -178,16 +178,10 @@ void editor_tabwidth_set(Editor *ed, int tabwidth) {
ed->tabwidth = tabwidth;
}
-bool editor_syntax_load(Editor *ed, Syntax *syntaxes, Color *colors) {
+bool editor_syntax_load(Editor *ed, Syntax *syntaxes) {
bool success = true;
ed->syntaxes = syntaxes;
- for (Color *color = colors; color && color->fg; color++) {
- if (color->attr == 0)
- color->attr = A_NORMAL;
- color->attr |= COLOR_PAIR(ed->ui->color_get(color->fg, color->bg));
- }
-
for (Syntax *syn = syntaxes; syn && syn->name; syn++) {
if (regcomp(&syn->file_regex, syn->file, REG_EXTENDED|REG_NOSUB|REG_ICASE|REG_NEWLINE))
success = false;
diff --git a/editor.h b/editor.h
index 3e8e644..fb57469 100644
--- a/editor.h
+++ b/editor.h
@@ -1,7 +1,6 @@
#ifndef EDITOR_H
#define EDITOR_H
-#include <curses.h>
#include <signal.h>
#include <stddef.h>
#include <stdbool.h>
@@ -273,9 +272,9 @@ int editor_tabwidth_get(Editor*);
/* load a set of syntax highlighting definitions which will be associated
* to the underlying window based on the file type loaded.
*
- * both *syntaxes and *colors must point to a NULL terminated arrays.
+ * The parameter `syntaxes' has to point to a NULL terminated array.
*/
-bool editor_syntax_load(Editor*, Syntax *syntaxes, Color *colors);
+bool editor_syntax_load(Editor*, Syntax *syntaxes);
void editor_syntax_unload(Editor*);
/* creates a new window, and loads the given file. if filename is NULL
diff --git a/ui-curses.c b/ui-curses.c
index 2473521..283ee16 100644
--- a/ui-curses.c
+++ b/ui-curses.c
@@ -371,11 +371,17 @@ static void ui_window_draw_text(UiWin *w, const Line *line) {
/* add a single space in an otherwise empty line to make
* the selection cohorent */
if (l->width == 1 && l->cells[0].data[0] == '\n') {
- wattrset(win->win, l->cells[0].attr);
+ int attr = l->cells[0].attr;
+ if (l->cells[0].selected)
+ attr |= A_REVERSE;
+ wattrset(win->win, attr);
waddstr(win->win, " \n");
} else {
for (int x = 0; x < l->width; x++) {
- wattrset(win->win, l->cells[x].attr);
+ int attr = l->cells[x].attr;
+ if (l->cells[x].selected)
+ attr |= A_REVERSE;
+ wattrset(win->win, attr);
waddstr(win->win, l->cells[x].data);
}
if (l->width != win->width - win->sidebar_width)
@@ -589,7 +595,7 @@ static void ui_terminal_restore(Ui *ui) {
wclear(stdscr);
}
-Ui *ui_curses_new(void) {
+Ui *ui_curses_new(Color *colors) {
setlocale(LC_CTYPE, "");
if (!getenv("ESCDELAY"))
set_escdelay(50);
@@ -631,13 +637,18 @@ Ui *ui_curses_new(void) {
.arrange = arrange,
.info = info,
.info_hide = info_hide,
- .color_get = color_get,
.haskey = ui_haskey,
.getkey = ui_getkey,
.terminal_save = ui_terminal_save,
.terminal_restore = ui_terminal_restore,
};
+ for (Color *color = colors; color && color->fg; color++) {
+ if (color->attr == 0)
+ color->attr = A_NORMAL;
+ color->attr |= COLOR_PAIR(color_get(color->fg, color->bg));
+ }
+
struct sigaction sa;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
diff --git a/ui-curses.h b/ui-curses.h
index 0509f25..32cdf2f 100644
--- a/ui-curses.h
+++ b/ui-curses.h
@@ -3,6 +3,7 @@
#include <curses.h>
#include "ui.h"
+#include "syntax.h"
enum {
UI_KEY_DOWN = KEY_DOWN,
@@ -20,7 +21,26 @@ enum {
UI_KEY_SHIFT_RIGHT = KEY_SRIGHT,
};
-Ui *ui_curses_new(void);
+enum {
+ UI_COLOR_DEFAULT = -1,
+ UI_COLOR_BLACK = COLOR_BLACK,
+ UI_COLOR_RED = COLOR_RED,
+ UI_COLOR_GREEN = COLOR_GREEN,
+ UI_COLOR_YELLOW = COLOR_YELLOW,
+ UI_COLOR_BLUE = COLOR_BLUE,
+ UI_COLOR_MAGENTA = COLOR_MAGENTA,
+ UI_COLOR_CYAN = COLOR_CYAN,
+ UI_COLOR_WHITE = COLOR_WHITE,
+};
+
+enum {
+ UI_ATTR_NORMAL = A_NORMAL,
+ UI_ATTR_UNDERLINE = A_UNDERLINE,
+ UI_ATTR_REVERSE = A_REVERSE,
+ UI_ATTR_BOLD = A_BOLD,
+};
+
+Ui *ui_curses_new(Color *colors);
void ui_curses_free(Ui*);
#endif
diff --git a/ui.h b/ui.h
index 18c9e0f..1a65184 100644
--- a/ui.h
+++ b/ui.h
@@ -29,7 +29,6 @@ typedef struct {
struct Ui {
bool (*init)(Ui*, Editor*);
void (*free)(Ui*);
- short (*color_get)(short fg, short bg);
void (*resize)(Ui*);
UiWin* (*window_new)(Ui*, View*, File*);
void (*window_free)(UiWin*);
diff --git a/view.c b/view.c
index 78a54f4..eb858d9 100644
--- a/view.c
+++ b/view.c
@@ -167,7 +167,7 @@ static bool view_addch(View *view, Cell *cell) {
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 & A_REVERSE);
+ cell->attr = view->symbols[t]->color->attr;
view->line->cells[view->col] = *cell;
view->line->len += cell->len;
view->line->width += cell->width;
@@ -215,7 +215,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 & A_REVERSE);
+ cell->attr = view->symbols[SYNTAX_SYMBOL_SPACE]->color->attr;
}
@@ -304,7 +304,7 @@ static size_t view_cursor_update(View *view) {
view_draw(view); /* clear active highlighting */
cursor->pos = pos_match;
view_cursor_sync(view);
- cursor->line->cells[cursor->col].attr |= A_REVERSE;
+ cursor->line->cells[cursor->col].selected = true;
cursor->pos = pos;
view_cursor_sync(view);
view->ui->draw_text(view->ui, view->topline);
@@ -374,7 +374,7 @@ void view_draw(View *view) {
regmatch_t match[syntax ? LENGTH(syntax->rules) : 1][1], *matched = NULL;
memset(match, 0, sizeof match);
/* default and current curses attributes to use */
- int default_attrs = COLOR_PAIR(0) | A_NORMAL, attrs = default_attrs;
+ int default_attrs = 0, attrs = default_attrs;
/* start from known multibyte state */
mbstate_t mbstate = { 0 };
@@ -468,7 +468,7 @@ void view_draw(View *view) {
cell.attr = attrs;
if (sel.start <= pos && pos < sel.end)
- cell.attr |= A_REVERSE;
+ cell.selected = true;
if (!view_addch(view, &cell))
break;
diff --git a/view.h b/view.h
index 1d10110..0adec05 100644
--- a/view.h
+++ b/view.h
@@ -22,8 +22,9 @@ typedef struct {
occupied by the same character have a length of 0. */
char data[8]; /* utf8 encoded character displayed in this cell might not be the
the same as in the underlying text, for example tabs get expanded */
- bool istab;
unsigned int attr;
+ bool istab;
+ bool selected;
} Cell;
typedef struct Line Line;
diff --git a/vis.c b/vis.c
index 339bfb0..594a7a9 100644
--- a/vis.c
+++ b/vis.c
@@ -2453,12 +2453,12 @@ int main(int argc, char *argv[]) {
}
}
- if (!(vis = editor_new(ui_curses_new())))
+ if (!(vis = editor_new(ui_curses_new(colors))))
die("Could not allocate editor core\n");
vis->mode_prev = vis->mode = config->mode;
- if (!editor_syntax_load(vis, syntaxes, colors))
+ if (!editor_syntax_load(vis, syntaxes))
die("Could not load syntax highlighting definitions\n");
char *cmd = NULL;