mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-15 21:14:35 +02:00
Create an auto-generated stub file for the kitty Options object
This commit is contained in:
@@ -5,13 +5,15 @@
|
||||
# Utils {{{
|
||||
import os
|
||||
from gettext import gettext as _
|
||||
from typing import Dict, Union
|
||||
from typing import (
|
||||
Dict, FrozenSet, Iterable, List, Optional, Set, Tuple, TypeVar, Union
|
||||
)
|
||||
|
||||
from . import fast_data_types as defines
|
||||
from .conf.definition import Option, Shortcut, option_func
|
||||
from .conf.utils import (
|
||||
choices, positive_float, positive_int, to_bool, to_cmdline, to_color,
|
||||
to_color_or_none, unit_float
|
||||
Color, choices, positive_float, positive_int, to_bool, to_cmdline,
|
||||
to_color, to_color_or_none, unit_float
|
||||
)
|
||||
from .constants import config_dir, is_macos
|
||||
from .fast_data_types import CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE
|
||||
@@ -42,14 +44,17 @@ def parse_mods(parts, sc):
|
||||
return mods
|
||||
|
||||
|
||||
def to_modifiers(val):
|
||||
def to_modifiers(val: str) -> int:
|
||||
return parse_mods(val.split('+'), val) or 0
|
||||
|
||||
|
||||
def uniq(vals, result_type=list):
|
||||
seen = set()
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
def uniq(vals: Iterable[T]) -> List[T]:
|
||||
seen: Set[T] = set()
|
||||
seen_add = seen.add
|
||||
return result_type(x for x in vals if x not in seen and not seen_add(x))
|
||||
return [x for x in vals if x not in seen and not seen_add(x)]
|
||||
# }}}
|
||||
|
||||
# Groups {{{
|
||||
@@ -221,7 +226,7 @@ o('italic_font', 'auto')
|
||||
o('bold_italic_font', 'auto')
|
||||
|
||||
|
||||
def to_font_size(x):
|
||||
def to_font_size(x: str) -> float:
|
||||
return max(MINIMUM_FONT_SIZE, float(x))
|
||||
|
||||
|
||||
@@ -245,7 +250,7 @@ support, because it will force kitty to always treat the text as LTR, which
|
||||
FriBidi expects for terminals."""))
|
||||
|
||||
|
||||
def adjust_line_height(x):
|
||||
def adjust_line_height(x: str) -> Union[int, float]:
|
||||
if x.endswith('%'):
|
||||
ans = float(x[:-1].strip()) / 100.0
|
||||
if ans < 0:
|
||||
@@ -281,7 +286,7 @@ Syntax is::
|
||||
'''))
|
||||
|
||||
|
||||
def disable_ligatures(x):
|
||||
def disable_ligatures(x: str) -> int:
|
||||
cmap = {'never': 0, 'cursor': 1, 'always': 2}
|
||||
return cmap.get(x.lower(), 0)
|
||||
|
||||
@@ -345,11 +350,11 @@ You can do this with e.g.::
|
||||
'''))
|
||||
|
||||
|
||||
def box_drawing_scale(x):
|
||||
ans = tuple(float(x.strip()) for x in x.split(','))
|
||||
def box_drawing_scale(x: str) -> Tuple[float, float, float, float]:
|
||||
ans = tuple(float(q.strip()) for q in x.split(','))
|
||||
if len(ans) != 4:
|
||||
raise ValueError('Invalid box_drawing scale, must have four entries')
|
||||
return ans
|
||||
return ans[0], ans[1], ans[2], ans[3]
|
||||
|
||||
|
||||
o(
|
||||
@@ -374,7 +379,7 @@ cshapes = {
|
||||
}
|
||||
|
||||
|
||||
def to_cursor_shape(x):
|
||||
def to_cursor_shape(x: str) -> int:
|
||||
try:
|
||||
return cshapes[x.lower()]
|
||||
except KeyError:
|
||||
@@ -385,9 +390,9 @@ def to_cursor_shape(x):
|
||||
)
|
||||
|
||||
|
||||
def cursor_text_color(x):
|
||||
def cursor_text_color(x: str) -> Optional[Color]:
|
||||
if x.lower() == 'background':
|
||||
return
|
||||
return None
|
||||
return to_color(x)
|
||||
|
||||
|
||||
@@ -416,14 +421,14 @@ inactivity. Set to zero to never stop blinking.
|
||||
g('scrollback') # {{{
|
||||
|
||||
|
||||
def scrollback_lines(x):
|
||||
x = int(x)
|
||||
if x < 0:
|
||||
x = 2 ** 32 - 1
|
||||
return x
|
||||
def scrollback_lines(x: str) -> int:
|
||||
ans = int(x)
|
||||
if ans < 0:
|
||||
ans = 2 ** 32 - 1
|
||||
return ans
|
||||
|
||||
|
||||
def scrollback_pager_history_size(x):
|
||||
def scrollback_pager_history_size(x: str) -> int:
|
||||
ans = int(max(0, float(x)) * 1024 * 1024)
|
||||
return min(ans, 4096 * 1024 * 1024 - 1)
|
||||
|
||||
@@ -497,7 +502,7 @@ The special value :code:`default` means to use the
|
||||
operating system's default URL handler.'''))
|
||||
|
||||
|
||||
def copy_on_select(raw):
|
||||
def copy_on_select(raw: str) -> str:
|
||||
q = raw.lower()
|
||||
# boolean values special cased for backwards compat
|
||||
if q in ('y', 'yes', 'true', 'clipboard'):
|
||||
@@ -612,7 +617,7 @@ number of cells instead of pixels.
|
||||
'''))
|
||||
|
||||
|
||||
def window_size(val):
|
||||
def window_size(val: str) -> Tuple[int, str]:
|
||||
val = val.lower()
|
||||
unit = 'cells' if val.endswith('c') else 'px'
|
||||
return positive_int(val.rstrip('c')), unit
|
||||
@@ -622,9 +627,9 @@ o('initial_window_width', '640', option_type=window_size)
|
||||
o('initial_window_height', '400', option_type=window_size)
|
||||
|
||||
|
||||
def to_layout_names(raw):
|
||||
def to_layout_names(raw: str) -> List[str]:
|
||||
parts = [x.strip().lower() for x in raw.split(',')]
|
||||
ans = []
|
||||
ans: List[str] = []
|
||||
for p in parts:
|
||||
if p in ('*', 'all'):
|
||||
ans.extend(sorted(all_layouts))
|
||||
@@ -695,7 +700,7 @@ zero and one, with zero being fully faded).
|
||||
'''))
|
||||
|
||||
|
||||
def hide_window_decorations(x):
|
||||
def hide_window_decorations(x: str) -> int:
|
||||
if x == 'titlebar-only':
|
||||
return 0b10
|
||||
if to_bool(x):
|
||||
@@ -717,7 +722,7 @@ operating system sends events corresponding to the start and end
|
||||
of a resize, this number is ignored.'''))
|
||||
|
||||
|
||||
def resize_draw_strategy(x):
|
||||
def resize_draw_strategy(x: str) -> int:
|
||||
cmap = {'static': 0, 'scale': 1, 'blank': 2, 'size': 3}
|
||||
return cmap.get(x.lower(), 0)
|
||||
|
||||
@@ -743,7 +748,7 @@ g('tabbar') # {{{
|
||||
default_tab_separator = ' ┇'
|
||||
|
||||
|
||||
def tab_separator(x):
|
||||
def tab_separator(x: str) -> str:
|
||||
for q in '\'"':
|
||||
if x.startswith(q) and x.endswith(q):
|
||||
x = x[1:-1]
|
||||
@@ -753,11 +758,11 @@ def tab_separator(x):
|
||||
return x
|
||||
|
||||
|
||||
def tab_bar_edge(x):
|
||||
def tab_bar_edge(x: str) -> int:
|
||||
return {'top': 1, 'bottom': 3}.get(x.lower(), 3)
|
||||
|
||||
|
||||
def tab_font_style(x):
|
||||
def tab_font_style(x: str) -> Tuple[bool, bool]:
|
||||
return {
|
||||
'bold-italic': (True, True),
|
||||
'bold': (True, False),
|
||||
@@ -777,7 +782,12 @@ In the fade style, each tab's edges fade into the background color, in the separ
|
||||
separated by a configurable separator, and the powerline shows the tabs as a continuous line.
|
||||
'''))
|
||||
|
||||
o('tab_bar_min_tabs', 2, option_type=lambda x: max(1, positive_int(x)), long_text=_('''
|
||||
|
||||
def tab_bar_min_tabs(x: str) -> int:
|
||||
return max(1, positive_int(x))
|
||||
|
||||
|
||||
o('tab_bar_min_tabs', 2, option_type=tab_bar_min_tabs, long_text=_('''
|
||||
The minimum number of tabs that must exist before the tab bar is shown
|
||||
'''))
|
||||
|
||||
@@ -789,7 +799,7 @@ of :code:`last` will switch to the right-most tab.
|
||||
'''))
|
||||
|
||||
|
||||
def tab_fade(x):
|
||||
def tab_fade(x: str) -> Tuple[float, ...]:
|
||||
return tuple(map(unit_float, x.split()))
|
||||
|
||||
|
||||
@@ -805,7 +815,7 @@ o('tab_separator', '"{}"'.format(default_tab_separator), option_type=tab_separat
|
||||
The separator between tabs in the tab bar when using :code:`separator` as the :opt:`tab_bar_style`.'''))
|
||||
|
||||
|
||||
def tab_title_template(x):
|
||||
def tab_title_template(x: str) -> str:
|
||||
if x:
|
||||
for q in '\'"':
|
||||
if x.startswith(q) and x.endswith(q):
|
||||
@@ -814,7 +824,7 @@ def tab_title_template(x):
|
||||
return x
|
||||
|
||||
|
||||
def active_tab_title_template(x):
|
||||
def active_tab_title_template(x: str) -> Optional[str]:
|
||||
x = tab_title_template(x)
|
||||
return None if x == 'none' else x
|
||||
|
||||
@@ -865,9 +875,9 @@ default as it has a performance cost)
|
||||
'''))
|
||||
|
||||
|
||||
def config_or_absolute_path(x):
|
||||
def config_or_absolute_path(x: str) -> Optional[str]:
|
||||
if x.lower() == 'none':
|
||||
return
|
||||
return None
|
||||
x = os.path.expanduser(x)
|
||||
x = os.path.expandvars(x)
|
||||
if not os.path.isabs(x):
|
||||
@@ -903,9 +913,10 @@ How much to dim text that has the DIM/FAINT attribute set. One means no dimming
|
||||
zero means fully dimmed (i.e. invisible).'''))
|
||||
|
||||
|
||||
def selection_foreground(x):
|
||||
def selection_foreground(x: str) -> Optional[Color]:
|
||||
if x.lower() != 'none':
|
||||
return to_color(x)
|
||||
return None
|
||||
|
||||
|
||||
o('selection_foreground', '#000000', option_type=selection_foreground, long_text=_('''
|
||||
@@ -974,7 +985,7 @@ terminal can fail silently because their stdout/stderr/stdin no longer work.
|
||||
'''))
|
||||
|
||||
|
||||
def allow_remote_control(x):
|
||||
def allow_remote_control(x: str) -> str:
|
||||
if x != 'socket-only':
|
||||
x = 'y' if to_bool(x) else 'n'
|
||||
return x
|
||||
@@ -1020,7 +1031,12 @@ that relative paths are interpreted with respect to the kitty config directory.
|
||||
Environment variables in the path are expanded.
|
||||
'''))
|
||||
|
||||
o('clipboard_control', 'write-clipboard write-primary', option_type=lambda x: frozenset(x.lower().split()), long_text=_('''
|
||||
|
||||
def clipboard_control(x: str) -> FrozenSet[str]:
|
||||
return frozenset(x.lower().split())
|
||||
|
||||
|
||||
o('clipboard_control', 'write-clipboard write-primary', option_type=clipboard_control, long_text=_('''
|
||||
Allow programs running in kitty to read and write from the clipboard. You can
|
||||
control exactly which actions are allowed. The set of possible actions is:
|
||||
write-clipboard read-clipboard write-primary read-primary. You can
|
||||
@@ -1046,7 +1062,7 @@ key-presses, to colors, to various advanced features may not work.
|
||||
g('os') # {{{
|
||||
|
||||
|
||||
def macos_titlebar_color(x):
|
||||
def macos_titlebar_color(x: str) -> int:
|
||||
x = x.strip('"')
|
||||
if x == 'system':
|
||||
return 0
|
||||
@@ -1067,7 +1083,7 @@ probably better off just hiding the titlebar with :opt:`hide_window_decorations`
|
||||
'''))
|
||||
|
||||
|
||||
def macos_option_as_alt(x):
|
||||
def macos_option_as_alt(x: str) -> int:
|
||||
x = x.lower()
|
||||
if x == 'both':
|
||||
return 0b11
|
||||
|
||||
Reference in New Issue
Block a user