From 233bbcea37b23925fc48ded7e05891e4169b72c2 Mon Sep 17 00:00:00 2001 From: night0721 Date: Tue, 12 Nov 2024 11:09:00 +0000 Subject: [PATCH] Highlight ; and escape sequence and . --- config.h | 6 +++++- vip.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/config.h b/config.h index ac1e25a..003bd91 100644 --- a/config.h +++ b/config.h @@ -26,6 +26,8 @@ #define RED_BG "\033[38;2;243;139;168m" #define TEAL_FG "\033[48;2;148;226;213m" #define TEAL_BG "\033[38;2;148;226;213m" +#define PINK_FG "\033[48;2;245;194;231m" +#define PINK_BG "\033[38;2;245;194;231m" /* ERROR is red with bold and italic */ #define ERROR "\033[38;2;243;139;168m\033[1m\033[3m" @@ -54,6 +56,7 @@ enum highlight { DEFAULT = 0, SYMBOL, COMMENT, + TERMINATOR, MLCOMMENT, KW, KW_TYPE, @@ -61,6 +64,7 @@ enum highlight { KW_BRACKET, STRING, CHAR, + ESCAPE, NUMBER, MATCH, RESET @@ -108,7 +112,7 @@ language_t langs[] = { "//", "/*", "*/", - { "switch", "if", "while", "for", "break", "continue", "return", "else", "struct", "union", "typedef", "static", "enum", "case", "sizeof", "#include", "#define", "#if", "#elseif", "#endif", "int|", "long|", "double|", "float|", "char|", "unsigned|", "void|", "size_t|", "uint8_t|", NULL }, + { "const", "switch", "if", "while", "for", "break", "continue", "return", "else", "struct", "union", "typedef", "static", "enum", "case", "sizeof", "#include", "#define", "#if", "#elseif", "#endif", "int|", "long|", "double|", "float|", "char|", "unsigned|", "void|", "size_t|", "uint8_t|", NULL }, { ".c", ".h", ".cpp", NULL }, }, }; diff --git a/vip.c b/vip.c index ca2311a..ff83e60 100644 --- a/vip.c +++ b/vip.c @@ -599,10 +599,18 @@ void draw_rows(void) bprintf(TEAL_BG); break; + case ESCAPE: + bprintf(PINK_BG); + break; + case SYMBOL: bprintf(SKY_BG); break; + case TERMINATOR: + bprintf(OVERLAY_2_BG); + break; + case COMMENT: case MLCOMMENT: bprintf("\033[3m"); @@ -754,7 +762,7 @@ int is_separator(int c) int is_symbol(int c) { - return strchr("+-/*=~%><:?&", c) != NULL; + return strchr("+-/*=~%><:?&|.", c) != NULL; } void update_highlight(row_t *row) @@ -778,6 +786,7 @@ void update_highlight(row_t *row) int in_string = 0; int in_char = 0; int in_include = 0; + int in_escape = 0; int in_comment = row->idx > 0 && cur_editor->row[row->idx - 1].opened_comment; int i = 0; @@ -813,6 +822,24 @@ void update_highlight(row_t *row) } } + if (in_escape) { + if (!(c > 47 && c < 58)) { + in_escape = 0; + } else { + row->hl[i] = ESCAPE; + i++; + prev_sep = 0; + continue; + } + } else { + if (c == '\\') { + in_escape = 1; + row->hl[i] = ESCAPE; + i++; + continue; + } + } + if (in_string) { row->hl[i] = STRING; if (c == '\\' && i + 1 < row->render_size) { @@ -867,13 +894,13 @@ void update_highlight(row_t *row) i++; continue; } - } + } if ((isdigit(c) && (prev_sep || prev_hl == NUMBER)) || (c == '.' && prev_hl == NUMBER) || (c >= 'A' && c <= 'Z') || (c == '_' && prev_hl == NUMBER) - ) { + ) { row->hl[i] = NUMBER; i++; prev_sep = 0; @@ -894,6 +921,13 @@ void update_highlight(row_t *row) continue; } + if (c == ';') { + row->hl[i] = TERMINATOR; + prev_sep = 1; + i++; + continue; + } + if (prev_sep) { int j; for (j = 0; keywords[j]; j++) {