query terminal kitten: Allow querying font face and size information
Fixes #3756
This commit is contained in:
parent
890a149a5d
commit
e337fcaadc
@ -35,6 +35,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
|||||||
|
|
||||||
- Linux: Fix Emoji/bitmapped fonts not use able in symbol_map
|
- Linux: Fix Emoji/bitmapped fonts not use able in symbol_map
|
||||||
|
|
||||||
|
- query terminal kitten: Allow querying font face and size information
|
||||||
|
(:iss:`3756`)
|
||||||
|
|
||||||
|
|
||||||
0.21.1 [2021-06-14]
|
0.21.1 [2021-06-14]
|
||||||
----------------------
|
----------------------
|
||||||
|
|||||||
@ -19,8 +19,12 @@ from kitty.utils import TTYIO
|
|||||||
class Query:
|
class Query:
|
||||||
name: str = ''
|
name: str = ''
|
||||||
ans: str = ''
|
ans: str = ''
|
||||||
query_name: str = ''
|
|
||||||
help_text: str = ''
|
help_text: str = ''
|
||||||
|
override_query_name: str = ''
|
||||||
|
|
||||||
|
@property
|
||||||
|
def query_name(self) -> str:
|
||||||
|
return self.override_query_name or f'kitty-query-{self.name}'
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.encoded_query_name = hexlify(self.query_name.encode('utf-8')).decode('ascii')
|
self.encoded_query_name = hexlify(self.query_name.encode('utf-8')).decode('ascii')
|
||||||
@ -62,7 +66,7 @@ def query(cls: Type[Query]) -> Type[Query]:
|
|||||||
@query
|
@query
|
||||||
class TerminalName(Query):
|
class TerminalName(Query):
|
||||||
name: str = 'name'
|
name: str = 'name'
|
||||||
query_name: str = 'TN'
|
override_query_name: str = 'name'
|
||||||
help_text: str = f'Terminal name ({names[0]})'
|
help_text: str = f'Terminal name ({names[0]})'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -73,7 +77,6 @@ class TerminalName(Query):
|
|||||||
@query
|
@query
|
||||||
class TerminalVersion(Query):
|
class TerminalVersion(Query):
|
||||||
name: str = 'version'
|
name: str = 'version'
|
||||||
query_name: str = 'kitty-query-version'
|
|
||||||
help_text: str = 'Terminal version, for e.g.: 0.19.2'
|
help_text: str = 'Terminal version, for e.g.: 0.19.2'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -84,7 +87,6 @@ class TerminalVersion(Query):
|
|||||||
@query
|
@query
|
||||||
class AllowHyperlinks(Query):
|
class AllowHyperlinks(Query):
|
||||||
name: str = 'allow_hyperlinks'
|
name: str = 'allow_hyperlinks'
|
||||||
query_name: str = 'kitty-query-allow_hyperlinks'
|
|
||||||
help_text: str = 'yes, no or ask'
|
help_text: str = 'yes, no or ask'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -92,6 +94,64 @@ class AllowHyperlinks(Query):
|
|||||||
return 'ask' if opts.allow_hyperlinks == 0b11 else ('yes' if opts.allow_hyperlinks else 'no')
|
return 'ask' if opts.allow_hyperlinks == 0b11 else ('yes' if opts.allow_hyperlinks else 'no')
|
||||||
|
|
||||||
|
|
||||||
|
@query
|
||||||
|
class FontFamily(Query):
|
||||||
|
name: str = 'font_family'
|
||||||
|
help_text: str = 'The current font\'s PostScript name'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_result(opts: Options) -> str:
|
||||||
|
from kitty.fast_data_types import current_fonts
|
||||||
|
cf = current_fonts()
|
||||||
|
return str(cf['medium'].display_name())
|
||||||
|
|
||||||
|
|
||||||
|
@query
|
||||||
|
class BoldFont(Query):
|
||||||
|
name: str = 'bold_font'
|
||||||
|
help_text: str = 'The current bold font\'s PostScript name'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_result(opts: Options) -> str:
|
||||||
|
from kitty.fast_data_types import current_fonts
|
||||||
|
cf = current_fonts()
|
||||||
|
return str(cf['bold'].display_name())
|
||||||
|
|
||||||
|
|
||||||
|
@query
|
||||||
|
class ItalicFont(Query):
|
||||||
|
name: str = 'italic_font'
|
||||||
|
help_text: str = 'The current italic font\'s PostScript name'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_result(opts: Options) -> str:
|
||||||
|
from kitty.fast_data_types import current_fonts
|
||||||
|
cf = current_fonts()
|
||||||
|
return str(cf['italic'].display_name())
|
||||||
|
|
||||||
|
|
||||||
|
@query
|
||||||
|
class BiFont(Query):
|
||||||
|
name: str = 'bold_italic_font'
|
||||||
|
help_text: str = 'The current bold-italic font\'s PostScript name'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_result(opts: Options) -> str:
|
||||||
|
from kitty.fast_data_types import current_fonts
|
||||||
|
cf = current_fonts()
|
||||||
|
return str(cf['bi'].display_name())
|
||||||
|
|
||||||
|
|
||||||
|
@query
|
||||||
|
class FontSize(Query):
|
||||||
|
name: str = 'font_size'
|
||||||
|
help_text: str = 'The current overall font size (individual windows can have different per window font sizes)'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_result(opts: Options) -> str:
|
||||||
|
return f'{opts.font_size:g}'
|
||||||
|
|
||||||
|
|
||||||
def get_result(name: str) -> Optional[str]:
|
def get_result(name: str) -> Optional[str]:
|
||||||
from kitty.fast_data_types import get_options
|
from kitty.fast_data_types import get_options
|
||||||
q = all_queries.get(name)
|
q = all_queries.get(name)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user