summaryrefslogtreecommitdiff
path: root/examples/persistent_history.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-08 21:48:00 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-08 21:48:00 -0500
commit303e9cb734d217fe4f142040518e3dd7a2a2b3ee (patch)
treecb069a30f8b1410f27bfc1a39b8bcc39547997ed /examples/persistent_history.py
parent4895d5d8db4e57e2ef9a062473a8536f4f07f213 (diff)
downloadcmd2-git-303e9cb734d217fe4f142040518e3dd7a2a2b3ee.tar.gz
Added optional persistent readline history feature
- Including an example and info in the Sphinx docs Also: - Created CHANGELOG entry for 0.8.1 release - Added info to README about new sub-menu feature - Bumped version to 0.8.1 TODO: - Added a unit test for the persistent readline history feature
Diffstat (limited to 'examples/persistent_history.py')
-rwxr-xr-xexamples/persistent_history.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/persistent_history.py b/examples/persistent_history.py
new file mode 100755
index 00000000..21a2cbf3
--- /dev/null
+++ b/examples/persistent_history.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# coding=utf-8
+"""This example demonstrates how to enable persistent readline history in your cmd2 application.
+
+This will allow end users of your cmd2-based application to use the arrow keys and Ctrl+r in a manner which persists
+across invocations of your cmd2 application. This can make it much easier for them to use your application.
+"""
+import cmd2
+
+
+class Cmd2PersistentHistory(cmd2.Cmd):
+ """Basic example of how to enable persistent readline history within your cmd2 app."""
+ def __init__(self):
+ """"""
+ cmd2.Cmd.__init__(self, persistent_history_file='~/.persistent_history.cmd2', persistent_history_length=500)
+
+ # ... your class code here ...
+
+
+if __name__ == '__main__':
+ app = Cmd2PersistentHistory()
+ app.cmdloop()