Highlight ; and escape sequence and .

This commit is contained in:
Night Kaly 2024-11-12 11:09:00 +00:00
parent a00669be81
commit 233bbcea37
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM
2 changed files with 42 additions and 4 deletions

View file

@ -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 },
},
};

36
vip.c
View file

@ -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) {
@ -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++) {