From d7207edf2b1076ddd7b1bf82a7ba15da474d7bf2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Jan 2025 11:54:06 +0530 Subject: [PATCH] DRYer --- kittens/query_terminal/main.py | 8 ++++---- kitty/conf/utils.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kittens/query_terminal/main.py b/kittens/query_terminal/main.py index 532c13522..db56e0134 100644 --- a/kittens/query_terminal/main.py +++ b/kittens/query_terminal/main.py @@ -5,8 +5,9 @@ import sys from binascii import hexlify, unhexlify from contextlib import suppress -from typing import Dict, Literal, Optional, Type +from typing import Dict, Optional, Type, get_args +from kitty.conf.utils import OSNames, os_name from kitty.constants import appname, str_version from kitty.options.types import Options from kitty.terminfo import names @@ -229,11 +230,10 @@ def get_result(opts: Options, window_id: int, os_window_id: int) -> str: @query class OSName(Query): name: str = 'os_name' - help_text: str = 'The name of the OS the terminal is running on. Kitty supports values: linux, macos, bsd or unknown' + help_text: str = f'The name of the OS the terminal is running on. Kitty returns values: {", ".join(sorted(get_args(OSNames)))}' @staticmethod - def get_result(opts: Options, window_id: int, os_window_id: int) -> Literal['macos', 'bsd', 'linux', 'unknown']: - from kitty.conf.utils import os_name + def get_result(opts: Options, window_id: int, os_window_id: int) -> OSNames: return os_name() diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index c68ea0194..773b53790 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -176,10 +176,10 @@ def set_file(self, file: str) -> Iterator['CurrentlyParsing']: currently_parsing = CurrentlyParsing() - +OSNames = Literal['macos', 'bsd', 'linux', 'unknown'] @run_once -def os_name() -> Literal['macos', 'bsd', 'linux', 'unknown']: +def os_name() -> OSNames: if is_macos: return 'macos' if 'bsd' in _plat: