Skip to content

Commit e965e50

Browse files
committed
fix(console): turn emoji substitution off globally
print_list and print_files print directly instead of going through the log methods, so they still replaced shortcodes with glyphs. Passing emoji=False to print does not reach file names inside the tree, so the console itself is now built with emoji off.
1 parent 3b58195 commit e965e50

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

plain2code_console.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class Plain2CodeConsole(Console):
2727
DEBUG_STYLE = Style(color="purple")
2828

2929
def __init__(self):
30-
super().__init__()
30+
# Emoji shortcodes must never be substituted. Set on the console because the
31+
# emoji flag of Console.print does not reach text inside renderables like Tree.
32+
super().__init__(emoji=False)
3133
try:
3234
import tiktoken
3335

@@ -66,13 +68,12 @@ def _log_and_print(self, level, base_style, args, color, kwargs):
6668
"""
6769
logger.log(level, " ".join(map(str, args)), extra={"log_color": color})
6870
style = base_style + Style(color=color) if color else base_style
69-
# Log messages must render exactly as logged: don't interpret square brackets
70-
# in interpolated content (error texts, file names) as Rich markup, and don't
71-
# let the repr highlighter restyle brackets and numbers inside them.
72-
# Don't let Rich substitute emoji shortcodes with glyphs. Literal emojis unaffected.
71+
# Messages must render exactly as logged and not pick its own styling:
72+
# -- no Rich markup (via square brackets) in interpolated content (error texts, file names)
73+
# -- no repr highlighter restyling brackets and numbers inside them.
74+
# -- emoji are off console-wide via __init__
7375
kwargs.setdefault("markup", False)
7476
kwargs.setdefault("highlight", False)
75-
kwargs.setdefault("emoji", False)
7677
super().print(*args, **kwargs, style=style)
7778

7879
def print_list(self, items, style=None):

tests/test_console_log_styles.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ def test_concept_name_matching_emoji_prints_verbatim(self):
116116
assert "📦" not in capture.get()
117117

118118

119+
class TestPrintHelpersDoNotSubstituteEmoji:
120+
"""
121+
Same rule as TestTerminalTextRendersVerbatim, for the two helpers that bypass _log_and_print.
122+
Only emoji is covered here, markup and highlighting still apply to them.
123+
"""
124+
125+
def test_print_list_does_not_substitute_emoji(self):
126+
console = Plain2CodeConsole()
127+
with console.capture() as capture:
128+
console.print_list(["The :Package: is a concept"])
129+
assert ":Package:" in capture.get()
130+
131+
def test_print_files_does_not_substitute_emoji_in_tree_labels(self):
132+
console = Plain2CodeConsole()
133+
with console.capture() as capture:
134+
console.print_files("Files added:", "build", {":Package:.py": "x"})
135+
assert ":Package:" in capture.get()
136+
137+
119138
class TestLoggingHandlerForwardsColor:
120139
"""LoggingHandler must forward the log_color record attribute into LogMessageEmitted."""
121140

0 commit comments

Comments
 (0)