summaryrefslogtreecommitdiff
path: root/cmd2/rl_utils.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-05-23 03:07:23 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-05-23 03:07:23 -0400
commit4ce81a71de2aeb184f64d360d1774b8698d16ba3 (patch)
tree263df36acc8878ff16dc8e37578ec8bf2724ffab /cmd2/rl_utils.py
parentc2594ff278ac50556cf4781910439ea1977a5873 (diff)
downloadcmd2-git-4ce81a71de2aeb184f64d360d1774b8698d16ba3.tar.gz
Stopped sharing history between cmd2 and python console
Diffstat (limited to 'cmd2/rl_utils.py')
-rw-r--r--cmd2/rl_utils.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py
index 8ef65d28..5d278a0b 100644
--- a/cmd2/rl_utils.py
+++ b/cmd2/rl_utils.py
@@ -33,6 +33,29 @@ rl_type = RlType.NONE
if 'pyreadline' in sys.modules:
rl_type = RlType.PYREADLINE
+ # pyreadline is incomplete in terms of the Python readline API
+ # Add the missing functions we need
+ try:
+ getattr(readline, 'remove_history_item')
+ except AttributeError:
+ # noinspection PyProtectedMember
+ def pyreadline_remove_history_item(pos: int) -> None:
+ """
+ An implementation of remove_history_item() for pyreadline
+ :param pos: The 0-based position in history to remove
+ """
+ # Save of the current location of the history cursor
+ saved_cursor = readline.rl.mode._history.history_cursor
+
+ # Delete the history item
+ del(readline.rl.mode._history.history[pos])
+
+ # Update the cursor if needed
+ if saved_cursor > pos:
+ readline.rl.mode._history.history_cursor -= 1
+
+ readline.remove_history_item = pyreadline_remove_history_item
+
elif 'gnureadline' in sys.modules or 'readline' in sys.modules:
# We don't support libedit
if 'libedit' not in readline.__doc__: