Coverage for src / crump / console_utils.py: 88%
8 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-11 14:40 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-11 14:40 +0000
1"""Utilities for cross-platform console output.
3This module provides helpers for rendering console output that works
4across different platforms, particularly handling Windows encoding limitations.
5"""
7import platform
10def get_box_char(unicode_char: str, ascii_fallback: str) -> str:
11 """Get appropriate box-drawing character based on platform.
13 On Windows, returns ASCII fallback to avoid UnicodeEncodeError with cp1252.
14 On other platforms, returns the Unicode character for better visual output.
16 Args:
17 unicode_char: The Unicode character to use on non-Windows platforms
18 ascii_fallback: The ASCII fallback to use on Windows
20 Returns:
21 The appropriate character for the current platform
22 """
23 if platform.system() == "Windows":
24 return ascii_fallback
25 return unicode_char
28# Common characters
29CHECKMARK = get_box_char("✓", "OK")
30BULLET = get_box_char("•", "*")
31HORIZONTAL_LINE = get_box_char("─", "-")