Skip to content

Commit

Permalink
An option to set TERMINFO to the database directly instead of a path
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Mar 21, 2024
1 parent ad64472 commit 198b69e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ rsync algorithm to speed up repeated transfers of large files.
Detailed list of changes
-------------------------------------

0.33.2 [future]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- A new option :opt:`terminfo_type` to allow passing the terminfo database embedded into the :envvar:`TERMINFO` env var directly instead of via a file

0.33.1 [2024-03-21]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ Variables that kitty sets when running child programs

.. envvar:: TERMINFO

Path to a directory containing the kitty terminfo database.
Path to a directory containing the kitty terminfo database. Or the terminfo
database itself encoded in base64. See :opt:`terminfo_type`.

.. envvar:: KITTY_INSTALLATION_DIR

Expand Down
14 changes: 11 additions & 3 deletions kitty/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def getpid() -> str:
return str(os.getpid())


@run_once
def base64_terminfo_data() -> str:
return (b'b64:' + fast_data_types.base64_encode(fast_data_types.terminfo_data(), True)).decode('ascii')


class ProcessDesc(TypedDict):
cwd: Optional[str]
pid: int
Expand Down Expand Up @@ -242,9 +247,12 @@ def get_final_env(self) -> Dict[str, str]:
# can use it to display the current directory name rather
# than the resolved path
env['PWD'] = self.cwd
tdir = checked_terminfo_dir()
if tdir:
env['TERMINFO'] = tdir
if opts.terminfo_type == 'path':
tdir = checked_terminfo_dir()
if tdir:
env['TERMINFO'] = tdir
elif opts.terminfo_type == 'direct':
env['TERMINFO'] = base64_terminfo_data()
env['KITTY_INSTALLATION_DIR'] = kitty_base_dir
if opts.forward_stdio:
env['KITTY_STDIO_FORWARDED'] = '3'
Expand Down
1 change: 1 addition & 0 deletions kitty/fast_data_types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1560,3 +1560,4 @@ def find_in_memoryview(buf: Union[bytes, memoryview, bytearray], chr: int) -> in
def replace_c0_codes_except_nl_space_tab(text: str) -> str:...
@overload
def replace_c0_codes_except_nl_space_tab(text: Union[bytes, memoryview, bytearray]) -> bytes:...
def terminfo_data() -> bytes:...
12 changes: 12 additions & 0 deletions kitty/options/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3221,6 +3221,18 @@
'''
)

opt('terminfo_type', 'path', choices=('path', 'direct', 'none'),
long_text='''
The value of the :envvar:`TERMINFO` environment variable to set. This variable is
used by programs running in the terminal to search for terminfo databases. The default value
of :code:`path` causes kitty to set it to a filesystem location containing the
kitty terminfo database. A value of :code:`direct` means put the entire database into
the env var directly. This can be useful when connecting to containers, for example. But,
note that not all software supports this. A value of :code:`none` means do not touch the variable.
'''
)


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
Expand Down
8 changes: 8 additions & 0 deletions kitty/options/parse.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions kitty/options/types.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 198b69e

Please sign in to comment.