diff options
author | kotfu <kotfu@kotfu.net> | 2019-11-29 16:11:34 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2019-11-29 16:11:34 -0700 |
commit | 51851b8aa0d685b039a066a3b8efe88aa05b6113 (patch) | |
tree | 7e59a0f716456deeb672ba90e0a239f1e906209b /cmd2/rl_utils.py | |
parent | 6102c0aa1b463b4653bf9d0e84fd0a6558fba5f1 (diff) | |
parent | ee735ed2a5a9e8d6d6fa6827a698c9d5630f0029 (diff) | |
download | cmd2-git-51851b8aa0d685b039a066a3b8efe88aa05b6113.tar.gz |
Merge branch 'master' into generating_output_docs
Diffstat (limited to 'cmd2/rl_utils.py')
-rw-r--r-- | cmd2/rl_utils.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py index 7f47db79..9a23cbcd 100644 --- a/cmd2/rl_utils.py +++ b/cmd2/rl_utils.py @@ -32,6 +32,9 @@ rl_type = RlType.NONE # Tells if the terminal we are running in supports vt100 control characters vt100_support = False +# Explanation for why readline wasn't loaded +_rl_warn_reason = '' + # The order of this check matters since importing pyreadline will also show readline in the modules list if 'pyreadline' in sys.modules: rl_type = RlType.PYREADLINE @@ -113,15 +116,26 @@ if 'pyreadline' in sys.modules: elif 'gnureadline' in sys.modules or 'readline' in sys.modules: # We don't support libedit if 'libedit' not in readline.__doc__: - rl_type = RlType.GNU - - # Load the readline lib so we can access members of it - import ctypes - readline_lib = ctypes.CDLL(readline.__file__) - - # Check if we are running in a terminal - if sys.stdout.isatty(): - vt100_support = True + try: + # Load the readline lib so we can access members of it + import ctypes + readline_lib = ctypes.CDLL(readline.__file__) + except AttributeError: # pragma: no cover + _rl_warn_reason = ("this application is running in a non-standard Python environment in\n" + "which readline is not loaded dynamically from a shared library file.") + else: + rl_type = RlType.GNU + vt100_support = sys.stdout.isatty() + +# Check if readline was loaded +if rl_type == RlType.NONE: # pragma: no cover + if not _rl_warn_reason: + _rl_warn_reason = ("no supported version of readline was found. To resolve this, install\n" + "pyreadline on Windows or gnureadline on Mac.") + rl_warning = ("Readline features including tab completion have been disabled because\n" + + _rl_warn_reason + '\n\n') +else: + rl_warning = '' # noinspection PyProtectedMember,PyUnresolvedReferences |