Skip to content

Commit be42f1b

Browse files
committed
test and added box drawing characters
1 parent ad6b886 commit be42f1b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

rich/cells.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from ._cell_widths import CELL_WIDTHS
88

99
# Regex to match sequence of the most common character ranges
10-
_is_single_cell_widths = re.compile("^[\u0020-\u007f\u00a0\u02ff\u0370-\u0482]*$").match
10+
_is_single_cell_widths = re.compile(
11+
"^[\u0020-\u007f\u00a0\u02ff\u0370-\u0482\u2500-\u25FF]*$"
12+
).match
1113

1214

1315
@lru_cache(4096)

tests/test_segment.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import string
12
from io import StringIO
23

34
import pytest
45

56
from rich.cells import cell_len
6-
from rich.segment import ControlType, Segment, SegmentLines, Segments
7+
from rich.segment import (
8+
ControlType,
9+
Segment,
10+
SegmentLines,
11+
Segments,
12+
_is_single_cell_widths,
13+
)
714
from rich.style import Style
815

916

@@ -378,3 +385,22 @@ def test_align_bottom():
378385
[Segment(" ", Style())],
379386
[Segment("X")],
380387
]
388+
389+
390+
def test_is_single_cell_widths() -> None:
391+
# Check _is_single_cell_widths reports correctly
392+
for character in string.printable:
393+
if ord(character) >= 32:
394+
assert _is_single_cell_widths(character)
395+
396+
BOX = "┌─┬┐│ ││├─┼┤│ ││├─┼┤├─┼┤│ ││└─┴┘"
397+
398+
for character in BOX:
399+
print(repr(character))
400+
assert _is_single_cell_widths(character)
401+
402+
for character in "💩":
403+
assert not _is_single_cell_widths(character)
404+
405+
for character in "わさび":
406+
assert not _is_single_cell_widths(character)

0 commit comments

Comments
 (0)