Skip to content

Instantly share code, notes, and snippets.

@dlipovetsky
Created November 27, 2021 07:05
Show Gist options
  • Save dlipovetsky/021ab8fd76ff2b7cf02eb16b6448f2d3 to your computer and use it in GitHub Desktop.
Save dlipovetsky/021ab8fd76ff2b7cf02eb16b6448f2d3 to your computer and use it in GitHub Desktop.
from typing import List, Optional
from kitty.boss import Boss
from kitty.tabs import Tab
from kitty.window import Window
from kittens.tui.handler import result_handler
import json
def main(args):
pass
@result_handler(no_ui=True)
def handle_result(args: List[str], answer: str, target_window_id: int, boss: Boss) -> str:
tab = boss.active_tab
if tab == None:
return
# The 'stack' layout only shows one window, so temporarily use the 'horizontal' layout to let the user choose a
# window.
changed_layout = False
if tab.current_layout and tab.current_layout.name == 'stack':
tab.goto_layout('horizontal')
changed_layout = True
def callback(tab: Optional[Tab], window: Optional[Window]) -> None:
if tab:
if window:
tab.set_active_window(window)
if changed_layout:
tab.last_used_layout()
# If the active window is not listed and the user selects it, the selection is cancelled, and callback is not
# called, which means the layout is not switched back. Therefore, list the active window, too.
#boss.visual_window_select_action(tab, callback, 'Choose window to switch to', only_window_ids=tab.all_window_ids_except_active_window)
boss.visual_window_select_action(tab, callback, 'Choose window to switch to')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment