From bb51cb14d1dfae45da247cc193d8cfa4b48781c4 Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Tue, 20 Aug 2024 23:47:12 +1000 Subject: [PATCH] [Resolve #1498] Tweak diff output In order to produce output that does not confuse syntax highlighters that recognise diff-formatted output, it is decided here to replace the "-" character (which would often cause a diff highlighter to colour the line as red) instead with "~" which would tend to be ignored by diff highlighters. --- sceptre/cli/diff.py | 6 +++--- sceptre/diffing/diff_writer.py | 12 ++++++------ tests/test_diffing/test_diff_writer.py | 18 +++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sceptre/cli/diff.py b/sceptre/cli/diff.py index 303b156c5..48e959b4a 100644 --- a/sceptre/cli/diff.py +++ b/sceptre/cli/diff.py @@ -189,12 +189,12 @@ def output_buffer_with_normalized_bar_lengths( max_length = len(max(buffer, key=len)) buffer.seek(0) full_length_star_bar = "*" * max_length - full_length_line_bar = "-" * max_length + full_length_tilde_bar = "~" * max_length for line in buffer: if DiffWriter.STAR_BAR in line: line = line.replace(DiffWriter.STAR_BAR, full_length_star_bar) - if DiffWriter.LINE_BAR in line: - line = line.replace(DiffWriter.LINE_BAR, full_length_line_bar) + if DiffWriter.TILDE_BAR in line: + line = line.replace(DiffWriter.TILDE_BAR, full_length_tilde_bar) output_stream.write(line) diff --git a/sceptre/diffing/diff_writer.py b/sceptre/diffing/diff_writer.py index b79c259ab..c3ecac245 100644 --- a/sceptre/diffing/diff_writer.py +++ b/sceptre/diffing/diff_writer.py @@ -25,7 +25,7 @@ class DiffWriter(Generic[DiffType]): """ STAR_BAR = "*" * 80 - LINE_BAR = "-" * 80 + TILDE_BAR = "~" * 80 def __init__( self, stack_diff: StackDiff, output_stream: TextIO, output_format: str @@ -59,26 +59,26 @@ def write(self): self._output(f"No difference to deployed stack {self.stack_name}") return - self._output(f"--> Difference detected for stack {self.stack_name}!") + self._output(f"==> Difference detected for stack {self.stack_name}!") if not self.is_deployed: self._write_new_stack_details() return - self._output(self.LINE_BAR) + self._output(self.TILDE_BAR) self._write_config_difference() - self._output(self.LINE_BAR) + self._output(self.TILDE_BAR) self._write_template_difference() def _write_new_stack_details(self): stack_config_text = self._dump_stack_config(self.stack_diff.generated_config) self._output( "This stack is not deployed yet!", - self.LINE_BAR, + self.TILDE_BAR, "New Config:", "", stack_config_text, - self.LINE_BAR, + self.TILDE_BAR, "New Template:", "", self.stack_diff.generated_template, diff --git a/tests/test_diffing/test_diff_writer.py b/tests/test_diffing/test_diff_writer.py index f2e8e7e82..deade3e00 100644 --- a/tests/test_diffing/test_diff_writer.py +++ b/tests/test_diffing/test_diff_writer.py @@ -57,7 +57,7 @@ def setup_method(self, method): self.output_stream = StringIO() self.diff_detected_message = ( - f"--> Difference detected for stack {self.stack_name}!" + f"==> Difference detected for stack {self.stack_name}!" ) @property @@ -133,11 +133,11 @@ def test_write__new_stack__writes_new_stack_config_and_template( DiffWriter.STAR_BAR, self.diff_detected_message, "This stack is not deployed yet!", - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, "New Config:", "", config_serializer(dict(self.generated_config._asdict())), - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, "New Template:", "", self.generated_template, @@ -152,11 +152,11 @@ def test_write__only_config_is_different__writes_config_difference(self): self.assert_expected_output( DiffWriter.STAR_BAR, self.diff_detected_message, - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, f"Config difference for {self.stack_name}:", "", self.diff_output, - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, "No template difference", ) @@ -169,9 +169,9 @@ def test_write__only_template_is_different__writes_template_difference(self): self.assert_expected_output( DiffWriter.STAR_BAR, self.diff_detected_message, - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, "No stack config difference", - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, f"Template difference for {self.stack_name}:", "", self.diff_output, @@ -186,11 +186,11 @@ def test_write__config_and_template_are_different__writes_both_differences(self) self.assert_expected_output( DiffWriter.STAR_BAR, self.diff_detected_message, - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, f"Config difference for {self.stack_name}:", "", self.diff_output, - DiffWriter.LINE_BAR, + DiffWriter.TILDE_BAR, f"Template difference for {self.stack_name}:", "", self.diff_output,