Skip to content

Commit

Permalink
test and added box drawing characters
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Oct 22, 2024
1 parent ad6b886 commit be42f1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion rich/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from ._cell_widths import CELL_WIDTHS

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


@lru_cache(4096)
Expand Down
28 changes: 27 additions & 1 deletion tests/test_segment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import string
from io import StringIO

import pytest

from rich.cells import cell_len
from rich.segment import ControlType, Segment, SegmentLines, Segments
from rich.segment import (
ControlType,
Segment,
SegmentLines,
Segments,
_is_single_cell_widths,
)
from rich.style import Style


Expand Down Expand Up @@ -378,3 +385,22 @@ def test_align_bottom():
[Segment(" ", Style())],
[Segment("X")],
]


def test_is_single_cell_widths() -> None:
# Check _is_single_cell_widths reports correctly
for character in string.printable:
if ord(character) >= 32:
assert _is_single_cell_widths(character)

BOX = "┌─┬┐│ ││├─┼┤│ ││├─┼┤├─┼┤│ ││└─┴┘"

for character in BOX:
print(repr(character))
assert _is_single_cell_widths(character)

for character in "💩":
assert not _is_single_cell_widths(character)

for character in "わさび":
assert not _is_single_cell_widths(character)

0 comments on commit be42f1b

Please sign in to comment.