Skip to content

Commit

Permalink
Implement window title stack
Browse files Browse the repository at this point in the history
Used by new versions of vim
  • Loading branch information
kovidgoyal committed Aug 29, 2018
1 parent 0e248b3 commit 3067103
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 4 additions & 0 deletions kitty/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def draw(*a):
write(' '.join(a))


def screen_manipulate_title_stack(op, which):
write(CSI + '%d;%dt' % (op, which))


def report_device_attributes(mode, char):
x = CSI
if char:
Expand Down
32 changes: 20 additions & 12 deletions kitty/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,20 +703,28 @@ dispatch_csi(Screen *screen, PyObject DUMP_UNUSED *dump_callback) {
REPORT_ERROR("Unknown CSI s sequence with start and end modifiers: '%c' '%c' and %u parameters", start_modifier, end_modifier, num_params);
break;
case 't':
if (!start_modifier && !end_modifier && num_params == 1) {
switch(params[0]) {
case 14:
case 16:
case 18:
CALL_CSI_HANDLER1(screen_report_size, 0);
break;
default:
REPORT_ERROR("Unknown CSI t sequences with parameter: '%u'", params[0]);
break;
}
if (!num_params) {
REPORT_ERROR("Unknown CSI t sequence with start and end modifiers: '%c' '%c' and no parameters", start_modifier, end_modifier);
break;
}
if (start_modifier || end_modifier) {
REPORT_ERROR("Unknown CSI t sequence with start and end modifiers: '%c' '%c', %u parameters and first parameter: %u", start_modifier, end_modifier, num_params, params[0]);
break;
}
REPORT_ERROR("Unknown CSI t sequence with start and end modifiers: '%c' '%c' and %u parameters", start_modifier, end_modifier, num_params);
switch(params[0]) {
case 14:
case 16:
case 18:
CALL_CSI_HANDLER1(screen_report_size, 0);
break;
case 22:
case 23:
CALL_CSI_HANDLER2(screen_manipulate_title_stack, 22, 0);
break;
default:
REPORT_ERROR("Unknown CSI t window manipulation sequence with %u parameters and first parameter: %u", num_params, params[0]);
break;
}
break;
case 'u':
if (!start_modifier && !end_modifier && !num_params) {
Expand Down
9 changes: 9 additions & 0 deletions kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,15 @@ screen_report_size(Screen *self, unsigned int which) {
}
}

void
screen_manipulate_title_stack(Screen *self, unsigned int op, unsigned int which) {
CALLBACK("manipulate_title_stack", "OOO",
op == 23 ? Py_True : Py_False,
which == 0 || which == 2 ? Py_True : Py_False,
which == 0 || which == 1 ? Py_True : Py_False
);
}

void
report_device_status(Screen *self, unsigned int which, bool private) {
// We don't implement the private device status codes, since I haven't come
Expand Down
1 change: 1 addition & 0 deletions kitty/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ bool screen_open_url(Screen*);
void screen_dirty_sprite_positions(Screen *self);
void screen_rescale_images(Screen *self);
void screen_report_size(Screen *, unsigned int which);
void screen_manipulate_title_stack(Screen *, unsigned int op, unsigned int which);
void screen_draw_overlay_text(Screen *self, const char *utf8_text);
#define DECLARE_CH_SCREEN_HANDLER(name) void screen_##name(Screen *screen);
DECLARE_CH_SCREEN_HANDLER(bell)
Expand Down
11 changes: 11 additions & 0 deletions kitty/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(self, tab, child, opts, args, override_title=None):
self.overlay_for = None
self.default_title = os.path.basename(child.argv[0] or appname)
self.child_title = self.default_title
self.title_stack = deque(maxlen=10)
self.allow_remote_control = child.allow_remote_control
self.id = add_window(tab.os_window_id, tab.id, self.title)
if not self.id:
Expand Down Expand Up @@ -413,6 +414,16 @@ def write(key, func):
write('c', set_clipboard_string)
if 'write-primary' in self.opts.clipboard_control:
write('p', set_primary_selection)

def manipulate_title_stack(self, pop, title, icon):
if title:
if pop:
if self.title_stack:
self.child_title = self.title_stack.popleft()
self.title_updated()
else:
if self.child_title:
self.title_stack.append(self.child_title)
# }}}

def text_for_selection(self):
Expand Down

0 comments on commit 3067103

Please sign in to comment.