mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 19:21:38 +02:00
Add layout name completion to @ goto-layout
This commit is contained in:
@@ -336,8 +336,14 @@ def complete_remote_command(ans: Completions, cmd_name: str, words: Sequence[str
|
|||||||
return
|
return
|
||||||
args_completer: Optional[CompleteArgsFunc] = None
|
args_completer: Optional[CompleteArgsFunc] = None
|
||||||
args_completion = command_for_name(cmd_name).args_completion
|
args_completion = command_for_name(cmd_name).args_completion
|
||||||
if args_completion and 'files' in args_completion:
|
if args_completion:
|
||||||
args_completer = remote_files_completer(args_completion['files'])
|
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)
|
complete_alias_map(ans, words, new_word, alias_map, complete_args=args_completer)
|
||||||
|
|
||||||
|
|
||||||
@@ -406,8 +412,7 @@ def complete_icat_args(ans: Completions, opt: Optional[OptionDict], prefix: str,
|
|||||||
complete_files_and_dirs(ans, prefix, 'Images', icat_file_predicate)
|
complete_files_and_dirs(ans, prefix, 'Images', icat_file_predicate)
|
||||||
|
|
||||||
|
|
||||||
def remote_files_completer(spec: Tuple[str, Tuple[str, ...]]) -> CompleteArgsFunc:
|
def remote_files_completer(name: str, matchers: Tuple[str, ...]) -> CompleteArgsFunc:
|
||||||
name, matchers = spec
|
|
||||||
|
|
||||||
def complete_files_map(ans: Completions, opt: Optional[OptionDict], prefix: str, unknown_args: Delegate) -> None:
|
def complete_files_map(ans: Completions, opt: Optional[OptionDict], prefix: str, unknown_args: Delegate) -> None:
|
||||||
|
|
||||||
@@ -423,6 +428,16 @@ def remote_files_completer(spec: Tuple[str, Tuple[str, ...]]) -> CompleteArgsFun
|
|||||||
return complete_files_map
|
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:
|
def config_file_predicate(filename: str) -> bool:
|
||||||
return filename.endswith('.conf')
|
return filename.endswith('.conf')
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING, Any, Callable, Dict, FrozenSet, Generator, List, NoReturn,
|
TYPE_CHECKING, Any, Callable, Dict, FrozenSet, Generator, Iterable, List,
|
||||||
Optional, Tuple, Type, Union, cast
|
NoReturn, Optional, Tuple, Type, Union, cast
|
||||||
)
|
)
|
||||||
|
|
||||||
from kitty.cli import get_defaults_from_seq, parse_args, parse_option_spec
|
from kitty.cli import get_defaults_from_seq, parse_args, parse_option_spec
|
||||||
@@ -14,8 +14,8 @@ from kitty.constants import appname, running_in_kitty
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from kitty.boss import Boss as B
|
from kitty.boss import Boss as B
|
||||||
from kitty.window import Window as W
|
|
||||||
from kitty.tabs import Tab
|
from kitty.tabs import Tab
|
||||||
|
from kitty.window import Window as W
|
||||||
Window = W
|
Window = W
|
||||||
Boss = B
|
Boss = B
|
||||||
Tab
|
Tab
|
||||||
@@ -110,7 +110,7 @@ class RemoteCommand:
|
|||||||
no_response: bool = False
|
no_response: bool = False
|
||||||
string_return_is_error: bool = False
|
string_return_is_error: bool = False
|
||||||
args_count: Optional[int] = None
|
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
|
defaults: Optional[Dict[str, Any]] = None
|
||||||
options_class: Type = RCOptions
|
options_class: Type = RCOptions
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
# 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 (
|
from .base import (
|
||||||
MATCH_TAB_OPTION, ArgsType, Boss, PayloadGetType, PayloadType, RCOptions,
|
MATCH_TAB_OPTION, ArgsType, Boss, PayloadGetType, PayloadType, RCOptions,
|
||||||
@@ -13,6 +13,11 @@ if TYPE_CHECKING:
|
|||||||
from kitty.cli_stub import GotoLayoutRCOptions as CLIOptions
|
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):
|
class GotoLayout(RemoteCommand):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@@ -27,6 +32,8 @@ class GotoLayout(RemoteCommand):
|
|||||||
)
|
)
|
||||||
options_spec = MATCH_TAB_OPTION
|
options_spec = MATCH_TAB_OPTION
|
||||||
argspec = 'LAYOUT_NAME'
|
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:
|
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user