Fix horizontal box-drawing alignment with textLength attribute

Horizontal line characters (─━═) render narrower than the intended
character width in most fonts, causing gaps when followed by other
characters. Now using textLength + lengthAdjust='spacing' to force
horizontal box-drawing spans to occupy their correct width.

- Added _is_all_horizontal_box_drawing() helper
- Added textLength attribute for horizontal line spans > 1 char
- Added comprehensive tests for new functionality
- svg_exporter.py now has 100% test coverage

Version bump to 0.3.8
This commit is contained in:
GitHub Copilot
2026-01-24 19:19:08 +00:00
parent 076bf4cd5d
commit d8d3885efb
3 changed files with 64 additions and 1 deletions
+39
View File
@@ -10,6 +10,7 @@ from textual_webterm.svg_exporter import (
_build_row_spans,
_color_to_hex,
_escape_xml,
_is_all_horizontal_box_drawing,
_is_box_drawing_vertical_or_corner,
_should_break_span,
render_terminal_svg,
@@ -387,6 +388,30 @@ class TestBoxDrawingHelpers:
"""Horizontal lines can merge with each other."""
assert _should_break_span("", "") is False
assert _should_break_span("", "") is False
def test_is_all_horizontal_box_drawing_empty(self) -> None:
"""Empty string returns False."""
assert _is_all_horizontal_box_drawing("") is False
def test_is_all_horizontal_box_drawing_normal_text(self) -> None:
"""Normal text returns False."""
assert _is_all_horizontal_box_drawing("Hello") is False
assert _is_all_horizontal_box_drawing("ABC") is False
def test_is_all_horizontal_box_drawing_horizontal_lines(self) -> None:
"""Horizontal box chars return True."""
assert _is_all_horizontal_box_drawing("") is True
assert _is_all_horizontal_box_drawing("───") is True
assert _is_all_horizontal_box_drawing("━━━") is True
assert _is_all_horizontal_box_drawing("═══") is True
def test_is_all_horizontal_box_drawing_mixed(self) -> None:
"""Mixed content returns False."""
assert _is_all_horizontal_box_drawing("─A─") is False
assert _is_all_horizontal_box_drawing("│──") is False # vertical at start
class TestRenderTerminalSvg:
"""Tests for render_terminal_svg function."""
def _char(
@@ -797,6 +822,20 @@ class TestEdgeCases:
assert "" in svg
assert "" in svg
def test_horizontal_lines_use_textlength(self) -> None:
"""Horizontal line spans use textLength for correct width."""
buffer = [[
self._char(""),
self._char(""),
self._char(""),
self._char(""),
self._char(""),
]]
svg = render_terminal_svg(buffer, width=5, height=1)
# Horizontal lines should have textLength attribute
assert 'textLength="24.0"' in svg
assert 'lengthAdjust="spacing"' in svg
def test_ansi_bright_colors(self) -> None:
"""All bright ANSI colors render."""
colors = ["brightred", "brightgreen", "brightyellow",