53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# vim:fileencoding=utf-8
|
|
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .base import (
|
|
MATCH_TAB_OPTION, ArgsType, Boss, MatchError, PayloadGetType,
|
|
PayloadType, RCOptions, RemoteCommand, ResponseType, Window
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from kitty.cli_stub import FocusTabRCOptions as CLIOptions
|
|
|
|
|
|
class FocusTab(RemoteCommand):
|
|
|
|
'''
|
|
match: The tab to focus
|
|
'''
|
|
|
|
short_desc = 'Focus the specified tab'
|
|
desc = 'The active window in the specified tab will be focused.'
|
|
options_spec = MATCH_TAB_OPTION + '''
|
|
|
|
--no-response
|
|
type=bool-set
|
|
default=false
|
|
Don't wait for a response indicating the success of the action. Note that
|
|
using this option means that you will not be notified of failures.
|
|
'''
|
|
argspec = ''
|
|
|
|
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
|
|
if opts.no_response:
|
|
global_opts.no_command_response = True
|
|
return {'match': opts.match}
|
|
|
|
def response_from_kitty(self, boss: 'Boss', window: 'Window', payload_get: PayloadGetType) -> ResponseType:
|
|
match = payload_get('match')
|
|
if match:
|
|
tabs = tuple(boss.match_tabs(match))
|
|
else:
|
|
tabs = tuple(boss.tab_for_window(window) if window else boss.active_tab)
|
|
if not tabs:
|
|
raise MatchError(match, 'tabs')
|
|
tab = tabs[0]
|
|
boss.set_active_tab(tab)
|
|
|
|
|
|
focus_tab = FocusTab()
|