line_as_ansi: only compute sgr if needed
This commit is contained in:
parent
ee39d7ba14
commit
a4c2a9ef0d
14
kitty/line.c
14
kitty/line.c
@ -237,21 +237,25 @@ line_as_ansi(Line *self, Py_UCS4 *buf, index_type buflen) {
|
|||||||
|
|
||||||
WRITE_SGR("0");
|
WRITE_SGR("0");
|
||||||
Cursor c1 = {{0}}, c2 = {{0}};
|
Cursor c1 = {{0}}, c2 = {{0}};
|
||||||
Cursor *cursor = &c1, *prev_cursor = &c2, *t;
|
Cursor *cursor = &c1, *prev_cursor = &c2;
|
||||||
|
char_type prev_attrs = 0;
|
||||||
|
|
||||||
for (index_type pos=0; pos < limit; pos++) {
|
for (index_type pos=0; pos < limit; pos++) {
|
||||||
|
bool need_sgr = false;
|
||||||
char_type attrs = self->gpu_cells[pos].attrs, ch = self->cpu_cells[pos].ch;
|
char_type attrs = self->gpu_cells[pos].attrs, ch = self->cpu_cells[pos].ch;
|
||||||
if (ch == 0) {
|
if (ch == 0) {
|
||||||
if (previous_width == 2) { previous_width = 0; continue; }
|
if (previous_width == 2) { previous_width = 0; continue; }
|
||||||
ch = ' ';
|
ch = ' ';
|
||||||
}
|
}
|
||||||
ATTRS_TO_CURSOR(attrs, cursor);
|
if (attrs != prev_attrs) { ATTRS_TO_CURSOR(attrs, cursor); need_sgr = true; prev_attrs = attrs; }
|
||||||
cursor->fg = self->gpu_cells[pos].fg; cursor->bg = self->gpu_cells[pos].bg;
|
#define CMPSET(color) if (cursor->color != self->gpu_cells[pos].color) { cursor->color = self->gpu_cells[pos].color; need_sgr = true; }
|
||||||
cursor->decoration_fg = self->gpu_cells[pos].decoration_fg & COL_MASK;
|
CMPSET(fg); CMPSET(bg); CMPSET(decoration_fg);
|
||||||
|
|
||||||
|
if (need_sgr) {
|
||||||
const char *sgr = cursor_as_sgr(cursor, prev_cursor);
|
const char *sgr = cursor_as_sgr(cursor, prev_cursor);
|
||||||
t = prev_cursor; prev_cursor = cursor; cursor = t;
|
*prev_cursor = *cursor;
|
||||||
if (*sgr) WRITE_SGR(sgr);
|
if (*sgr) WRITE_SGR(sgr);
|
||||||
|
}
|
||||||
WRITE_CH(ch);
|
WRITE_CH(ch);
|
||||||
for(unsigned c = 0; c < arraysz(self->cpu_cells[pos].cc_idx) && self->cpu_cells[pos].cc_idx[c]; c++) {
|
for(unsigned c = 0; c < arraysz(self->cpu_cells[pos].cc_idx) && self->cpu_cells[pos].cc_idx[c]; c++) {
|
||||||
WRITE_CH(codepoint_for_mark(self->cpu_cells[pos].cc_idx[c]));
|
WRITE_CH(codepoint_for_mark(self->cpu_cells[pos].cc_idx[c]));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user