mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 05:24:20 +02:00
Move type parsers for config into own module
This commit is contained in:
@@ -7,7 +7,7 @@ import re
|
||||
import shlex
|
||||
from typing import (
|
||||
Any, Callable, Dict, FrozenSet, Generator, Iterable, Iterator, List,
|
||||
NamedTuple, Optional, Sequence, Tuple, Type, TypeVar, Union
|
||||
NamedTuple, Optional, Sequence, Tuple, Type, TypeVar, Union, Set
|
||||
)
|
||||
|
||||
from ..rgb import Color, to_color as as_color
|
||||
@@ -24,6 +24,14 @@ class BadLine(NamedTuple):
|
||||
exception: Exception
|
||||
|
||||
|
||||
def positive_int(x: ConvertibleToNumbers) -> int:
|
||||
return max(0, int(x))
|
||||
|
||||
|
||||
def positive_float(x: ConvertibleToNumbers) -> float:
|
||||
return max(0, float(x))
|
||||
|
||||
|
||||
def to_color(x: str) -> Color:
|
||||
ans = as_color(x, validate=True)
|
||||
if ans is None: # this is only for type-checking
|
||||
@@ -342,3 +350,9 @@ def parse_kittens_key(
|
||||
return None
|
||||
ans = parse_kittens_func_args(action, funcs_with_args)
|
||||
return ans, parse_shortcut(sc)
|
||||
|
||||
|
||||
def uniq(vals: Iterable[T]) -> List[T]:
|
||||
seen: Set[T] = set()
|
||||
seen_add = seen.add
|
||||
return [x for x in vals if x not in seen and not seen_add(x)]
|
||||
|
||||
Reference in New Issue
Block a user