:py:mod:`khard.helpers.interactive`
===================================

.. py:module:: khard.helpers.interactive

.. autoapi-nested-parse::

   Helper functions for user interaction.



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

Classes
~~~~~~~

.. autoapisummary::

   khard.helpers.interactive.EditState
   khard.helpers.interactive.Editor



Functions
~~~~~~~~~

.. autoapisummary::

   khard.helpers.interactive.confirm
   khard.helpers.interactive.select



Attributes
~~~~~~~~~~

.. autoapisummary::

   khard.helpers.interactive.T


.. py:data:: T
   

   

.. py:function:: confirm(message: str, accept_enter_key: bool = True) -> bool

   Ask the user for confirmation on the terminal.

   :param message: the question to print
   :param accept_enter_key: Accept ENTER as alternative for "n"
   :returns: the answer of the user


.. py:function:: select(items: List[T], include_none: bool = False) -> Optional[T]

   Ask the user to select an item from a list.

   The list should be displayed to the user before calling this function and
   should be indexed starting with 1.

   :param items: the list from which to select
   :param include_none: whether to allow the selection of no item
   :returns: None or the selected item


.. py:class:: EditState

   Bases: :py:obj:`enum.Enum`

   Generic enumeration.

   Derive from this class to define new enumerations.

   .. py:attribute:: modified
      :annotation: = 1

      

   .. py:attribute:: unmodified
      :annotation: = 2

      

   .. py:attribute:: aborted
      :annotation: = 3

      


.. py:class:: Editor(editor: Union[str, List[str]], merge_editor: Union[str, List[str]])

   Wrapper around subprocess.Popen to edit and merge files.

   .. py:method:: write_temp_file(text: str = '') -> Generator[str, None, None]
      :staticmethod:

      Create a new temporary file and write some initial text to it.

      :param text: the text to write to the temp file
      :returns: the file name of the newly created temp file


   .. py:method:: _mtime(filename: str) -> datetime.datetime
      :staticmethod:


   .. py:method:: edit_files(file1: str, file2: Optional[str] = None) -> EditState

      Edit the given files

      If only one file is given the timestamp of this file is checked, if two
      files are given the timestamp of the second file is checked for
      modification.

      :param file1: the first file (checked for modification if file2 not
          present)
      :param file2: the second file (checked for modification of present)
      :returns: the result of the modification


   .. py:method:: edit_templates(yaml2card: Callable[[str], khard.carddav_object.CarddavObject], template1: str, template2: Optional[str] = None) -> Optional[khard.carddav_object.CarddavObject]

      Edit YAML templates of contacts and parse them back

      :param yaml2card: a function to convert the modified YAML templates
          into a CarddavObject
      :param template1: the first template
      :param template2: the second template (optional, for merges)
      :returns: the parsed CarddavObject or None



