summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-07-20 17:20:34 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-07-20 17:20:34 -0400
commit30c740eb5906518f75418160d8308072d0378e3e (patch)
tree8b0903c2be20dc50334b30d58b61a0f4ba4d0036 /cmd2/cmd2.py
parent01a6f9b4f4daa20ed0216a49147ec005349c77e1 (diff)
downloadcmd2-git-30c740eb5906518f75418160d8308072d0378e3e.tar.gz
Much simpler solution for clipboard append
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py18
1 files changed, 5 insertions, 13 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 72784d4c..39e80866 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2089,16 +2089,14 @@ class Cmd(cmd.Cmd):
redir_error = True
else:
# going to a paste buffer
- if statement.output == constants.REDIRECTION_APPEND:
- temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
- temp_file.write(get_paste_buffer())
- new_stdout = open(temp_file.name, mode='a+')
- else:
- new_stdout = tempfile.TemporaryFile(mode='w+')
-
+ new_stdout = tempfile.TemporaryFile(mode="w+")
saved_state.redirecting = True
sys.stdout = self.stdout = new_stdout
+ if statement.output == constants.REDIRECTION_APPEND:
+ self.stdout.write(get_paste_buffer())
+ self.stdout.flush()
+
return redir_error, saved_state
def _restore_output(self, statement: Statement, saved_state: utils.RedirectionSavedState) -> None:
@@ -2114,8 +2112,6 @@ class Cmd(cmd.Cmd):
if statement.output and not statement.output_to:
self.stdout.seek(0)
write_to_paste_buffer(self.stdout.read())
- if statement.output == constants.REDIRECTION_APPEND:
- delete_name = self.stdout.name
try:
# Close the file or pipe that stdout was redirected to
@@ -2123,10 +2119,6 @@ class Cmd(cmd.Cmd):
except BrokenPipeError:
pass
- # If we appended to the clipboard, make sure to delete the tempfile
- if delete_name is not None:
- os.unlink(delete_name)
-
# Restore the stdout values
self.stdout = saved_state.saved_self_stdout
sys.stdout = saved_state.saved_sys_stdout