Karana.KUtils.MultibodyTUI.dialog#

Classes for controlling dialog in TUIs.

Classes#

EntryDialog

Base class for a user text input TUI.

SearchDialog

Dialog for searching.

FlagData

Simple class to track the value of a flag.

FlagsTUI

TUI for controlling a set of flags.

MenuEntry

Class with data needed for a TUI menu.

MenuTUI

TUI for a menu.

ChoiceData

Data associated with a ChoiceTUI.

ChoiceTUI

A TUI for controlling choices.

Module Contents#

class Karana.KUtils.MultibodyTUI.dialog.EntryDialog(prompt: list[str] | None = None, entry: str = '')[source]#

Base class for a user text input TUI.

prompt = None#
entry = ''#
run() str | None[source]#

Run the TUI.

This blocks until the user entry is confirmed or canceled

isValid() bool[source]#

Check if the user entered content is valid.

Returns:

Always returns True.

Return type:

bool

footer() list[str][source]#

Return the footer message.

Returns:

The footer message.

Return type:

list[str]

redraw()[source]#

Redraw the TUI.

class Karana.KUtils.MultibodyTUI.dialog.SearchDialog(universe: list[str], prompt=list[str] | None)[source]#

Bases: EntryDialog

Dialog for searching.

universe#
matches() list[str][source]#

Return a list of matches.

Returns:

A list of matches from the users search.

Return type:

list[str]

isValid() bool[source]#

Check if matches were found.

Returns:

True if matches were found, False otherwise.

Return type:

bool

static boldMatch(string: str, substr: str) str[source]#

Make part of a string bold.

Parameters:
  • string (str) – The full string.

  • substr (str) – The substring to make bold.

Returns:

A string with the substr bolded.

Return type:

str

footer() list[str][source]#

Return the footer message.

Returns:

The footer message.

Return type:

list[str]

class Karana.KUtils.MultibodyTUI.dialog.FlagData[source]#

Simple class to track the value of a flag.

brief: str#
enabled: bool#
toggle()[source]#

Toggle the flag.

__bool__()[source]#

Return true if the flag is true.

Returns:

True if the flag is True, False otherwise.

Return type:

bool

class Karana.KUtils.MultibodyTUI.dialog.FlagsTUI(header: list[str], flags: list[FlagData])[source]#

Bases: Karana.KUtils.MultibodyTUI.base.TUIBase

TUI for controlling a set of flags.

property confirmed#

Return true if confirmed.

Returns:

True if confirmed, False otherwise.

Return type:

bool

redraw()[source]#

Redraw the TUI.

handleKey(key)[source]#

Handle user key presses.

Parameters:

key – The key pressed.

Returns:

True to continue with this TUI, False to exit.

Return type:

bool

class Karana.KUtils.MultibodyTUI.dialog.MenuEntry[source]#

Class with data needed for a TUI menu.

brief: str#
callback: collections.abc.Callable | None = None#
description: str = ''#
done: bool = False#
class Karana.KUtils.MultibodyTUI.dialog.MenuTUI(header: list[str], entries: list[MenuEntry], index: int = 0)[source]#

Bases: Karana.KUtils.MultibodyTUI.base.TUIBase

TUI for a menu.

redraw()[source]#

Redraw the TUI.

footer() list[str][source]#

Return footer message.

Returns:

The footer message.

Return type:

list[str]

property current: MenuEntry#

Return the current menu item.

Returns:

The current menu item.

Return type:

MenuEntry

handleKey(key)[source]#

Handle user key presses.

Parameters:

key – The key the user pressed.

Returns:

True if we should stay in the TUI, False to exit.

Return type:

bool

class Karana.KUtils.MultibodyTUI.dialog.ChoiceData[source]#

Data associated with a ChoiceTUI.

brief: str#
value: Any#
description: str = ''#
class Karana.KUtils.MultibodyTUI.dialog.ChoiceTUI(header: list[str], choices: list[ChoiceData], index: int = 0)[source]#

Bases: Karana.KUtils.MultibodyTUI.base.TUIBase

A TUI for controlling choices.

property choice: ChoiceData | None#

The currently selected choice.

Returns:

The currently selected choice.

Return type:

ChoiceData | None

redraw()[source]#

Redraw the TUI.

handleKey(key)[source]#

Handle user key presses.

Parameters:

key – The key pressed.

Returns:

True to continue with this TUI, False to exit.

Return type:

bool