Implement DECALN

This commit is contained in:
Kovid Goyal 2016-11-30 08:34:02 +05:30
parent 358b2bc5f1
commit d132ba5a48
4 changed files with 23 additions and 8 deletions

View file

@ -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);

View file

@ -9,16 +9,16 @@
#include <structmember.h>
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, ' ');
}
}
}

View file

@ -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);
}

View file

@ -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 {{{