From 3cd744b247c60833e198ddfd561b033cc0bdbfd9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Jan 2018 13:23:04 +0530 Subject: [PATCH] Implement @focus-window --- kitty/remote_control.py | 21 +++++++++++++++++++++ remote-control.asciidoc | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kitty/remote_control.py b/kitty/remote_control.py index d53f0ffd5..734e80ed6 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -328,6 +328,27 @@ def new_window(boss, window, payload): return str(w.id) +@cmd( + 'Focus the specified window', + options_spec=MATCH_WINDOW_OPTION +) +def cmd_focus_window(global_opts, opts, args): + return {'match': opts.match} + + +def focus_window(boss, window, payload): + windows = [window or boss.active_window] + match = payload['match'] + if match: + windows = tuple(boss.match_windows(match)) + if not windows: + raise ValueError('No matching windows for expression: {}'.format(match)) + for window in windows: + if window: + boss.set_active_window(window) + break + + @cmd( 'Get text from the specified window', options_spec=MATCH_WINDOW_OPTION + '''\n diff --git a/remote-control.asciidoc b/remote-control.asciidoc index 6e2fdfed2..7130ad574 100644 --- a/remote-control.asciidoc +++ b/remote-control.asciidoc @@ -35,7 +35,7 @@ another window, for example: This will show the output of ls in the output window instead of the current window. You can use this technique to, for example, show the output of running -make in your editor in a different window. The possibilities are endless. +`make` in your editor in a different window. The possibilities are endless. You can even have things you type show up in a different window. Run: @@ -57,6 +57,10 @@ Let's change the title of the current tab: kitty @ set-tab-title Master Tab +Now lets switch to the newly opened tab. + + kitty @ focus-window --match title:New + You can get a listing of available tabs and windows, by running: kitty @ ls