Skip to content

Commit 91d7c30

Browse files
feat(cli): add unicode terminal detection
1 parent a0e730b commit 91d7c30

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

hatch/cli/cli_utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ class Color(Enum):
188188
RESET = "\033[0m"
189189

190190

191+
def _supports_unicode() -> bool:
192+
"""Check if terminal supports UTF-8 for unicode symbols.
193+
194+
Used to determine whether to use ✓/✗ symbols or ASCII fallback (+/x)
195+
in partial success reporting.
196+
197+
Reference: R13 §12.3 (13-error_message_formatting_v0.md)
198+
199+
Returns:
200+
bool: True if terminal supports UTF-8, False otherwise.
201+
202+
Example:
203+
>>> if _supports_unicode():
204+
... success_symbol = "✓"
205+
... else:
206+
... success_symbol = "+"
207+
"""
208+
import locale
209+
encoding = locale.getpreferredencoding(False)
210+
return encoding.lower() in ('utf-8', 'utf8')
211+
212+
191213
def _colors_enabled() -> bool:
192214
"""Check if color output should be enabled.
193215

0 commit comments

Comments
 (0)