khard.helpers.interactive¶
Helper functions for user interaction.
Module Contents¶
Classes¶
Generic enumeration. |
|
Wrapper around subprocess.Popen to edit and merge files. |
Functions¶
|
Ask the user for confirmation on the terminal. |
|
Ask the user to select an item from a list. |
Attributes¶
- khard.helpers.interactive.T¶
- khard.helpers.interactive.confirm(message: str, accept_enter_key: bool = True) bool¶
Ask the user for confirmation on the terminal.
- Parameters:
message – the question to print
accept_enter_key – Accept ENTER as alternative for “n”
- Returns:
the answer of the user
- khard.helpers.interactive.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.
- Parameters:
items – the list from which to select
include_none – whether to allow the selection of no item
- Returns:
None or the selected item
- class khard.helpers.interactive.EditState¶
Bases:
enum.EnumGeneric enumeration.
Derive from this class to define new enumerations.
- modified = 1¶
- unmodified = 2¶
- aborted = 3¶
- class khard.helpers.interactive.Editor(editor: Union[str, List[str]], merge_editor: Union[str, List[str]])¶
Wrapper around subprocess.Popen to edit and merge files.
- static write_temp_file(text: str = '') Generator[str, None, None]¶
Create a new temporary file and write some initial text to it.
- Parameters:
text – the text to write to the temp file
- Returns:
the file name of the newly created temp file
- static _mtime(filename: str) datetime.datetime¶
- 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.
- Parameters:
file1 – the first file (checked for modification if file2 not present)
file2 – the second file (checked for modification of present)
- Returns:
the result of the modification
- 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
- Parameters:
yaml2card – a function to convert the modified YAML templates into a CarddavObject
template1 – the first template
template2 – the second template (optional, for merges)
- Returns:
the parsed CarddavObject or None