From c11a20f1ec24b34b986befb155ebbd0353059dad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 9 Jan 2018 23:09:57 +0530 Subject: [PATCH] Add --new-tab to @new-window --- kitty/boss.py | 7 +++++-- kitty/remote_control.py | 24 ++++++++++++++++++++++-- kitty/tabs.py | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 05a593907..3e3306309 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -19,7 +19,7 @@ from .fonts.render import prerender, resize_fonts, set_font_family from .keys import get_shortcut from .remote_control import handle_cmd from .session import create_session -from .tabs import SpecialWindow, TabManager +from .tabs import SpecialWindow, SpecialWindowInstance, TabManager from .utils import ( end_startup_notification, get_primary_selection, init_startup_notification, open_url, safe_print, set_primary_selection, single_instance @@ -452,7 +452,10 @@ class Boss: def _new_tab(self, args, cwd_from=None): special_window = None if args: - special_window = self.args_to_special_window(args, cwd_from=cwd_from) + if isinstance(args, SpecialWindowInstance): + special_window = args + else: + special_window = self.args_to_special_window(args, cwd_from=cwd_from) tm = self.active_tab_manager if tm is not None: tm.new_tab(special_window=special_window, cwd_from=cwd_from) diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 6dd87c9d1..9fe9a6b26 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -11,6 +11,7 @@ from functools import partial from .cli import emph, parse_args from .config import parse_send_text_bytes from .constants import appname, version +from .tabs import SpecialWindow from .utils import read_with_timeout @@ -225,13 +226,32 @@ program running in it. --cwd The initial working directory for the new window. + + +--new-tab +type=bool-set +Open a new tab + + +--tab-title +When using --new-tab set the title of the tab. ''' ) def cmd_new_window(global_opts, opts, args): - return {'match': opts.match, 'title': opts.title, 'cwd': opts.cwd, 'args': args or []} + return {'match': opts.match, 'title': opts.title, 'cwd': opts.cwd, + 'new_tab': opts.new_tab, 'tab_title': opts.tab_title, + 'args': args or []} def new_window(boss, window, payload): + w = SpecialWindow(cmd=payload['args'] or None, override_title=payload['title'], cwd=payload['cwd']) + if payload['new_tab']: + boss._new_tab(w) + tab = boss.active_tab + if payload['tab_title']: + tab.set_title(payload['tab_title']) + return str(boss.active_window.id) + match = payload['match'] if match: tabs = tuple(boss.match_tabs(match)) @@ -240,7 +260,7 @@ def new_window(boss, window, payload): else: tabs = [boss.active_tab] tab = tabs[0] - w = tab.new_window(use_shell=True, cmd=payload['args'] or None, override_title=payload['title'], cwd=payload['cwd']) + w = tab.new_special_window(w) return str(w.id) diff --git a/kitty/tabs.py b/kitty/tabs.py index 4a66f1316..af13bf6c3 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -143,7 +143,7 @@ class Tab: # {{{ return window def new_special_window(self, special_window): - self.new_window(False, *special_window) + return self.new_window(False, *special_window) def close_window(self): if self.windows: