diff --git a/README.asciidoc b/README.asciidoc index 1d3458148..cf524c615 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -39,6 +39,7 @@ :sc_scroll_page_down: pass:quotes[`ctrl+shift+page_down`] :sc_scroll_page_up: pass:quotes[`ctrl+shift+page_up`] :sc_second_window: pass:quotes[`ctrl+shift+2`] +:sc_set_tab_title: pass:quotes[`ctrl+shift+alt+t`] :sc_seventh_window: pass:quotes[`ctrl+shift+7`] :sc_show_scrollback: pass:quotes[`ctrl+shift+h`] :sc_sixth_window: pass:quotes[`ctrl+shift+6`] @@ -202,6 +203,7 @@ windows are: |Next layout | {sc_next_layout} |Move tab forward | {sc_move_tab_forward} |Move tab backward | {sc_move_tab_backward} +|Set tab title | {sc_set_tab_title} |=== diff --git a/kittens/ask/main.py b/kittens/ask/main.py index 173762bf3..4265df63b 100644 --- a/kittens/ask/main.py +++ b/kittens/ask/main.py @@ -6,7 +6,6 @@ import json import os import readline import sys -from gettext import gettext as _ from kitty.cli import parse_args from kitty.constants import cache_dir @@ -87,7 +86,7 @@ def real_main(args): try: args, items = parse_args(args[1:], option_text, '', msg, 'kitty ask') except SystemExit as e: - print(e.args[0], file=sys.stderr) + print(e.args[0]) input('Press enter to quit...') raise SystemExit(1) @@ -95,11 +94,9 @@ def real_main(args): with alternate_screen(), HistoryCompleter(args.name): if args.message: - print(styled(args.message), bold=True) + print(styled(args.message, bold=True)) - prompt = ': ' - if args.type == 'line': - prompt = _('Enter line: ') + prompt = '> ' try: ans = input(prompt) except (KeyboardInterrupt, EOFError): @@ -110,8 +107,8 @@ def real_main(args): def main(args=sys.argv): try: real_main(args) - except Exception: + except Exception as e: import traceback - traceback.print_exc() + traceback.print_exc(file=sys.stdout) input('Press enter to quit...') raise SystemExit(1) diff --git a/kitty/boss.py b/kitty/boss.py index 4680d1986..47f97e6c6 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -3,6 +3,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal import atexit +import json import re import socket from functools import partial @@ -204,7 +205,6 @@ class Boss: return response def peer_message_received(self, msg): - import json msg = msg.decode('utf-8') cmd_prefix = '\x1bP@kitty-cmd' if msg.startswith(cmd_prefix): @@ -435,10 +435,17 @@ class Boss: overlay_for=w.id)) overlay_window.action_on_close = partial(self.send_unicode_character, w.id) + def get_output(self, source_window, num_lines=1): + output = '' + s = source_window.screen + for i in range(min(num_lines, s.lines)): + output += str(s.linebuf.line(i)) + return output + def send_unicode_character(self, target_window_id, source_window): w = self.window_id_map.get(target_window_id) if w is not None: - output = str(source_window.screen.linebuf.line(0)) + output = self.get_output(source_window) if output.startswith('OK: '): try: text = chr(int(output.partition(' ')[2], 16)) @@ -448,6 +455,28 @@ class Boss: else: w.paste(text) + def set_tab_title(self): + w = self.active_window + tab = self.active_tab + if w is not None and tab is not None and w.overlay_for is None: + args = ['--name=tab-title', '--message', _('Enter the new title for this tab below.')] + overlay_window = tab.new_special_window( + SpecialWindow( + ['kitty', '+runpy', 'from kittens.ask.main import main; main()'] + args, + overlay_for=w.id)) + overlay_window.action_on_close = partial(self.do_set_tab_title, tab.id) + + def do_set_tab_title(self, tab_id, source_window): + output = self.get_output(source_window) + if output.startswith('OK: '): + title = json.loads(output.partition(' ')[2].strip()) + tm = self.active_tab_manager + if tm is not None and title: + for tab in tm.tabs: + if tab.id == tab_id: + tab.set_title(title) + break + def run_simple_kitten(self, type_of_input, kitten, *args): import shlex w = self.active_window diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 38a67252c..4251c4a0c 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -392,6 +392,7 @@ map ctrl+shift+q close_tab map ctrl+shift+l next_layout map ctrl+shift+. move_tab_forward map ctrl+shift+, move_tab_backward +map ctrl+shift+alt+t set_tab_title # You can also create shortcuts to go to specific tabs, with 1 being the first tab # map ctrl+alt+1 goto_tab 1 # map ctrl+alt+2 goto_tab 2