parenthesis colouring in repl

This commit is contained in:
VaclavT 2021-04-14 07:57:58 +02:00
parent a50a3bceb3
commit 0319bf6030
1 changed files with 15 additions and 1 deletions

View File

@ -601,7 +601,21 @@ static void refreshMultiLine(struct linenoiseState *l) {
unsigned int i;
for (i = 0; i < l->len; i++) abAppend(&ab,"*",1);
} else {
abAppend(&ab,l->buf,l->len);
int colors[] = {31, 32, 33, 35, 36};
int nesting = 0;
for (int i = 0; i < l->len; i++) {
if (l->buf[i]=='(') {
snprintf(seq,64,"\033[%d;1m(\033[0m",colors[nesting % sizeof(colors)]);
abAppend(&ab,seq,strlen(seq));
nesting++;
} else if (l->buf[i]==')') {
nesting--;
snprintf(seq,64,"\033[%d;1m)\033[0m",colors[nesting % sizeof(colors)]);
abAppend(&ab,seq,strlen(seq));
} else {
abAppend(&ab,l->buf+i,1);
}
}
}
/* Show hits if any. */