mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
vt: cell now tracks attributes (bold, italic, underline etc)
This commit is contained in:
parent
2a4c08b941
commit
c5b60253a7
4 changed files with 67 additions and 63 deletions
84
csi.c
84
csi.c
|
|
@ -10,55 +10,55 @@ csi_sgr(struct terminal *term)
|
|||
for (size_t i = 0; i < term->vt.params.idx; i++) {
|
||||
switch (term->vt.params.v[i].value) {
|
||||
case 0:
|
||||
term->vt.bold = false;
|
||||
term->vt.attrs.bold = false;
|
||||
term->vt.dim = false;
|
||||
term->vt.italic = false;
|
||||
term->vt.underline = false;
|
||||
term->vt.strikethrough = false;
|
||||
term->vt.blink = false;
|
||||
term->vt.conceal = false;
|
||||
term->vt.reverse = false;
|
||||
term->vt.foreground = term->grid.foreground;
|
||||
term->vt.background = term->grid.background;
|
||||
term->vt.attrs.italic = false;
|
||||
term->vt.attrs.underline = false;
|
||||
term->vt.attrs.strikethrough = false;
|
||||
term->vt.attrs.blink = false;
|
||||
term->vt.attrs.conceal = false;
|
||||
term->vt.attrs.reverse = false;
|
||||
term->vt.attrs.foreground = term->grid.foreground;
|
||||
term->vt.attrs.background = term->grid.background;
|
||||
break;
|
||||
|
||||
case 1: term->vt.bold = true; break;
|
||||
case 1: term->vt.attrs.bold = true; break;
|
||||
case 2: term->vt.dim = true; break;
|
||||
case 3: term->vt.italic = true; break;
|
||||
case 4: term->vt.underline = true; break;
|
||||
case 5: term->vt.blink = true; break;
|
||||
case 6: term->vt.blink = true; break;
|
||||
case 7: term->vt.reverse = true; break;
|
||||
case 8: term->vt.conceal = true; break;
|
||||
case 9: term->vt.strikethrough = true; break;
|
||||
case 3: term->vt.attrs.italic = true; break;
|
||||
case 4: term->vt.attrs.underline = true; break;
|
||||
case 5: term->vt.attrs.blink = true; break;
|
||||
case 6: term->vt.attrs.blink = true; break;
|
||||
case 7: term->vt.attrs.reverse = true; break;
|
||||
case 8: term->vt.attrs.conceal = true; break;
|
||||
case 9: term->vt.attrs.strikethrough = true; break;
|
||||
|
||||
case 22: term->vt.bold = term->vt.dim = false; break;
|
||||
case 23: term->vt.italic = false; break;
|
||||
case 24: term->vt.underline = false; break;
|
||||
case 25: term->vt.blink = false; break;
|
||||
case 27: term->vt.reverse = false; break;
|
||||
case 28: term->vt.conceal = false; break;
|
||||
case 29: term->vt.strikethrough = false; break;
|
||||
case 22: term->vt.attrs.bold = term->vt.dim = false; break;
|
||||
case 23: term->vt.attrs.italic = false; break;
|
||||
case 24: term->vt.attrs.underline = false; break;
|
||||
case 25: term->vt.attrs.blink = false; break;
|
||||
case 27: term->vt.attrs.reverse = false; break;
|
||||
case 28: term->vt.attrs.conceal = false; break;
|
||||
case 29: term->vt.attrs.strikethrough = false; break;
|
||||
|
||||
case 30: term->vt.foreground = 0x000000ff; break;
|
||||
case 31: term->vt.foreground = 0xff0000ff; break;
|
||||
case 32: term->vt.foreground = 0x00ff00ff; break;
|
||||
case 33: term->vt.foreground = 0xf0f000ff; break;
|
||||
case 34: term->vt.foreground = 0x0000ffff; break;
|
||||
case 35: term->vt.foreground = 0xf000f0ff; break;
|
||||
case 36: term->vt.foreground = 0x00f0f0ff; break;
|
||||
case 37: term->vt.foreground = 0xffffffff; break;
|
||||
case 39: term->vt.foreground = term->grid.foreground; break;
|
||||
case 30: term->vt.attrs.foreground = 0x000000ff; break;
|
||||
case 31: term->vt.attrs.foreground = 0xff0000ff; break;
|
||||
case 32: term->vt.attrs.foreground = 0x00ff00ff; break;
|
||||
case 33: term->vt.attrs.foreground = 0xf0f000ff; break;
|
||||
case 34: term->vt.attrs.foreground = 0x0000ffff; break;
|
||||
case 35: term->vt.attrs.foreground = 0xf000f0ff; break;
|
||||
case 36: term->vt.attrs.foreground = 0x00f0f0ff; break;
|
||||
case 37: term->vt.attrs.foreground = 0xffffffff; break;
|
||||
case 39: term->vt.attrs.foreground = term->grid.foreground; break;
|
||||
|
||||
case 40: term->vt.background = 0x000000ff; break;
|
||||
case 41: term->vt.background = 0xff0000ff; break;
|
||||
case 42: term->vt.background = 0x00ff00ff; break;
|
||||
case 43: term->vt.background = 0xf0f000ff; break;
|
||||
case 44: term->vt.background = 0x0000ffff; break;
|
||||
case 45: term->vt.background = 0xf000f0ff; break;
|
||||
case 46: term->vt.background = 0x00f0f0ff; break;
|
||||
case 47: term->vt.background = 0xffffffff; break;
|
||||
case 49: term->vt.background = term->grid.background; break;
|
||||
case 40: term->vt.attrs.background = 0x000000ff; break;
|
||||
case 41: term->vt.attrs.background = 0xff0000ff; break;
|
||||
case 42: term->vt.attrs.background = 0x00ff00ff; break;
|
||||
case 43: term->vt.attrs.background = 0xf0f000ff; break;
|
||||
case 44: term->vt.attrs.background = 0x0000ffff; break;
|
||||
case 45: term->vt.attrs.background = 0xf000f0ff; break;
|
||||
case 46: term->vt.attrs.background = 0x00f0f0ff; break;
|
||||
case 47: term->vt.attrs.background = 0xffffffff; break;
|
||||
case 49: term->vt.attrs.background = term->grid.background; break;
|
||||
|
||||
default:
|
||||
LOG_ERR("unimplemented: CSI: SGR: %u", term->vt.params.v[i].value);
|
||||
|
|
|
|||
18
main.c
18
main.c
|
|
@ -109,13 +109,13 @@ grid_render(struct context *c)
|
|||
//LOG_DBG("cell %dx%d dirty: c=0x%02x (%c)",
|
||||
// row, col, cell->c[0], cell->c[0]);
|
||||
|
||||
br = (double)((cell->background >> 24) & 0xff) / 255.0;
|
||||
bg = (double)((cell->background >> 16) & 0xff) / 255.0;
|
||||
bb = (double)((cell->background >> 8) & 0xff) / 255.0;
|
||||
br = (double)((cell->attrs.background >> 24) & 0xff) / 255.0;
|
||||
bg = (double)((cell->attrs.background >> 16) & 0xff) / 255.0;
|
||||
bb = (double)((cell->attrs.background >> 8) & 0xff) / 255.0;
|
||||
|
||||
fr = (double)((cell->foreground >> 24) & 0xff) / 255.0;
|
||||
fg = (double)((cell->foreground >> 16) & 0xff) / 255.0;
|
||||
fb = (double)((cell->foreground >> 8) & 0xff) / 255.0;
|
||||
fr = (double)((cell->attrs.foreground >> 24) & 0xff) / 255.0;
|
||||
fg = (double)((cell->attrs.foreground >> 16) & 0xff) / 255.0;
|
||||
fb = (double)((cell->attrs.foreground >> 8) & 0xff) / 255.0;
|
||||
|
||||
if (has_cursor)
|
||||
cairo_set_source_rgba(buf->cairo, fr, fg, fb, 1.0);
|
||||
|
|
@ -196,8 +196,10 @@ resize(struct context *c, int width, int height)
|
|||
|
||||
size_t new_cells_len = c->term.grid.cols * c->term.grid.rows;
|
||||
for (size_t i = old_cells_len; i < new_cells_len; i++) {
|
||||
c->term.grid.cells[i] = (struct cell){.foreground = default_foreground,
|
||||
.background = default_background};
|
||||
c->term.grid.cells[i] = (struct cell){
|
||||
.attrs = {.foreground = default_foreground,
|
||||
.background = default_background},
|
||||
};
|
||||
}
|
||||
|
||||
LOG_DBG("resize: %dx%d, grid: cols=%d, rows=%d",
|
||||
|
|
|
|||
25
terminal.h
25
terminal.h
|
|
@ -4,11 +4,22 @@
|
|||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct cell {
|
||||
char c[5];
|
||||
struct attributes {
|
||||
bool bold;
|
||||
bool italic;
|
||||
bool underline;
|
||||
bool strikethrough;
|
||||
bool blink;
|
||||
bool conceal;
|
||||
bool reverse;
|
||||
uint32_t foreground;
|
||||
uint32_t background;
|
||||
};
|
||||
|
||||
struct cell {
|
||||
bool dirty;
|
||||
char c[5];
|
||||
struct attributes attrs;
|
||||
};
|
||||
|
||||
struct grid {
|
||||
|
|
@ -52,16 +63,8 @@ struct vt {
|
|||
size_t idx;
|
||||
size_t left;
|
||||
} utf8;
|
||||
bool bold;
|
||||
struct attributes attrs;
|
||||
bool dim;
|
||||
bool italic;
|
||||
bool underline;
|
||||
bool strikethrough;
|
||||
bool blink;
|
||||
bool conceal;
|
||||
bool reverse;
|
||||
uint32_t foreground;
|
||||
uint32_t background;
|
||||
};
|
||||
|
||||
struct terminal {
|
||||
|
|
|
|||
3
vt.c
3
vt.c
|
|
@ -186,8 +186,7 @@ action(struct terminal *term, enum action action, uint8_t c)
|
|||
cell->c[1] = '\0';
|
||||
}
|
||||
|
||||
cell->foreground = term->vt.foreground;
|
||||
cell->background = term->vt.background;
|
||||
cell->attrs = term->vt.attrs;
|
||||
|
||||
term->grid.cells[++term->grid.cursor].dirty = true;
|
||||
term->grid.dirty = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue