Fix clearing of tab stops

This commit is contained in:
Kovid Goyal 2016-11-30 10:21:37 +05:30
parent eb3bf71ef7
commit f0b1af964b
2 changed files with 34 additions and 1 deletions

View File

@ -406,9 +406,14 @@ screen_clear_tab_stop(Screen *self, unsigned int how) {
case 0:
if (self->cursor->x < self->columns) self->tabstops[self->cursor->x] = false;
break;
case 2:
break; // no-op
case 3:
break;
for (unsigned int i = 0; i < self->columns; i++) self->tabstops[i] = false;
break;
default:
fprintf(stderr, "%s %s %u\n", ERROR_PREFIX, "Unsupported clear tab stop mode: ", how);
break;
}
}
@ -1027,6 +1032,8 @@ static PyObject* current_char_width(Screen *self) {
return PyLong_FromUnsignedLong(ans);
}
WRAP2(cursor_position, 1, 1)
#define COUNT_WRAP(name) WRAP1(name, 1)
COUNT_WRAP(insert_lines)
COUNT_WRAP(delete_lines)
@ -1043,6 +1050,7 @@ COUNT_WRAP(cursor_forward)
static PyMethodDef methods[] = {
MND(line, METH_O)
MND(draw, METH_O)
MND(cursor_position, METH_VARARGS)
MND(set_mode, METH_VARARGS)
MND(reset_mode, METH_VARARGS)
MND(reset, METH_NOARGS)

View File

@ -246,3 +246,28 @@ class TestScreen(BaseTest):
for i in range(s.lines):
self.ae(str(hb.line(i)), '3')
self.ae(str(hb.line(5)), '2')
def test_tab_stops(self):
# Taken from vttest/main.c
s = self.create_screen(cols=80, lines=2)
s.cursor_position(1, 1)
s.clear_tab_stop(3)
for col in range(1, s.columns - 1, 3):
s.cursor_forward(3)
s.set_tab_stop()
s.cursor_position(1, 4)
for col in range(4, s.columns - 1, 6):
s.clear_tab_stop(0)
s.cursor_forward(6)
s.cursor_position(1, 7)
s.clear_tab_stop(2)
s.cursor_position(1, 1)
for col in range(1, s.columns - 1, 6):
s.tab()
s.draw('*')
s.cursor_position(2, 2)
for col in range(2, s.columns - 1, 6):
for i in range(5):
s.draw(' ')
s.draw('*')
self.ae(str(s.line(0)), str(s.line(1)))