Add simple parsing tests
This commit is contained in:
parent
9c002ef23c
commit
5069b50fb2
@ -39,11 +39,11 @@ HANDLER(text) {
|
||||
#define CALL_SCREEN_HANDLER(name) \
|
||||
DRAW_TEXT; \
|
||||
Py_XDECREF(PyObject_CallFunction(dump_callback, "sC", #name, (int)ch)); PyErr_Clear(); \
|
||||
screen_##name(screen, ch);
|
||||
screen_##name(screen, ch); break;
|
||||
#else
|
||||
#define CALL_SCREEN_HANDLER(name) \
|
||||
DRAW_TEXT; \
|
||||
screen_##name(screen, ch);
|
||||
screen_##name(screen, ch); break;
|
||||
#endif
|
||||
|
||||
#define CHANGE_PARSER_STATE(state) screen->parser_state = state; return;
|
||||
|
||||
@ -87,6 +87,16 @@ void screen_bell(Screen UNUSED *self, uint8_t ch) { // {{{
|
||||
} // }}}
|
||||
|
||||
// Draw text {{{
|
||||
|
||||
void screen_shift_out(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
self->current_charset = 1;
|
||||
self->utf8_state = 0;
|
||||
}
|
||||
|
||||
void screen_shift_in(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
self->current_charset = 0;
|
||||
self->utf8_state = 0;
|
||||
}
|
||||
|
||||
static inline unsigned int safe_wcwidth(uint32_t ch) {
|
||||
int ans = wcwidth(ch);
|
||||
@ -169,34 +179,8 @@ void screen_draw(Screen *self, uint8_t *buf, unsigned int buflen) {
|
||||
}
|
||||
// }}}
|
||||
|
||||
void screen_backspace(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
screen_cursor_back(self, 1, -1);
|
||||
}
|
||||
|
||||
void screen_tab(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
// Move to the next tab space, or the end of the screen if there aren't anymore left.
|
||||
unsigned int found = 0;
|
||||
for (unsigned int i = self->cursor->x + 1; i < self->columns; i++) {
|
||||
if (self->tabstops[i]) { found = i; break; }
|
||||
}
|
||||
if (!found) found = self->columns - 1;
|
||||
if (found != (unsigned int)self->cursor->x) {
|
||||
self->cursor->x = found;
|
||||
tracker_cursor_changed(self->change_tracker);
|
||||
}
|
||||
}
|
||||
|
||||
void screen_shift_out(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
self->current_charset = 1;
|
||||
self->utf8_state = 0;
|
||||
}
|
||||
|
||||
void screen_shift_in(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
self->current_charset = 0;
|
||||
self->utf8_state = 0;
|
||||
}
|
||||
|
||||
// Graphics {{{
|
||||
|
||||
void screen_change_default_color(Screen *self, unsigned int which, uint32_t col) {
|
||||
if (self->callbacks == Py_None) return;
|
||||
if (col & 0xFF) PyObject_CallMethod(self->callbacks, "change_default_color", "s(III)", which == FG ? "fg" : "bg",
|
||||
@ -209,6 +193,7 @@ void screen_change_default_color(Screen *self, unsigned int which, uint32_t col)
|
||||
|
||||
// Modes {{{
|
||||
|
||||
|
||||
void screen_toggle_screen_buffer(Screen *self) {
|
||||
screen_save_cursor(self);
|
||||
if (self->linebuf == self->main_linebuf) {
|
||||
@ -328,6 +313,22 @@ void screen_reset_mode(Screen *self, int mode) {
|
||||
|
||||
// Cursor {{{
|
||||
|
||||
void screen_backspace(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
screen_cursor_back(self, 1, -1);
|
||||
}
|
||||
void screen_tab(Screen UNUSED *self, uint8_t UNUSED ch) {
|
||||
// Move to the next tab space, or the end of the screen if there aren't anymore left.
|
||||
unsigned int found = 0;
|
||||
for (unsigned int i = self->cursor->x + 1; i < self->columns; i++) {
|
||||
if (self->tabstops[i]) { found = i; break; }
|
||||
}
|
||||
if (!found) found = self->columns - 1;
|
||||
if (found != (unsigned int)self->cursor->x) {
|
||||
self->cursor->x = found;
|
||||
tracker_cursor_changed(self->change_tracker);
|
||||
}
|
||||
}
|
||||
|
||||
void screen_cursor_back(Screen *self, unsigned int count/*=1*/, int move_direction/*=-1*/) {
|
||||
int x = self->cursor->x;
|
||||
if (count == 0) count = 1;
|
||||
@ -762,6 +763,7 @@ static PyMemberDef members[] = {
|
||||
{"linebuf", T_OBJECT_EX, offsetof(Screen, linebuf), 0, "linebuf"},
|
||||
{"lines", T_UINT, offsetof(Screen, lines), 0, "lines"},
|
||||
{"columns", T_UINT, offsetof(Screen, columns), 0, "columns"},
|
||||
{"current_charset", T_UINT, offsetof(Screen, current_charset), 0, "current_charset"},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
||||
28
kitty_tests/parser.py
Normal file
28
kitty_tests/parser.py
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
from kitty.fast_data_types import parse_bytes
|
||||
|
||||
|
||||
class TestScreen(BaseTest):
|
||||
|
||||
def test_simple_parsing(self):
|
||||
s = self.create_screen()
|
||||
parse_bytes(s, b'12')
|
||||
self.ae(str(s.line(0)), '12 ')
|
||||
parse_bytes(s, b'3456')
|
||||
self.ae(str(s.line(0)), '12345')
|
||||
self.ae(str(s.line(1)), '6 ')
|
||||
parse_bytes(s, b'\n123\n\r45')
|
||||
self.ae(str(s.line(1)), '6 ')
|
||||
self.ae(str(s.line(2)), ' 123 ')
|
||||
self.ae(str(s.line(3)), '45 ')
|
||||
parse_bytes(s, b'\rabcde')
|
||||
self.ae(str(s.line(3)), 'abcde')
|
||||
parse_bytes(s, '\rßxyz1'.encode('utf-8'))
|
||||
self.ae(str(s.line(3)), 'ßxyz1')
|
||||
parse_bytes(s, 'ニチ '.encode('utf-8'))
|
||||
self.ae(str(s.line(4)), 'ニチ ')
|
||||
Loading…
x
Reference in New Issue
Block a user