From 605d8fe59af97fd549a0e8b16460ce7bef31a210 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 31 Mar 2025 10:32:48 +1300 Subject: [PATCH] fix: Fix ColorParseError by ensuring hex colors have # prefix --- aider/io.py | 3 ++- tests/basic/test_io.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/aider/io.py b/aider/io.py index 9a0b6f399..08c03ef53 100644 --- a/aider/io.py +++ b/aider/io.py @@ -963,6 +963,7 @@ class InputOutput: if not isinstance(message, Text): message = Text(message) + color = ensure_hash_prefix(color) if color else None style = dict(style=color) if self.pretty and color else dict() try: self.console.print(message, **style) @@ -993,7 +994,7 @@ class InputOutput: style = dict() if self.pretty: if self.tool_output_color: - style["color"] = self.tool_output_color + style["color"] = ensure_hash_prefix(self.tool_output_color) style["reverse"] = bold style = RichStyle(**style) diff --git a/tests/basic/test_io.py b/tests/basic/test_io.py index 7b18d4bf3..66dd7ccc9 100644 --- a/tests/basic/test_io.py +++ b/tests/basic/test_io.py @@ -446,6 +446,33 @@ class TestInputOutputMultilineMode(unittest.TestCase): self.assertEqual(ensure_hash_prefix("1234567"), "1234567") # Wrong length self.assertEqual(ensure_hash_prefix("xyz"), "xyz") # Invalid hex chars self.assertEqual(ensure_hash_prefix("12345g"), "12345g") # Invalid hex chars + + def test_tool_output_color_handling(self): + """Test that tool_output correctly handles hex colors without # prefix""" + from unittest.mock import patch + from rich.text import Text + + # Create IO with hex color without # for tool_output_color + io = InputOutput(tool_output_color="FFA500", pretty=True) + + # Patch console.print to avoid actual printing + with patch.object(io.console, "print") as mock_print: + # This would raise ColorParseError without the fix + io.tool_output("Test message") + + # Verify the call was made without error + mock_print.assert_called_once() + + # Verify the style was correctly created with # prefix + # The first argument is the message, second would be the style + kwargs = mock_print.call_args.kwargs + self.assertIn("style", kwargs) + + # Test with other hex color + io = InputOutput(tool_output_color="00FF00", pretty=True) + with patch.object(io.console, "print") as mock_print: + io.tool_output("Test message") + mock_print.assert_called_once() if __name__ == "__main__":