From 5b4bec9d56b2907a168d0688b0a3cde64043d048 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Sat, 11 Apr 2020 14:42:37 -0400 Subject: Simplfied _redirect_output() by raising exception instead of returning bool --- cmd2/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 03ede2a3..8ad8fc67 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -674,7 +674,7 @@ class RedirectionSavedState: self.saved_sys_stdout = sys_stdout self.saved_pipe_proc_reader = pipe_proc_reader - # Tells if the command is redirecting + # Tells if the command is redirecting or piping self.redirecting = False # If the command created a process to pipe to, then then is its reader -- cgit v1.2.1 From e7314ef1daea68c08c979a99f4dbf7d58db03af4 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Sun, 12 Apr 2020 18:46:21 -0400 Subject: onecmd_plus_hooks() no longer handles updating any state data related to redirection. For simplicity, it's all done in _redirect_output() and _restore_output(). --- cmd2/utils.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 8ad8fc67..cd0c7d54 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 or piping - 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 -- cgit v1.2.1