Skip to content

Commit 432427b

Browse files
authored
Merge pull request #689 from python-cmd2/history_pickle
Persistent history for #669
2 parents d0add87 + 1be2e4b commit 432427b

File tree

8 files changed

+563
-238
lines changed

8 files changed

+563
-238
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ dmypy.json
2828
dmypy.sock
2929

3030
# cmd2 history file used in hello_cmd2.py
31-
cmd2_history.txt
31+
cmd2_history.dat

CHANGELOG.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@
2323
* Added support for custom Namespaces in the argparse decorators. See description of `ns_provider` argument
2424
for more information.
2525
* Transcript testing now sets the `exit_code` returned from `cmdloop` based on Success/Failure
26-
* Potentially breaking changes
26+
* The history of entered commands previously was saved using the readline persistence mechanism,
27+
and only persisted if you had readline installed. Now history is persisted independent of readline; user
28+
input from previous invocations of `cmd2` based apps now shows in the `history` command.
29+
30+
* Breaking changes
2731
* Replaced `unquote_redirection_tokens()` with `unquote_specific_tokens()`. This was to support the fix
2832
that allows terminators in alias and macro values.
2933
* Changed `Statement.pipe_to` to a string instead of a list
3034
* `preserve_quotes` is now a keyword-only argument in the argparse decorators
3135
* Refactored so that `cmd2.Cmd.cmdloop()` returns the `exit_code` instead of a call to `sys.exit()`
32-
* It is now applicaiton developer's responsibility to treat the return value from `cmdloop()` accordingly
36+
It is now application developer's responsibility to treat the return value from `cmdloop()` accordingly
37+
* Only valid commands are persistent in history between invocations of `cmd2` based apps. Previously
38+
all user input was persistent in history. If readline is installed, the history available with the up and
39+
down arrow keys (readline history) may not match that shown in the `history` command, because `history`
40+
only tracks valid input, while readline history captures all input.
41+
* History is now persisted in a binary format, not plain text format. Previous history files are destroyed
42+
on first launch of a `cmd2` based app of version 0.9.13 or higher.
43+
* HistoryItem class is no longer a subclass of `str`. If you are directly accessing the `.history` attribute
44+
of a `cmd2` based app, you will need to update your code to use `.history.get(1).statement.raw` instead.
3345
* **Python 3.4 EOL notice**
3446
* Python 3.4 reached its [end of life](https://www.python.org/dev/peps/pep-0429/) on March 18, 2019
3547
* This is the last release of `cmd2` which will support Python 3.4
@@ -38,7 +50,7 @@
3850
* Bug Fixes
3951
* Fixed a bug in how redirection and piping worked inside ``py`` or ``pyscript`` commands
4052
* Fixed bug in `async_alert` where it didn't account for prompts that contained newline characters
41-
* Fixed path completion case when CWD is just a slash. Relative path matches were incorrectly prepended with a slash.
53+
* Fixed path completion case when CWD is just a slash. Relative path matches were incorrectly prepended with a slash.
4254
* Enhancements
4355
* Added ability to include command name placeholders in the message printed when trying to run a disabled command.
4456
* See docstring for ``disable_command()`` or ``disable_category()`` for more details.
@@ -60,7 +72,7 @@
6072
* ``_report_disabled_command_usage()`` - in all cases since this is called when a disabled command is run
6173
* Removed *** from beginning of error messages printed by `do_help()` and `default()`
6274
* Significantly refactored ``cmd.Cmd`` class so that all class attributes got converted to instance attributes, also:
63-
* Added ``allow_redirection``, ``terminators``, ``multiline_commands``, and ``shortcuts`` as optional arguments
75+
* Added ``allow_redirection``, ``terminators``, ``multiline_commands``, and ``shortcuts`` as optional arguments
6476
to ``cmd.Cmd.__init__()`
6577
* A few instance attributes were moved inside ``StatementParser`` and properties were created for accessing them
6678
* ``self.pipe_proc`` is now called ``self.cur_pipe_proc_reader`` and is a ``ProcReader`` class.
@@ -98,7 +110,7 @@
98110
``cmd2`` convention of setting ``self.matches_sorted`` to True before returning the results if you have already
99111
sorted the ``CompletionItem`` list. Otherwise it will be sorted using ``self.matches_sort_key``.
100112
* Removed support for bash completion since this feature had slow performance. Also it relied on
101-
``AutoCompleter`` which has since developed a dependency on ``cmd2`` methods.
113+
``AutoCompleter`` which has since developed a dependency on ``cmd2`` methods.
102114
* Removed ability to call commands in ``pyscript`` as if they were functions (e.g. ``app.help()``) in favor
103115
of only supporting one ``pyscript`` interface. This simplifies future maintenance.
104116
* No longer supporting C-style comments. Hash (#) is the only valid comment marker.
@@ -118,7 +130,7 @@
118130
* Fixed bug where the ``set`` command was not tab completing from the current ``settable`` dictionary.
119131
* Enhancements
120132
* Changed edit command to use do_shell() instead of calling os.system()
121-
133+
122134
## 0.9.8 (February 06, 2019)
123135
* Bug Fixes
124136
* Fixed issue with echoing strings in StdSim. Because they were being sent to a binary buffer, line buffering
@@ -139,9 +151,9 @@
139151
* Deletions (potentially breaking changes)
140152
* Deleted ``Cmd.colorize()`` and ``Cmd._colorcodes`` which were deprecated in 0.9.5
141153
* Replaced ``dir_exe_only`` and ``dir_only`` flags in ``path_complete`` with optional ``path_filter`` function
142-
that is used to filter paths out of completion results.
154+
that is used to filter paths out of completion results.
143155
* ``perror()`` no longer prepends "ERROR: " to the error message being printed
144-
156+
145157
## 0.9.6 (October 13, 2018)
146158
* Bug Fixes
147159
* Fixed bug introduced in 0.9.5 caused by backing up and restoring `self.prompt` in `pseudo_raw_input`.
@@ -167,8 +179,8 @@
167179
the argparse object. Also, single-character tokens that happen to be a
168180
prefix char are not treated as flags by argparse and AutoCompleter now
169181
matches that behavior.
170-
* Fixed bug where AutoCompleter was not distinguishing between a negative number and a flag
171-
* Fixed bug where AutoCompleter did not handle -- the same way argparse does (all args after -- are non-options)
182+
* Fixed bug where AutoCompleter was not distinguishing between a negative number and a flag
183+
* Fixed bug where AutoCompleter did not handle -- the same way argparse does (all args after -- are non-options)
172184
* Enhancements
173185
* Added ``exit_code`` attribute of ``cmd2.Cmd`` class
174186
* Enables applications to return a non-zero exit code when exiting from ``cmdloop``
@@ -180,10 +192,10 @@
180192
* These allow you to provide feedback to the user in an asychronous fashion, meaning alerts can
181193
display when the user is still entering text at the prompt. See [async_printing.py](https://github.com/python-cmd2/cmd2/blob/master/examples/async_printing.py)
182194
for an example.
183-
* Cross-platform colored output support
195+
* Cross-platform colored output support
184196
* ``colorama`` gets initialized properly in ``Cmd.__init()``
185197
* The ``Cmd.colors`` setting is no longer platform dependent and now has three values:
186-
* Terminal (default) - output methods do not strip any ANSI escape sequences when output is a terminal, but
198+
* Terminal (default) - output methods do not strip any ANSI escape sequences when output is a terminal, but
187199
if the output is a pipe or a file the escape sequences are stripped
188200
* Always - output methods **never** strip ANSI escape sequences, regardless of the output destination
189201
* Never - output methods strip all ANSI escape sequences
@@ -193,18 +205,18 @@
193205
* Deprecations
194206
* Deprecated the built-in ``cmd2`` support for colors including ``Cmd.colorize()`` and ``Cmd._colorcodes``
195207
* Deletions (potentially breaking changes)
196-
* The ``preparse``, ``postparsing_precmd``, and ``postparsing_postcmd`` methods *deprecated* in the previous release
208+
* The ``preparse``, ``postparsing_precmd``, and ``postparsing_postcmd`` methods *deprecated* in the previous release
197209
have been deleted
198210
* The new application lifecycle hook system allows for registration of callbacks to be called at various points
199211
in the lifecycle and is more powerful and flexible than the previous system
200212
* ``alias`` is now a command with sub-commands to create, list, and delete aliases. Therefore its syntax
201213
has changed. All current alias commands in startup scripts or transcripts will break with this release.
202214
* `unalias` was deleted since ``alias delete`` replaced it
203-
215+
204216
## 0.9.4 (August 21, 2018)
205217
* Bug Fixes
206218
* Fixed bug where ``preparse`` was not getting called
207-
* Fixed bug in parsing of multiline commands where matching quote is on another line
219+
* Fixed bug in parsing of multiline commands where matching quote is on another line
208220
* Enhancements
209221
* Improved implementation of lifecycle hooks to support a plugin
210222
framework, see ``docs/hooks.rst`` for details.

0 commit comments

Comments
 (0)