66import json
77
88
9+ # ANSI color codes
10+ colors = {
11+ "blue" : "\033 [94m" , # Bright blue
12+ "green" : "\033 [92m" , # Bright green
13+ "reset" : "\033 [0m" , # Reset to default color
14+ }
15+
16+
17+ def color_text (text , color = "blue" ):
18+ """
19+ Colors a string as blue or green.
20+
21+ Args:
22+ text (str): The string to color
23+ color (str): Color to apply - either "blue" or "green" (default: "blue")
24+
25+ Returns:
26+ str: The colored string with ANSI escape codes
27+
28+ Raises:
29+ ValueError: If color is not "blue" or "green"
30+ """
31+
32+ if color not in ["blue" , "green" ]:
33+ raise ValueError ("Color must be either 'blue' or 'green'" )
34+
35+ return f"{ colors [color ]} { text } { colors ['reset' ]} "
36+
37+
938def dump_json_colored (data , color = "reset" , indent = 2 , sort_keys = False ):
1039 """
1140 Dumps a JSON dictionary with colored text output.
@@ -23,12 +52,6 @@ def dump_json_colored(data, color="reset", indent=2, sort_keys=False):
2352 ValueError: If color is not "blue" or "green"
2453 TypeError: If data is not JSON serializable
2554 """
26- # ANSI color codes
27- colors = {
28- "blue" : "\033 [94m" , # Bright blue
29- "green" : "\033 [92m" , # Bright green
30- "reset" : "\033 [0m" , # Reset to default color
31- }
3255
3356 if color not in ["blue" , "green" ]:
3457 raise ValueError ("Color must be either 'blue' or 'green'" )
0 commit comments