Karana.KUtils.MultibodyTUI.dialog
=================================

.. py:module:: Karana.KUtils.MultibodyTUI.dialog

.. autoapi-nested-parse::

   Classes for controlling dialog in TUIs.



Classes
-------

.. autoapisummary::

   Karana.KUtils.MultibodyTUI.dialog.EntryDialog
   Karana.KUtils.MultibodyTUI.dialog.SearchDialog
   Karana.KUtils.MultibodyTUI.dialog.FlagData
   Karana.KUtils.MultibodyTUI.dialog.FlagsTUI
   Karana.KUtils.MultibodyTUI.dialog.MenuEntry
   Karana.KUtils.MultibodyTUI.dialog.MenuTUI
   Karana.KUtils.MultibodyTUI.dialog.ChoiceData
   Karana.KUtils.MultibodyTUI.dialog.ChoiceTUI


Module Contents
---------------

.. py:class:: EntryDialog(prompt: list[str] | None = None, entry: str = '')

   Base class for a user text input TUI.


   .. py:attribute:: prompt
      :value: None



   .. py:attribute:: entry
      :value: ''



   .. py:method:: run() -> str | None

      Run the TUI.

      This blocks until the user entry is confirmed or canceled



   .. py:method:: isValid() -> bool

      Check if the user entered content is valid.

      :returns: Always returns True.
      :rtype: bool



   .. py:method:: footer() -> list[str]

      Return the footer message.

      :returns: The footer message.
      :rtype: list[str]



   .. py:method:: redraw()

      Redraw the TUI.



.. py:class:: SearchDialog(universe: list[str], prompt=list[str] | None)

   Bases: :py:obj:`EntryDialog`


   Dialog for searching.


   .. py:attribute:: universe


   .. py:method:: matches() -> list[str]

      Return a list of matches.

      :returns: A list of matches from the users search.
      :rtype: list[str]



   .. py:method:: isValid() -> bool

      Check if matches were found.

      :returns: True if matches were found, False otherwise.
      :rtype: bool



   .. py:method:: boldMatch(string: str, substr: str) -> str
      :staticmethod:


      Make part of a string bold.

      :param string: The full string.
      :type string: str
      :param substr: The substring to make bold.
      :type substr: str

      :returns: A string with the substr bolded.
      :rtype: str



   .. py:method:: footer() -> list[str]

      Return the footer message.

      :returns: The footer message.
      :rtype: list[str]



.. py:class:: FlagData

   Simple class to track the value of a flag.


   .. py:attribute:: brief
      :type:  str


   .. py:attribute:: enabled
      :type:  bool


   .. py:method:: toggle()

      Toggle the flag.



   .. py:method:: __bool__()

      Return true if the flag is true.

      :returns: True if the flag is True, False otherwise.
      :rtype: bool



.. py:class:: FlagsTUI(header: list[str], flags: list[FlagData])

   Bases: :py:obj:`Karana.KUtils.MultibodyTUI.base.TUIBase`


   TUI for controlling a set of flags.


   .. py:property:: confirmed

      Return true if confirmed.

      :returns: True if confirmed, False otherwise.
      :rtype: bool


   .. py:method:: redraw()

      Redraw the TUI.



   .. py:method:: handleKey(key)

      Handle user key presses.

      :param key: The key pressed.

      :returns: True to continue with this TUI, False to exit.
      :rtype: bool



.. py:class:: MenuEntry

   Class with data needed for a TUI menu.


   .. py:attribute:: brief
      :type:  str


   .. py:attribute:: callback
      :type:  collections.abc.Callable | None
      :value: None



   .. py:attribute:: description
      :type:  str
      :value: ''



   .. py:attribute:: done
      :type:  bool
      :value: False



.. py:class:: MenuTUI(header: list[str], entries: list[MenuEntry], index: int = 0)

   Bases: :py:obj:`Karana.KUtils.MultibodyTUI.base.TUIBase`


   TUI for a menu.


   .. py:method:: redraw()

      Redraw the TUI.



   .. py:method:: footer() -> list[str]

      Return footer message.

      :returns: The footer message.
      :rtype: list[str]



   .. py:property:: current
      :type: MenuEntry


      Return the current menu item.

      :returns: The current menu item.
      :rtype: MenuEntry


   .. py:method:: handleKey(key)

      Handle user key presses.

      :param key: The key the user pressed.

      :returns: True if we should stay in the TUI, False to exit.
      :rtype: bool



.. py:class:: ChoiceData

   Data associated with a ChoiceTUI.


   .. py:attribute:: brief
      :type:  str


   .. py:attribute:: value
      :type:  Any


   .. py:attribute:: description
      :type:  str
      :value: ''



.. py:class:: ChoiceTUI(header: list[str], choices: list[ChoiceData], index: int = 0)

   Bases: :py:obj:`Karana.KUtils.MultibodyTUI.base.TUIBase`


   A TUI for controlling choices.


   .. py:property:: choice
      :type: ChoiceData | None


      The currently selected choice.

      :returns: The currently selected choice.
      :rtype: ChoiceData | None


   .. py:method:: redraw()

      Redraw the TUI.



   .. py:method:: handleKey(key)

      Handle user key presses.

      :param key: The key pressed.

      :returns: True to continue with this TUI, False to exit.
      :rtype: bool



