From d132ba5a487fbe16324883f46fef3fea2763251a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Nov 2016 08:34:02 +0530 Subject: [PATCH] Implement DECALN --- kitty/data-types.h | 3 ++- kitty/line-buf.c | 12 ++++++------ kitty/parser.c | 7 +++++++ kitty/screen.c | 9 ++++++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 26ac576bb..befa12953 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -318,7 +318,7 @@ void line_right_shift(Line *, unsigned int , unsigned int ); void line_add_combining_char(Line *, uint32_t , unsigned int ); void linebuf_init_line(LineBuf *, index_type); -void linebuf_clear(LineBuf *); +void linebuf_clear(LineBuf *, char_type ch); void linebuf_init_line(LineBuf *, index_type); void linebuf_index(LineBuf* self, index_type top, index_type bottom); void linebuf_reverse_index(LineBuf *self, index_type top, index_type bottom); @@ -333,6 +333,7 @@ void historybuf_add_line(HistoryBuf *self, const Line *line); void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other); void historybuf_init_line(HistoryBuf *self, index_type num, Line *l); +void screen_align(Screen*); void screen_restore_cursor(Screen *); void screen_save_cursor(Screen *); void screen_cursor_position(Screen*, unsigned int, unsigned int); diff --git a/kitty/line-buf.c b/kitty/line-buf.c index 84e6e751c..635a60293 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -9,16 +9,16 @@ #include static inline void -clear_chars_to_space(LineBuf* linebuf, index_type y) { +clear_chars_to(LineBuf* linebuf, index_type y, char_type ch) { char_type *chars = linebuf->chars + linebuf->xnum * y; - for (index_type i = 0; i < linebuf->xnum; i++) chars[i] = (1 << ATTRS_SHIFT) | 32; + for (index_type i = 0; i < linebuf->xnum; i++) chars[i] = (1 << ATTRS_SHIFT) | ch; } -void linebuf_clear(LineBuf *self) { +void linebuf_clear(LineBuf *self, char_type ch) { memset(self->buf, 0, self->block_size * CELL_SIZE); memset(self->continued_map, 0, self->ynum * sizeof(bool)); for (index_type i = 0; i < self->ynum; i++) { - clear_chars_to_space(self, i); + clear_chars_to(self, i, ch); self->line_map[i] = i; } } @@ -26,7 +26,7 @@ void linebuf_clear(LineBuf *self) { static PyObject* clear(LineBuf *self) { #define clear_doc "Clear all lines in this LineBuf" - linebuf_clear(self); + linebuf_clear(self, ' '); Py_RETURN_NONE; } @@ -69,7 +69,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { self->line->xnum = xnum; for(index_type i = 0; i < ynum; i++) { self->line_map[i] = i; - clear_chars_to_space(self, i); + clear_chars_to(self, i, ' '); } } } diff --git a/kitty/parser.c b/kitty/parser.c index 5b0cd5144..1bb465e5a 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -191,6 +191,7 @@ handle_esc_mode_char(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_cal case '.': case '/': case ' ': + case '#': screen->parser_buf[screen->parser_buf_pos++] = ch; break; default: @@ -201,6 +202,12 @@ handle_esc_mode_char(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_cal default: if ((screen->parser_buf[0] == '%' && ch == 'G') || (screen->parser_buf[0] == '(' && ch == 'B')) { // switch to utf-8 or ascii, since we are always in utf-8, ignore. + } else if (screen->parser_buf[0] == '#') { + if (ch == '8') { + screen_align(screen); + } else { + REPORT_ERROR("Unhandled Esc # code: 0x%x", ch); + } } else { REPORT_ERROR("Unhandled charset related escape code: 0x%x 0x%x", screen->parser_buf[0], ch); } diff --git a/kitty/screen.c b/kitty/screen.c index 49a0da4b7..5ebb06b92 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -56,7 +56,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { void screen_reset(Screen *self) { if (self->linebuf == self->alt_linebuf) screen_toggle_screen_buffer(self); - linebuf_clear(self->linebuf); + linebuf_clear(self->linebuf, ' '); self->modes = empty_modes; self->utf8_state = 0; self->margin_top = 0; self->margin_bottom = self->lines - 1; @@ -189,6 +189,13 @@ screen_draw(Screen *self, uint32_t ch) { if (x != self->cursor->x || y != self->cursor->y) tracker_cursor_changed(self->change_tracker); } +void +screen_align(Screen *self) { + self->margin_top = 0; self->margin_bottom = self->lines - 1; + screen_cursor_position(self, 1, 1); + linebuf_clear(self->linebuf, 'E'); +} + // }}} // Graphics {{{