query_terminal: Add support for reporting name of the OS the terminal emulator is running on

Fixes #8201
This commit is contained in:
Kovid Goyal
2025-01-07 08:21:53 +05:30
parent a3d6bf7a2c
commit 69aead6d3d
3 changed files with 16 additions and 2 deletions

View File

@@ -87,7 +87,7 @@ Detailed list of changes
0.39.0 [future]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- diff kitten: Automatically use dark/light color scheme based on the color scheme of the parent terminal. Can be controlled via the new :opt:`kitten-diff.color_scheme` option. Note that this is a **default behavior change** (:iss:`8170`)
- :doc:`diff kitten <kittens/diff>`: Automatically use dark/light color scheme based on the color scheme of the parent terminal. Can be controlled via the new :opt:`kitten-diff.color_scheme` option. Note that this is a **default behavior change** (:iss:`8170`)
- Allow dynamically generating configuration by running an arbitrary program using the new :code:`geninclude` directive in :file:`kitty.conf`
@@ -101,6 +101,8 @@ Detailed list of changes
- diff kitten: Abort when run inside a terminal that does not support the kitty keyboard protocol (:iss:`8185`)
- :doc:`query kitten <kittens/query_terminal>`: Add support for reporting name of the OS the terminal emulator is running on (:iss:`8201`)
- macOS: Allow using the Passwords app to autofill passwords via the Edit->Autofill menu mimicking other macOS applications (:pull:`8195`)
- macOS: Add menu items to the Edit menu to clear the screen and scrollback

View File

@@ -226,6 +226,17 @@ class ClipboardControl(Query):
return ' '.join(opts.clipboard_control)
@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'
@staticmethod
def get_result(opts: Options, window_id: int, os_window_id: int) -> str:
from kitty.conf.utils import os_name
return os_name()
def get_result(name: str, window_id: int, os_window_id: int) -> Optional[str]:
from kitty.fast_data_types import get_options
q = all_queries.get(name)

View File

@@ -14,6 +14,7 @@ from typing import (
Iterable,
Iterator,
List,
Literal,
NamedTuple,
Optional,
Sequence,
@@ -178,7 +179,7 @@ currently_parsing = CurrentlyParsing()
@run_once
def os_name() -> str:
def os_name() -> Literal['macos', 'bsd', 'linux', 'unknown']:
if is_macos:
return 'macos'
if 'bsd' in _plat: