Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## 0.9.22 (TBD, 2019)
* Bug Fixes
* Fixed bug where a redefined `ansi.style_error` was not being used in all `cmd2` files
* Other
* Removed `bold=True` from `ansi.style_success` because it was difficult for red-greed colorblind users to
distinguish that color from the `ansi.style_warning` color in certain terminals.
* Enhancements
* Enabled line buffering when redirecting output to a file

## 0.9.21 (November 26, 2019)
* Bug Fixes
Expand Down
15 changes: 9 additions & 6 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,22 +1874,25 @@ def _redirect_output(self, statement: Statement) -> Tuple[bool, utils.Redirectio
self.perror("Cannot redirect to paste buffer; missing 'pyperclip' and/or pyperclip dependencies")
redir_error = True

# Redirecting to a file
elif statement.output_to:
# going to a file
mode = 'w'
# statement.output can only contain
# REDIRECTION_APPEND or REDIRECTION_OUTPUT
# statement.output can only contain REDIRECTION_APPEND or REDIRECTION_OUTPUT
if statement.output == constants.REDIRECTION_APPEND:
mode = 'a'
else:
mode = 'w'

try:
new_stdout = open(utils.strip_quotes(statement.output_to), mode)
# Use line buffering
new_stdout = open(utils.strip_quotes(statement.output_to), mode=mode, buffering=1)
saved_state.redirecting = True
sys.stdout = self.stdout = new_stdout
except OSError as ex:
self.pexcept('Failed to redirect because - {}'.format(ex))
redir_error = True

# Redirecting to a paste buffer
else:
# going to a paste buffer
new_stdout = tempfile.TemporaryFile(mode="w+")
saved_state.redirecting = True
sys.stdout = self.stdout = new_stdout
Expand Down