From 9e68cc559a38e0c82c79a8bbe703174f04cbbe20 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Nov 2016 21:50:54 +0530 Subject: [PATCH] Implement CBT --- kitty/control-codes.h | 2 ++ kitty/data-types.h | 2 ++ kitty/parser.c | 2 ++ kitty/screen.c | 16 ++++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/kitty/control-codes.h b/kitty/control-codes.h index 84be1313f..0813282d6 100644 --- a/kitty/control-codes.h +++ b/kitty/control-codes.h @@ -225,6 +225,8 @@ // *Horizontal position adjust*: Same as :data:`CHA`. #define HPA '`' +// Back tab +#define CBT 'Z' // Misc sequences // ---------------- diff --git a/kitty/data-types.h b/kitty/data-types.h index 6a55e62c4..8ff3748a7 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -353,6 +353,8 @@ void screen_reverse_index(Screen *self); void screen_index(Screen *self); void screen_reset(Screen *self); void screen_set_tab_stop(Screen *self); +void screen_tab(Screen *self); +void screen_backtab(Screen *self, unsigned int); void screen_clear_tab_stop(Screen *self, unsigned int how); void screen_set_mode(Screen *self, unsigned int mode); void screen_reset_mode(Screen *self, unsigned int mode); diff --git a/kitty/parser.c b/kitty/parser.c index 545fda3bd..333f6289c 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -410,6 +410,8 @@ dispatch_csi(Screen *screen, PyObject DUMP_UNUSED *dump_callback) { CALL_CSI_HANDLER1(screen_cursor_to_column, 1); case VPA: CALL_CSI_HANDLER1(screen_cursor_to_line, 1); + case CBT: + CALL_CSI_HANDLER1(screen_backtab, 1); case CUP: case HVP: CALL_CSI_HANDLER2(screen_cursor_position, 1, 1); diff --git a/kitty/screen.c b/kitty/screen.c index 006935690..4bed1b344 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -430,6 +430,22 @@ screen_tab(Screen *self) { } } +void +screen_backtab(Screen *self, unsigned int count) { + // Move back count tabs + if (!count) count = 1; + unsigned int before = self->cursor->x; + int i; + while (count > 0 && self->cursor->x > 0) { + count--; + for (i = self->cursor->x - 1; i >= 0; i--) { + if (self->tabstops[i]) { self->cursor->x = i; break; } + } + if (i <= 0) self->cursor->x = 0; + } + if (before != self->cursor->x) tracker_cursor_changed(self->change_tracker); +} + void screen_clear_tab_stop(Screen *self, unsigned int how) { switch(how) {