diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-14 21:13:46 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-14 21:13:46 -0400 |
commit | cfcff77bf47910e4c5aaaad8fa33f181281f94ee (patch) | |
tree | 737327a32df4a21bb827512edd12d8343868ccd0 /cmd2/utils.py | |
parent | 88d8b57221662b42cfcd7490314c2869c4ea9bfe (diff) | |
download | cmd2-git-cfcff77bf47910e4c5aaaad8fa33f181281f94ee.tar.gz |
Converted dynamic class attributes to instance attributes
The following attritubes which are intended to be dynamically settable at runtime are now instance attributes:
- colors
- continuation_prompt
- debug
- echo
- editor
- feedback_to_output
- locals_in_py
- quiet
- timing
- settable
Also:
- Moved code for finding a default editor to a function in utils and set a new DEFAULT_EDITOR class attribute with the return value of that
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index c43ff62a..f3c29227 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -5,6 +5,7 @@ import collections import os import re +import sys import unicodedata from typing import Any, Iterable, List, Optional, Union @@ -351,3 +352,17 @@ def unquote_redirection_tokens(args: List[str]) -> None: unquoted_arg = strip_quotes(arg) if unquoted_arg in constants.REDIRECTION_TOKENS: args[i] = unquoted_arg + + +def find_editor() -> str: + """Find a reasonable editor to use by default for the system that the cmd2 application is running on.""" + editor = os.environ.get('EDITOR') + if not editor: + if sys.platform[:3] == 'win': + editor = 'notepad' + else: + # Favor command-line editors first so we don't leave the terminal to edit + for editor in ['vim', 'vi', 'emacs', 'nano', 'pico', 'gedit', 'kate', 'subl', 'geany', 'atom']: + if which(editor): + break + return editor |