tAdd user configuration for colors, implement digit coloring - ve - a minimal text editor (work in progress) (HTM) git clone git://src.adamsgaard.dk/ve (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 97418d42195f0f408fd2dfd02531fb50120482fc (DIR) parent 46d33db19cc6321705a9c52f7929a2a689d88ebc (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Thu, 8 Aug 2019 09:20:35 +0200 Add user configuration for colors, implement digit coloring Diffstat: M config.def.h | 11 +++++++++++ M ve.1 | 1 + M ve.c | 26 +++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) --- (DIR) diff --git a/config.def.h b/config.def.h t@@ -12,3 +12,13 @@ static int status_message_timeout = 3; */ /* static unsigned int cursorshape_normal = 2; */ /* static unsigned int cursorshape_insert = 6; */ + +/* + * color settings for syntax highglighting + */ +static const int colors[][3] = { + /* fg bg style */ + [ColorDigits] = { 1, 0, 0 }, + [ColorComments] = { 2, 0, 0 }, + [ColorKeywords] = { 3, 0, 0 }, +}; +\ No newline at end of file (DIR) diff --git a/ve.1 b/ve.1 t@@ -24,6 +24,7 @@ enter INSERT mode .SH SEE ALSO .BR vi(1), .BR vim(1) +.BR vis(1) .SH BUGS Please report found bugs at https://gitlab.com/admesg/ve/issues .SH AUTHOR (DIR) diff --git a/ve.c b/ve.c t@@ -15,7 +15,6 @@ #include <time.h> #include <unistd.h> -#include "config.h" /* macros */ t@@ -56,6 +55,12 @@ struct editor_config { int find_direction; }; +/* color scheme types */ +enum { ColorDigits, ColorComments, ColorKeywords }; +enum { FG, BG, STYLE }; + +/* configuration, allows nested code to access above variables */ +#include "config.h" /* function declarations */ t@@ -684,7 +689,9 @@ editor_scroll() void editor_draw_rows(struct abuf *ab) { - int y, len, file_row; + int y, j, len, file_row; + char *c; + char buf[16]; for (y = 0; y < E.screen_rows; ++y) { file_row = y + E.row_offset; if (file_row < E.num_rows) { t@@ -693,7 +700,20 @@ editor_draw_rows(struct abuf *ab) len = 0; if (len > E.screen_columns) len = E.screen_columns; - ab_append(ab, &E.row[file_row].rchars[E.column_offset], len); + /* ab_append(ab, &E.row[file_row].rchars[E.column_offset], len); */ + c = &E.row[file_row].rchars[E.column_offset]; + for (j = 0; j < len; ++j) { + if (isdigit(c[j])) { + snprintf(buf, sizeof(buf), + "\x1b[3%dm", colors[ColorDigits][FG]); + ab_append(ab, buf, strlen(buf)); + /* ab_append(ab, "\x1b[31m", 5); */ + ab_append(ab, &c[j], 1); + ab_append(ab, "\x1b[39m", 5); + } else { + ab_append(ab, &c[j], 1); + } + } } else { ab_append(ab, "~", 1); }