summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-04-15 19:18:49 -0400
committerGitHub <noreply@github.com>2020-04-15 19:18:49 -0400
commitba42eb40199652224601b118b7411c59d4a14340 (patch)
tree24b34d3300e96d0b39493d5d4e554fa2fdc1da46 /cmd2/utils.py
parentc5aa3fd31567574a9ed9fa97f7ba7e7083af707f (diff)
parent85bb29b7edfc6485556f398ddb192c16d1509856 (diff)
downloadcmd2-git-ba42eb40199652224601b118b7411c59d4a14340.tar.gz
Merge branch 'master' into table_creator
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 58305a61..0749f32b 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -665,20 +665,26 @@ class ContextFlag:
class RedirectionSavedState:
- """Created by each command to store information about their redirection."""
-
+ """Created by each command to store information required to restore state after redirection"""
def __init__(self, self_stdout: Union[StdSim, TextIO], sys_stdout: Union[StdSim, TextIO],
- pipe_proc_reader: Optional[ProcReader]) -> None:
- # Used to restore values after the command ends
+ pipe_proc_reader: Optional[ProcReader], saved_redirecting: bool) -> None:
+ """
+ RedirectionSavedState initializer
+ :param self_stdout: saved value of Cmd.stdout
+ :param sys_stdout: saved value of sys.stdout
+ :param pipe_proc_reader: saved value of Cmd._cur_pipe_proc_reader
+ :param saved_redirecting: saved value of Cmd._redirecting
+ """
+ # Tells if command is redirecting
+ self.redirecting = False
+
+ # Used to restore values after redirection ends
self.saved_self_stdout = self_stdout
self.saved_sys_stdout = sys_stdout
- self.saved_pipe_proc_reader = pipe_proc_reader
-
- # Tells if the command is redirecting
- self.redirecting = False
- # If the command created a process to pipe to, then then is its reader
- self.pipe_proc_reader = None
+ # Used to restore values after command ends regardless of whether the command redirected
+ self.saved_pipe_proc_reader = pipe_proc_reader
+ self.saved_redirecting = saved_redirecting
# noinspection PyUnusedLocal