DRYer
This commit is contained in:
parent
56e55ddbc3
commit
5103381c27
17
kitty/line.c
17
kitty/line.c
@ -62,13 +62,7 @@ static PyObject *
|
|||||||
as_unicode(Line* self) {
|
as_unicode(Line* self) {
|
||||||
Py_ssize_t n = 0;
|
Py_ssize_t n = 0;
|
||||||
static Py_UCS4 buf[4096];
|
static Py_UCS4 buf[4096];
|
||||||
index_type xlimit = MIN(sizeof(buf)/sizeof(buf[0]), self->xnum);
|
index_type xlimit = MIN(sizeof(buf)/sizeof(buf[0]), xlimit_for_line(self));
|
||||||
if (BLANK_CHAR == 0) {
|
|
||||||
while (xlimit != 0) {
|
|
||||||
if ((self->cells[xlimit - 1].ch & CHAR_MASK) != BLANK_CHAR) break;
|
|
||||||
xlimit--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
char_type previous_width = 0;
|
char_type previous_width = 0;
|
||||||
for(index_type i = 0; i < xlimit; i++) {
|
for(index_type i = 0; i < xlimit; i++) {
|
||||||
char_type ch = self->cells[i].ch & CHAR_MASK;
|
char_type ch = self->cells[i].ch & CHAR_MASK;
|
||||||
@ -127,14 +121,7 @@ line_as_ansi(Line *self, Py_UCS4 *buf, index_type buflen) {
|
|||||||
#define CHECK_COLOR(name, val, off_code) if (name != (val)) { name = (val); WRITE_COLOR(name, off_code); }
|
#define CHECK_COLOR(name, val, off_code) if (name != (val)) { name = (val); WRITE_COLOR(name, off_code); }
|
||||||
#define WRITE_CH(val) if (i > buflen - 1) return i; buf[i++] = val;
|
#define WRITE_CH(val) if (i > buflen - 1) return i; buf[i++] = val;
|
||||||
|
|
||||||
index_type limit = self->xnum, i=0;
|
index_type limit = xlimit_for_line(self), i=0;
|
||||||
int r;
|
|
||||||
if (!self->continued) { // Trim trailing blanks
|
|
||||||
for(r = self->xnum - 1; r >= 0; r--) {
|
|
||||||
if ((self->cells[r].ch & CHAR_MASK) != BLANK_CHAR) break;
|
|
||||||
}
|
|
||||||
limit = r + 1;
|
|
||||||
}
|
|
||||||
bool bold = false, italic = false, reverse = false, strike = false;
|
bool bold = false, italic = false, reverse = false, strike = false;
|
||||||
uint32_t fg = 0, bg = 0, decoration_fg = 0, decoration = 0;
|
uint32_t fg = 0, bg = 0, decoration_fg = 0, decoration = 0;
|
||||||
char_type previous_width = 0;
|
char_type previous_width = 0;
|
||||||
|
|||||||
@ -46,6 +46,18 @@ clear_chars_in_line(Cell *cells, index_type xnum, char_type ch) {
|
|||||||
for (index_type i = 0; i < xnum; i++) cells[i].ch = c;
|
for (index_type i = 0; i < xnum; i++) cells[i].ch = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline index_type
|
||||||
|
xlimit_for_line(Line *line) {
|
||||||
|
index_type xlimit = line->xnum;
|
||||||
|
if (BLANK_CHAR == 0) {
|
||||||
|
while (xlimit != 0) {
|
||||||
|
if ((line->cells[xlimit - 1].ch & CHAR_MASK) != BLANK_CHAR) break;
|
||||||
|
xlimit--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return xlimit;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject* line_text_at(char_type, combining_type);
|
PyObject* line_text_at(char_type, combining_type);
|
||||||
void line_clear_text(Line *self, unsigned int at, unsigned int num, int ch);
|
void line_clear_text(Line *self, unsigned int at, unsigned int num, int ch);
|
||||||
void line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num, bool clear_char);
|
void line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num, bool clear_char);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user