Add layout name completion to @ goto-layout
This commit is contained in:
parent
d7ab96856c
commit
23b8cafc41
3 changed files with 31 additions and 9 deletions
|
|
@ -336,8 +336,14 @@ def complete_remote_command(ans: Completions, cmd_name: str, words: Sequence[str
|
|||
return
|
||||
args_completer: Optional[CompleteArgsFunc] = None
|
||||
args_completion = command_for_name(cmd_name).args_completion
|
||||
if args_completion and 'files' in args_completion:
|
||||
args_completer = remote_files_completer(args_completion['files'])
|
||||
if args_completion:
|
||||
if 'files' in args_completion:
|
||||
title, matchers = args_completion['files']
|
||||
if isinstance(matchers, tuple):
|
||||
args_completer = remote_files_completer(title, matchers)
|
||||
elif 'names' in args_completion:
|
||||
title, q = args_completion['names']
|
||||
args_completer = remote_args_completer(title, q() if callable(q) else q)
|
||||
complete_alias_map(ans, words, new_word, alias_map, complete_args=args_completer)
|
||||
|
||||
|
||||
|
|
@ -406,8 +412,7 @@ def icat_file_predicate(filename: str) -> bool:
|
|||
complete_files_and_dirs(ans, prefix, 'Images', icat_file_predicate)
|
||||
|
||||
|
||||
def remote_files_completer(spec: Tuple[str, Tuple[str, ...]]) -> CompleteArgsFunc:
|
||||
name, matchers = spec
|
||||
def remote_files_completer(name: str, matchers: Tuple[str, ...]) -> CompleteArgsFunc:
|
||||
|
||||
def complete_files_map(ans: Completions, opt: Optional[OptionDict], prefix: str, unknown_args: Delegate) -> None:
|
||||
|
||||
|
|
@ -423,6 +428,16 @@ def predicate(filename: str) -> bool:
|
|||
return complete_files_map
|
||||
|
||||
|
||||
def remote_args_completer(title: str, words: Iterable[str]) -> CompleteArgsFunc:
|
||||
items = sorted(words)
|
||||
|
||||
def complete_names_for_arg(ans: Completions, opt: Optional[OptionDict], prefix: str, unknown_args: Delegate) -> None:
|
||||
if opt is None:
|
||||
ans.match_groups[title] = {c: '' for c in items if c.startswith(prefix)}
|
||||
|
||||
return complete_names_for_arg
|
||||
|
||||
|
||||
def config_file_predicate(filename: str) -> bool:
|
||||
return filename.endswith('.conf')
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
from contextlib import suppress
|
||||
from typing import (
|
||||
TYPE_CHECKING, Any, Callable, Dict, FrozenSet, Generator, List, NoReturn,
|
||||
Optional, Tuple, Type, Union, cast
|
||||
TYPE_CHECKING, Any, Callable, Dict, FrozenSet, Generator, Iterable, List,
|
||||
NoReturn, Optional, Tuple, Type, Union, cast
|
||||
)
|
||||
|
||||
from kitty.cli import get_defaults_from_seq, parse_args, parse_option_spec
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from kitty.boss import Boss as B
|
||||
from kitty.window import Window as W
|
||||
from kitty.tabs import Tab
|
||||
from kitty.window import Window as W
|
||||
Window = W
|
||||
Boss = B
|
||||
Tab
|
||||
|
|
@ -110,7 +110,7 @@ class RemoteCommand:
|
|||
no_response: bool = False
|
||||
string_return_is_error: bool = False
|
||||
args_count: Optional[int] = None
|
||||
args_completion: Optional[Dict[str, Tuple[str, Tuple[str, ...]]]] = None
|
||||
args_completion: Optional[Dict[str, Tuple[str, Union[Callable[[], Iterable[str]], Tuple[str, ...]]]]] = None
|
||||
defaults: Optional[Dict[str, Any]] = None
|
||||
options_class: Type = RCOptions
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# vim:fileencoding=utf-8
|
||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING, Optional, Iterable
|
||||
|
||||
from .base import (
|
||||
MATCH_TAB_OPTION, ArgsType, Boss, PayloadGetType, PayloadType, RCOptions,
|
||||
|
|
@ -13,6 +13,11 @@
|
|||
from kitty.cli_stub import GotoLayoutRCOptions as CLIOptions
|
||||
|
||||
|
||||
def layout_names() -> Iterable[str]:
|
||||
from kitty.layout.interface import all_layouts
|
||||
return all_layouts.keys()
|
||||
|
||||
|
||||
class GotoLayout(RemoteCommand):
|
||||
|
||||
'''
|
||||
|
|
@ -27,6 +32,8 @@ class GotoLayout(RemoteCommand):
|
|||
)
|
||||
options_spec = MATCH_TAB_OPTION
|
||||
argspec = 'LAYOUT_NAME'
|
||||
args_count = 1
|
||||
args_completion = {'names': ('Layouts', layout_names)}
|
||||
|
||||
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
|
||||
if len(args) != 1:
|
||||
|
|
|
|||
Loading…
Reference in a new issue