Highlight char

This commit is contained in:
Night Kaly 2024-11-12 10:49:24 +00:00
parent f520b71657
commit a00669be81
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM
2 changed files with 28 additions and 0 deletions

View file

@ -24,6 +24,8 @@
#define YELLOW_BG "\033[38;2;249;226;175m" #define YELLOW_BG "\033[38;2;249;226;175m"
#define RED_FG "\033[48;2;243;139;168m" #define RED_FG "\033[48;2;243;139;168m"
#define RED_BG "\033[38;2;243;139;168m" #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"
/* ERROR is red with bold and italic */ /* ERROR is red with bold and italic */
#define ERROR "\033[38;2;243;139;168m\033[1m\033[3m" #define ERROR "\033[38;2;243;139;168m\033[1m\033[3m"
@ -58,6 +60,7 @@ enum highlight {
KW_FN, KW_FN,
KW_BRACKET, KW_BRACKET,
STRING, STRING,
CHAR,
NUMBER, NUMBER,
MATCH, MATCH,
RESET RESET

25
vip.c
View file

@ -595,6 +595,10 @@ void draw_rows(void)
bprintf(GREEN_BG); bprintf(GREEN_BG);
break; break;
case CHAR:
bprintf(TEAL_BG);
break;
case SYMBOL: case SYMBOL:
bprintf(SKY_BG); bprintf(SKY_BG);
break; break;
@ -772,6 +776,7 @@ void update_highlight(row_t *row)
int prev_sep = 1; int prev_sep = 1;
int in_string = 0; int in_string = 0;
int in_char = 0;
int in_include = 0; int in_include = 0;
int in_comment = row->idx > 0 && cur_editor->row[row->idx - 1].opened_comment; int in_comment = row->idx > 0 && cur_editor->row[row->idx - 1].opened_comment;
@ -828,6 +833,26 @@ void update_highlight(row_t *row)
} }
} }
if (in_char) {
row->hl[i] = CHAR;
if (c == '\\' && i + 1 < row->render_size) {
row->hl[i + 1] = CHAR;
i += 2;
continue;
}
if (c == in_char) in_char = 0;
i++;
prev_sep = 1;
continue;
} else {
if (c == '\'') {
in_char = c;
row->hl[i] = CHAR;
i++;
continue;
}
}
if (in_include) { if (in_include) {
row->hl[i] = STRING; row->hl[i] = STRING;
if (c == '>') in_include = 0; if (c == '>') in_include = 0;