Create a shortcut to set the tab title
No longer need to use remote control just to change tab titles.
This commit is contained in:
parent
71db024a3b
commit
be8f2b8106
@ -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}
|
||||
|
||||
|===
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user