Coverage for src/crump/console_utils.py: 88%

1"""Utilities for cross-platform console output.

2

3 This module provides helpers for rendering console output that works

4 across different platforms, particularly handling Windows encoding limitations.

5"""

6

7 import platform

8

9

10 def get_box_char(unicode_char: str, ascii_fallback: str) -> str:

11 """Get appropriate box-drawing character based on platform.

12

13 On Windows, returns ASCII fallback to avoid UnicodeEncodeError with cp1252.

14 On other platforms, returns the Unicode character for better visual output.

15

16 Args:

17 unicode_char: The Unicode character to use on non-Windows platforms

18 ascii_fallback: The ASCII fallback to use on Windows

19

20 Returns:

21 The appropriate character for the current platform

22 """

23 if platform.system() == "Windows":

24 return ascii_fallback

25 return unicode_char

26

27

28# Common characters

29 CHECKMARK = get_box_char("✓", "OK")

30 BULLET = get_box_char("•", "*")

31 HORIZONTAL_LINE = get_box_char("─", "-")