![]() |
Belle II Software development
|
Public Member Functions | |
| __init__ (self, str editor_command=None, str initial_content=None, str commentlines_start_with="#") | |
| input (self) | |
| get_editor_command (self) | |
Public Attributes | |
| editor_command_list = shlex.split(editor_command_string, posix=True) | |
| command line for the editor, split to separate executable name command line arguments | |
| initial_content = initial_content | |
| initial content of the editor window | |
| comment_string = commentlines_start_with | |
| string which starts comments in the file | |
Protected Member Functions | |
| _remove_comment_lines (self, a_string) | |
| _default_environment_editor (self) | |
| _prompt_for_editor (self) | |
Class to get user input via opening a temporary file in a text editor.
It is an alternative to the python commands ``input()`` or ``sys.stdin.readlines`` and is
similar to the behaviour of ``git commit`` for editing commit messages. By using an editor
instead of the command line, the user is motivated to give expressive multi-line input,
leveraging the full text editing capabilities of his editor. This function cannot be used for
example in interactive terminal scripts, whenever detailed user input is required.
Heavily inspired by the code in this blog post:
https://chase-seibert.github.io/blog/2012/10/31/python-fork-exec-vim-raw-input.html
Parameters:
editor_command: Editor to open for user input. If ``None``, get
default editor from environment variables. It should be the name
of a shell executable and can contain command line arguments.
initial_content: Initial string to insert into the temporary file that
is opened for user input. Can be used for default input or to
insert comment lines with instructions.
commentlines_start_with: Optionally define string with which comment
lines start
Definition at line 316 of file terminal_utils.py.
| __init__ | ( | self, | |
| str | editor_command = None, | ||
| str | initial_content = None, | ||
| str | commentlines_start_with = "#" ) |
Constructor
Definition at line 340 of file terminal_utils.py.
|
protected |
Return editor from environment variables. If not existing, return vi(m) as default.
Definition at line 396 of file terminal_utils.py.
|
protected |
Ask user to provide editor command
Definition at line 404 of file terminal_utils.py.
|
protected |
Remove lines from string that start with a comment character and return modified version.
Definition at line 386 of file terminal_utils.py.
| get_editor_command | ( | self | ) |
Get editor shell command string used for user input.
Definition at line 381 of file terminal_utils.py.
| input | ( | self | ) |
Get user input via editing a temporary file in an editor. If opening the editor fails, fall back to command line input
Definition at line 358 of file terminal_utils.py.
| comment_string = commentlines_start_with |
string which starts comments in the file
Definition at line 356 of file terminal_utils.py.
| editor_command_list = shlex.split(editor_command_string, posix=True) |
command line for the editor, split to separate executable name command line arguments
Definition at line 348 of file terminal_utils.py.
| initial_content = initial_content |
initial content of the editor window
Definition at line 354 of file terminal_utils.py.