A facility to easily have child programs print to kitty stdout

Works better than the kitty-print DCS escape code as that tends to get
interleaved with other writes to the tty since the loop infrastructure
writes in a separate I/O thread.
This commit is contained in:
Kovid Goyal
2023-07-21 13:02:14 +05:30
parent eecf24b986
commit 59b47a3a8f
8 changed files with 44 additions and 13 deletions

View File

@@ -3082,6 +3082,16 @@ work. Changing this option by reloading the config will only affect newly
created windows.
'''
)
opt('forward_stdio', 'no', option_type='to_bool', long_text='''
Forward STDOUT and STDERR of the kitty process to child processes
as file descriptors 3 and 4. This is useful for debugging as it
allows child processes to print to kitty's STDOUT directly. For example,
:code:`echo hello world >&3` in a shell will print to the parent kitty's
STDOUT. When enabled, this also sets the :code:`KITTY_STDIO_FORWARDED=3`
environment variable so child processes know about the forwarding.
''')
egr() # }}}

View File

@@ -990,6 +990,9 @@ class Parser:
def foreground(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['foreground'] = to_color(val)
def forward_stdio(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['forward_stdio'] = to_bool(val)
def hide_window_decorations(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['hide_window_decorations'] = hide_window_decorations(val)

View File

@@ -365,6 +365,7 @@ option_names = ( # {{{
'font_size',
'force_ltr',
'foreground',
'forward_stdio',
'hide_window_decorations',
'inactive_border_color',
'inactive_tab_background',
@@ -526,6 +527,7 @@ class Options:
font_size: float = 11.0
force_ltr: bool = False
foreground: Color = Color(221, 221, 221)
forward_stdio: bool = False
hide_window_decorations: int = 0
inactive_border_color: Color = Color(204, 204, 204)
inactive_tab_background: Color = Color(153, 153, 153)