@@ -595,7 +595,7 @@ def _(event: Any) -> None: # pragma: no cover
595595 if os .path .exists (startup_script ):
596596 script_cmd = f"run_script { su .quote (startup_script )} "
597597 if silence_startup_script :
598- script_cmd += f" { constants .REDIRECTION_OUTPUT } { os .devnull } "
598+ script_cmd += f" { constants .REDIRECTION_OVERWRITE } { os .devnull } "
599599 self ._startup_commands .append (script_cmd )
600600
601601 # Transcript files to run instead of interactive command loop
@@ -2140,7 +2140,7 @@ def _redirect_complete(self, text: str, line: str, begidx: int, endidx: int, com
21402140
21412141 if prior_token == constants .REDIRECTION_PIPE :
21422142 do_shell_completion = True
2143- elif in_pipe or prior_token in (constants .REDIRECTION_OUTPUT , constants .REDIRECTION_APPEND ):
2143+ elif in_pipe or prior_token in (constants .REDIRECTION_OVERWRITE , constants .REDIRECTION_APPEND ):
21442144 do_path_completion = True
21452145
21462146 prior_token = cur_token
@@ -2190,14 +2190,14 @@ def _perform_completion(
21902190 # Parse the command line to get the command token.
21912191 command = ''
21922192 if custom_settings is None :
2193- statement = self .statement_parser .parse_command_only (line )
2194- command = statement .command
2193+ partial_statement = self .statement_parser .parse_command_only (line )
2194+ command = partial_statement .command
21952195
21962196 # Malformed command line (e.g. quoted command token)
21972197 if not command :
21982198 return Completions ()
21992199
2200- expanded_line = statement .command_and_args
2200+ expanded_line = partial_statement .command_and_args
22012201
22022202 if not expanded_line [- 1 :].isspace ():
22032203 # Unquoted trailing whitespace gets stripped by parse_command_only().
@@ -2642,8 +2642,8 @@ def parseline(self, line: str) -> tuple[str, str, str]:
26422642 :param line: line read by prompt-toolkit
26432643 :return: tuple containing (command, args, line)
26442644 """
2645- statement = self .statement_parser .parse_command_only (line )
2646- return statement .command , statement .args , statement .command_and_args
2645+ partial_statement = self .statement_parser .parse_command_only (line )
2646+ return partial_statement .command , partial_statement .args , partial_statement .command_and_args
26472647
26482648 def onecmd_plus_hooks (
26492649 self ,
@@ -2853,8 +2853,8 @@ def _complete_statement(self, line: str) -> Statement:
28532853 except Cmd2ShlexError :
28542854 # we have an unclosed quotation mark, let's parse only the command
28552855 # and see if it's a multiline
2856- statement = self .statement_parser .parse_command_only (line )
2857- if not statement .multiline_command :
2856+ partial_statement = self .statement_parser .parse_command_only (line )
2857+ if not partial_statement .multiline_command :
28582858 # not a multiline command, so raise the exception
28592859 raise
28602860
@@ -2907,8 +2907,7 @@ def _input_line_to_statement(self, line: str) -> Statement:
29072907 # Make sure all input has been read and convert it to a Statement
29082908 statement = self ._complete_statement (line )
29092909
2910- # If this is the first loop iteration, save the original line and stop
2911- # combining multiline history entries in the remaining iterations.
2910+ # If this is the first loop iteration, save the original line
29122911 if orig_line is None :
29132912 orig_line = statement .raw
29142913
@@ -2922,22 +2921,14 @@ def _input_line_to_statement(self, line: str) -> Statement:
29222921 else :
29232922 break
29242923
2925- # This will be true when a macro was used
2924+ # If a macro was expanded, the 'statement' now contains the expanded text.
2925+ # We need to swap the 'raw' attribute back to the string the user typed
2926+ # so history shows the original line.
29262927 if orig_line != statement .raw :
2927- # Build a Statement that contains the resolved macro line
2928- # but the originally typed line for its raw member.
2929- statement = Statement (
2930- statement .args ,
2931- raw = orig_line ,
2932- command = statement .command ,
2933- arg_list = statement .arg_list ,
2934- multiline_command = statement .multiline_command ,
2935- terminator = statement .terminator ,
2936- suffix = statement .suffix ,
2937- pipe_to = statement .pipe_to ,
2938- output = statement .output ,
2939- output_to = statement .output_to ,
2940- )
2928+ statement_dict = statement .to_dict ()
2929+ statement_dict ["raw" ] = orig_line
2930+ statement = Statement .from_dict (statement_dict )
2931+
29412932 return statement
29422933
29432934 def _resolve_macro (self , statement : Statement ) -> str | None :
@@ -3004,7 +2995,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
30042995 # Don't return since we set some state variables at the end of the function
30052996 pass
30062997
3007- elif statement .pipe_to :
2998+ elif statement .redirector == constants . REDIRECTION_PIPE :
30082999 # Create a pipe with read and write sides
30093000 read_fd , write_fd = os .pipe ()
30103001
@@ -3028,7 +3019,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
30283019
30293020 # For any stream that is a StdSim, we will use a pipe so we can capture its output
30303021 proc = subprocess .Popen ( # noqa: S602
3031- statement .pipe_to ,
3022+ statement .redirect_to ,
30323023 stdin = subproc_stdin ,
30333024 stdout = subprocess .PIPE if isinstance (self .stdout , utils .StdSim ) else self .stdout , # type: ignore[unreachable]
30343025 stderr = subprocess .PIPE if isinstance (sys .stderr , utils .StdSim ) else sys .stderr ,
@@ -3055,14 +3046,14 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
30553046 if stdouts_match :
30563047 sys .stdout = self .stdout
30573048
3058- elif statement .output :
3059- if statement .output_to :
3049+ elif statement .redirector in ( constants . REDIRECTION_OVERWRITE , constants . REDIRECTION_APPEND ) :
3050+ if statement .redirect_to :
30603051 # redirecting to a file
30613052 # statement.output can only contain REDIRECTION_APPEND or REDIRECTION_OUTPUT
3062- mode = 'a' if statement .output == constants .REDIRECTION_APPEND else 'w'
3053+ mode = 'a' if statement .redirector == constants .REDIRECTION_APPEND else 'w'
30633054 try :
30643055 # Use line buffering
3065- new_stdout = cast (TextIO , open (su .strip_quotes (statement .output_to ), mode = mode , buffering = 1 )) # noqa: SIM115
3056+ new_stdout = cast (TextIO , open (su .strip_quotes (statement .redirect_to ), mode = mode , buffering = 1 )) # noqa: SIM115
30663057 except OSError as ex :
30673058 raise RedirectionError ('Failed to redirect output' ) from ex
30683059
@@ -3093,7 +3084,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
30933084 if stdouts_match :
30943085 sys .stdout = self .stdout
30953086
3096- if statement .output == constants .REDIRECTION_APPEND :
3087+ if statement .redirector == constants .REDIRECTION_APPEND :
30973088 self .stdout .write (current_paste_buffer )
30983089 self .stdout .flush ()
30993090
@@ -3111,7 +3102,10 @@ def _restore_output(self, statement: Statement, saved_redir_state: utils.Redirec
31113102 """
31123103 if saved_redir_state .redirecting :
31133104 # If we redirected output to the clipboard
3114- if statement .output and not statement .output_to :
3105+ if (
3106+ statement .redirector in (constants .REDIRECTION_OVERWRITE , constants .REDIRECTION_APPEND )
3107+ and not statement .redirect_to
3108+ ):
31153109 self .stdout .seek (0 )
31163110 write_to_paste_buffer (self .stdout .read ())
31173111
0 commit comments