mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 16:58:09 +02:00
Fix line_as_ansi
This commit is contained in:
21
kitty/line.c
21
kitty/line.c
@@ -382,28 +382,28 @@ line_as_ansi(Line *self, ANSIBuf *output, const GPUCell** prev_cell, index_type
|
|||||||
if (*prev_cell == NULL) *prev_cell = &blank_cell;
|
if (*prev_cell == NULL) *prev_cell = &blank_cell;
|
||||||
const CellAttrs mask_for_sgr = {.val=SGR_MASK};
|
const CellAttrs mask_for_sgr = {.val=SGR_MASK};
|
||||||
|
|
||||||
|
#define CMP_ATTRS (cell->attrs.val & mask_for_sgr.val) != ((*prev_cell)->attrs.val & mask_for_sgr.val)
|
||||||
|
#define CMP(x) cell->x != (*prev_cell)->x
|
||||||
|
|
||||||
for (index_type pos=start_at; pos < limit; pos++) {
|
for (index_type pos=start_at; pos < limit; pos++) {
|
||||||
unsigned n = text_in_cell_ansi(self->cpu_cells + pos, self->text_cache, output);
|
|
||||||
if (output->buf[output->len - n] == 0) {
|
|
||||||
if (previous_width == 2) { previous_width = 0; output->len -= n; continue; }
|
|
||||||
output->buf[output->len - n] = ' ';
|
|
||||||
}
|
|
||||||
if (output->hyperlink_pool) {
|
if (output->hyperlink_pool) {
|
||||||
hyperlink_id_type hid = self->cpu_cells[pos].hyperlink_id;
|
hyperlink_id_type hid = self->cpu_cells[pos].hyperlink_id;
|
||||||
if (hid != output->active_hyperlink_id) {
|
if (hid != output->active_hyperlink_id) {
|
||||||
WRITE_HYPERLINK(hid);
|
WRITE_HYPERLINK(hid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cell = &self->gpu_cells[pos];
|
cell = &self->gpu_cells[pos];
|
||||||
|
|
||||||
#define CMP_ATTRS (cell->attrs.val & mask_for_sgr.val) != ((*prev_cell)->attrs.val & mask_for_sgr.val)
|
|
||||||
#define CMP(x) cell->x != (*prev_cell)->x
|
|
||||||
if (CMP_ATTRS || CMP(fg) || CMP(bg) || CMP(decoration_fg)) {
|
if (CMP_ATTRS || CMP(fg) || CMP(bg) || CMP(decoration_fg)) {
|
||||||
const char *sgr = cell_as_sgr(cell, *prev_cell);
|
const char *sgr = cell_as_sgr(cell, *prev_cell);
|
||||||
if (*sgr) WRITE_SGR(sgr);
|
if (*sgr) WRITE_SGR(sgr);
|
||||||
}
|
}
|
||||||
*prev_cell = cell;
|
|
||||||
|
unsigned n = text_in_cell_ansi(self->cpu_cells + pos, self->text_cache, output);
|
||||||
|
if (output->buf[output->len - n] == 0) {
|
||||||
|
if (previous_width == 2) { previous_width = 0; output->len -= n; continue; }
|
||||||
|
output->buf[output->len - n] = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
if (output->buf[output->len - n] == '\t') {
|
if (output->buf[output->len - n] == '\t') {
|
||||||
unsigned num_cells_to_skip_for_tab = 0;
|
unsigned num_cells_to_skip_for_tab = 0;
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
@@ -414,6 +414,7 @@ line_as_ansi(Line *self, ANSIBuf *output, const GPUCell** prev_cell, index_type
|
|||||||
num_cells_to_skip_for_tab--; pos++;
|
num_cells_to_skip_for_tab--; pos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*prev_cell = cell;
|
||||||
previous_width = cell->attrs.width;
|
previous_width = cell->attrs.width;
|
||||||
}
|
}
|
||||||
return escape_code_written;
|
return escape_code_written;
|
||||||
|
|||||||
@@ -543,8 +543,8 @@ class TestDataTypes(BaseTest):
|
|||||||
c.bg = (1 << 24) | (2 << 16) | (3 << 8) | 2
|
c.bg = (1 << 24) | (2 << 16) | (3 << 8) | 2
|
||||||
c.decoration_fg = (5 << 8) | 1
|
c.decoration_fg = (5 << 8) | 1
|
||||||
l2.set_text('1', 0, 1, c)
|
l2.set_text('1', 0, 1, c)
|
||||||
self.ae(l2.as_ansi(), '\x1b[1;2;3;7;9;34;48:2:1:2:3;58:5:5m' '1'
|
self.ae(str(l2), '10000')
|
||||||
'\x1b[22;23;27;29;39;49;59m' '0000')
|
self.ae(l2.as_ansi(), '\x1b[1;2;3;7;9;34;48:2:1:2:3;58:5:5m' '1' '\x1b[22;23;27;29;39;49;59m' '0000') # ]]
|
||||||
lb = filled_line_buf()
|
lb = filled_line_buf()
|
||||||
for i in range(1, lb.ynum + 1):
|
for i in range(1, lb.ynum + 1):
|
||||||
lb.set_continued(i, True)
|
lb.set_continued(i, True)
|
||||||
|
|||||||
Reference in New Issue
Block a user