From be42f1b082477f1ec4bdf5d05da7145c78418cda Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 22 Oct 2024 16:10:04 +0100 Subject: [PATCH] test and added box drawing characters --- rich/cells.py | 4 +++- tests/test_segment.py | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/rich/cells.py b/rich/cells.py index 93ecf6abc..af8e81c7b 100644 --- a/rich/cells.py +++ b/rich/cells.py @@ -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) diff --git a/tests/test_segment.py b/tests/test_segment.py index 2264dbe50..a9e649410 100644 --- a/tests/test_segment.py +++ b/tests/test_segment.py @@ -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 @@ -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)