Implement @focus-window

This commit is contained in:
Kovid Goyal 2018-01-10 13:23:04 +05:30
parent 88523b2692
commit 3cd744b247
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 26 additions and 1 deletions

View File

@ -328,6 +328,27 @@ def new_window(boss, window, payload):
return str(w.id) 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( @cmd(
'Get text from the specified window', 'Get text from the specified window',
options_spec=MATCH_WINDOW_OPTION + '''\n options_spec=MATCH_WINDOW_OPTION + '''\n

View File

@ -35,7 +35,7 @@ another window, for example:
This will show the output of ls in the output window instead of the current 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 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: 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 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: You can get a listing of available tabs and windows, by running:
kitty @ ls kitty @ ls