mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 19:05:13 +00:00
fix(console): count spacing combining marks as one cell
Rich measures Indic marks like ि as zero width, so the --list panel border drifted on Hindi, Telugu and Tamil labels.
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
"""Rich measures Indic spacing marks as one cell, so a panel border stays aligned after such a label."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
from rich.cells import cell_len
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.panel import Panel
|
||||||
|
|
||||||
|
import unshackle.core.console # noqa: F401 # installs the cell width override
|
||||||
|
|
||||||
|
|
||||||
|
def test_spacing_marks_take_one_cell() -> None:
|
||||||
|
assert cell_len("हिंदी") == 4 # two Mc marks count, the Mn anusvara does not
|
||||||
|
assert cell_len("தமிழ்") == 4
|
||||||
|
assert cell_len("ไทย") == 3
|
||||||
|
|
||||||
|
|
||||||
|
def test_panel_pads_an_indic_label_to_the_border() -> None:
|
||||||
|
out = io.StringIO()
|
||||||
|
Console(file=out, width=20, color_system=None).print(Panel("हिंदी"))
|
||||||
|
|
||||||
|
assert out.getvalue().splitlines()[1] == "│ हिंदी" + " " * 12 + " │"
|
||||||
@@ -4,10 +4,13 @@ import logging
|
|||||||
import math
|
import math
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import unicodedata
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from functools import lru_cache
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import IO, Any, Callable, Iterable, List, Literal, Mapping, Optional, TextIO, Union
|
from typing import IO, Any, Callable, Iterable, List, Literal, Mapping, Optional, TextIO, Union
|
||||||
|
|
||||||
|
import rich.cells
|
||||||
from rich import box
|
from rich import box
|
||||||
from rich._log_render import FormatTimeCallable, LogRender
|
from rich._log_render import FormatTimeCallable, LogRender
|
||||||
from rich.color import Color, blend_rgb
|
from rich.color import Color, blend_rgb
|
||||||
@@ -414,6 +417,18 @@ def force_utf8_streams() -> None:
|
|||||||
|
|
||||||
force_utf8_streams()
|
force_utf8_streams()
|
||||||
|
|
||||||
|
_rich_cell_size = rich.cells.get_character_cell_size
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=4096)
|
||||||
|
def _cell_size(character: str, *args: str) -> int:
|
||||||
|
"""Count a spacing combining mark (Mc, e.g. Devanagari ि) as one cell, as terminals draw it; Rich's table says 0."""
|
||||||
|
return 1 if unicodedata.category(character) == "Mc" else _rich_cell_size(character, *args)
|
||||||
|
|
||||||
|
|
||||||
|
rich.cells.get_character_cell_size = _cell_size
|
||||||
|
rich.cells.cached_cell_len.cache_clear()
|
||||||
|
|
||||||
console = ComfyConsole(
|
console = ComfyConsole(
|
||||||
log_time=False,
|
log_time=False,
|
||||||
log_path=False,
|
log_path=False,
|
||||||
|
|||||||
Reference in New Issue
Block a user