Also get the current fg/bg colors to render text with

This commit is contained in:
Kovid Goyal
2024-05-08 08:40:30 +05:30
parent 5d74d210ee
commit 65b790df40
3 changed files with 58 additions and 16 deletions

View File

@@ -175,6 +175,41 @@ class DpiY(Query):
return f'{cf["logical_dpi_y"]:g}'
@query
class Foreground(Query):
name: str = 'foreground'
help_text: str = 'The current foreground color as a 24-bit # color code'
@staticmethod
def get_result(opts: Options, window_id: int, os_window_id: int) -> str:
from kitty.fast_data_types import Color, get_boss
boss = get_boss()
w = boss.window_id_map.get(window_id)
if w is None:
return opts.foreground.as_sharp
col = w.screen.color_profile.default_fg
r, g, b = col >> 16, (col >> 8) & 0xff, col & 0xff
return Color(r, g, b).as_sharp
@query
class Background(Query):
name: str = 'background'
help_text: str = 'The current background color as a 24-bit # color code'
@staticmethod
def get_result(opts: Options, window_id: int, os_window_id: int) -> str:
from kitty.fast_data_types import Color, get_boss
boss = get_boss()
w = boss.window_id_map.get(window_id)
if w is None:
return opts.background.as_sharp
col = w.screen.color_profile.default_bg
r, g, b = col >> 16, (col >> 8) & 0xff, col & 0xff
return Color(r, g, b).as_sharp
@query
class ClipboardControl(Query):
name: str = 'clipboard_control'