Karana.KUtils.MultibodyTUI.terminal#

Functions for controlling the text in the 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.

tuiMode([on_resume])

Context manager to configure the terminal for a TUI.

normalMode([on_resume])

Context manager to configure the terminal for regular input.

clearScreen()

Clear screen and move cursor to top-left.

printLines(lines)

Print the provided lines in the terminal.

printWithPager(text)

Display text in a pager, respecting the PAGER variable.

pollKey(→ 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.tuiMode(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 tuiMode 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.normalMode(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.clearScreen()[source]#

Clear screen and move cursor to top-left.

Karana.KUtils.MultibodyTUI.terminal.printLines(lines: list[str])[source]#

Print the provided lines in the terminal.

Parameters:

lines (list[str]) – The lines to print.

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

Display text in a pager, respecting the PAGER variable.

Parameters:

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

Karana.KUtils.MultibodyTUI.terminal.pollKey(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