|
@@ -29,13 +29,13 @@ void term_init(struct term *t, int num_rows, int num_cols, int pango)
|
|
|
t->params[0] = 0;
|
|
|
t->params[1] = 0;
|
|
|
t->pango = pango;
|
|
|
- t->sgra.fg = 7;
|
|
|
- t->sgra.bg = 0;
|
|
|
- t->sgra.bold = 0;
|
|
|
+ t->sgra.normal = 1;
|
|
|
for (int i = 0; i < t->num_rows; i++) {
|
|
|
t->rows[i].cells = calloc(t->num_cols, sizeof(struct cell));
|
|
|
for (int j = 0; j < t->num_cols; j++) {
|
|
|
- t->rows[i].cells[j].c = ' ';
|
|
|
+ struct cell *cur_cell = &t->rows[i].cells[j];
|
|
|
+ cur_cell->c = ' ';
|
|
|
+ cur_cell->sgra.normal = 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -215,17 +215,16 @@ static void term_csi_erase_in_line(struct term *t) {
|
|
|
static void term_csi_sgr(struct term *t) {
|
|
|
for (int i = 0; i < t->param_idx + 1; i++) {
|
|
|
int p = t->params[i];
|
|
|
- switch (p) {
|
|
|
- case 0:
|
|
|
- t->sgra.fg = 7;
|
|
|
- t->sgra.bg = 0;
|
|
|
- t->sgra.bold = 0;
|
|
|
- break;
|
|
|
-
|
|
|
- case 1: t->sgra.bold = 1; break;
|
|
|
+ if (0 == p) {
|
|
|
+ t->sgra.normal = 1;
|
|
|
+ } else {
|
|
|
+ t->sgra.normal = 0;
|
|
|
+ switch (p) {
|
|
|
+ case 1: t->sgra.bold = 1; break;
|
|
|
|
|
|
- case 30 ... 37: t->sgra.fg = p - 30; break;
|
|
|
- case 40 ... 47: t->sgra.bg = p - 40; break;
|
|
|
+ case 30 ... 37: t->sgra.fg = p - 30; break;
|
|
|
+ case 40 ... 47: t->sgra.bg = p - 40; break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -373,7 +372,7 @@ char *term_to_string(struct term *t)
|
|
|
for (int i = 0; i < t->num_rows; i++) {
|
|
|
for (int j = 0; j < t->num_cols; j++) {
|
|
|
struct cell cur_cell = t->rows[i].cells[j];
|
|
|
- if (t->pango) {
|
|
|
+ if (t->pango && 0 == cur_cell.sgra.normal) {
|
|
|
// TODO: use snprintf...
|
|
|
s += sprintf(s, "<span weight='%s' fgcolor='#%s' bgcolor='#%s'>%c</span>",
|
|
|
cur_cell.sgra.bold ? "bold" : "normal",
|