Karana.KUtils.MultibodyTUI.terminal#

Functions#

bold(→ str)

Apply the bold effect

invert(→ str)

Swap background and foreground colors

critical(→ str)

Style the text for a critical error

error(→ str)

Style the text for an error

warn(→ str)

Style the text for a warning

info(→ str)

Style the text for important info

tui_mode([on_resume])

Context manager to configure the terminal for a TUI

normal_mode([on_resume])

Context manager to configure the terminal for regular input

clear_screen()

print_lines(lines)

print_with_pager(text)

Displays text in a pager, respecting the PAGER variable

poll_key(→ str)

Poll for a pending key press

Module Contents#

Karana.KUtils.MultibodyTUI.terminal.bold(text: str) str[source]#

Apply the bold effect

Parameters:

text (str) – The given text

Returns:

The bolded text

Return type:

str

Karana.KUtils.MultibodyTUI.terminal.invert(text: str) str[source]#

Swap background and foreground colors

Parameters:

text (str) – The given text

Returns:

The inverted text

Return type:

str

Karana.KUtils.MultibodyTUI.terminal.critical(text: str) str[source]#

Style the text for a critical error

Parameters:

text (str) – The given text

Returns:

The stylized text

Return type:

str

Karana.KUtils.MultibodyTUI.terminal.error(text: str) str[source]#

Style the text for an error

Parameters:

text (str) – The given text

Returns:

The stylized text

Return type:

str

Karana.KUtils.MultibodyTUI.terminal.warn(text: str) str[source]#

Style the text for a warning

Parameters:

text (str) – The given text

Returns:

The stylized text

Return type:

str

Karana.KUtils.MultibodyTUI.terminal.info(text: str) str[source]#

Style the text for important info

Parameters:

text (str) – The given text

Returns:

The stylized text

Return type:

str

Karana.KUtils.MultibodyTUI.terminal.tui_mode(on_resume: collections.abc.Callable | None = None)[source]#

Context manager to configure the terminal for a TUI

This primarily handles setting cbreak mode for immediate key handling and restoring the previous mode upon exiting the context. Multiple tui_mode contexts may be nested.

Parameters:

on_resume (collections.abc.Callable | None) – Optional callable triggered upon SIGCONT (eg when resuming from Ctrl-Z).

Karana.KUtils.MultibodyTUI.terminal.normal_mode(on_resume: collections.abc.Callable | None = None)[source]#

Context manager to configure the terminal for regular input

This can be used to return the terminal to regular interaction. This is could be used for example to return to normal behavior when entering a Python REPL from within a TUI.

Parameters:

on_resume (collections.abc.Callable | None) – Optional callable triggered upon SIGCONT (eg when resuming from Ctrl-Z).

Karana.KUtils.MultibodyTUI.terminal.clear_screen()[source]#
Karana.KUtils.MultibodyTUI.terminal.print_lines(lines: list[str])[source]#
Karana.KUtils.MultibodyTUI.terminal.print_with_pager(text: str)[source]#

Displays text in a pager, respecting the PAGER variable

Parameters:

text (str) – The text to display in the pager.

Karana.KUtils.MultibodyTUI.terminal.poll_key(timeout: float = 0.1) str[source]#

Poll for a pending key press

Parameters:

timeout (float) – Amount of time in seconds to wait for a key press

Returns:

The pressed key or the empty string if no key was pressed.

Return type:

str