summaryrefslogtreecommitdiff
path: root/cmd2/rl_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/rl_utils.py')
-rw-r--r--cmd2/rl_utils.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py
index 099d76b7..aacd93cb 100644
--- a/cmd2/rl_utils.py
+++ b/cmd2/rl_utils.py
@@ -21,6 +21,7 @@ except ImportError:
class RlType(Enum):
"""Readline library types we recognize"""
+
GNU = 1
PYREADLINE = 2
NONE = 3
@@ -39,9 +40,9 @@ _rl_warn_reason = ''
if 'pyreadline' in sys.modules:
rl_type = RlType.PYREADLINE
+ import atexit
from ctypes import byref
from ctypes.wintypes import DWORD, HANDLE
- import atexit
# Check if we are running in a terminal
if sys.stdout.isatty(): # pragma: no cover
@@ -105,7 +106,7 @@ if 'pyreadline' in sys.modules:
saved_cursor = readline.rl.mode._history.history_cursor
# Delete the history item
- del(readline.rl.mode._history.history[pos])
+ del readline.rl.mode._history.history[pos]
# Update the cursor if needed
if saved_cursor > pos:
@@ -119,10 +120,13 @@ elif 'gnureadline' in sys.modules or 'readline' in sys.modules:
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.")
+ _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()
@@ -130,10 +134,11 @@ elif 'gnureadline' in sys.modules or 'readline' in sys.modules:
# 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')
+ _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 = ''