feat: preview

This commit is contained in:
2026-04-01 10:13:14 +02:00
parent 8776459ffb
commit 0316e50233
13 changed files with 590 additions and 538 deletions

View File

@@ -7,6 +7,7 @@ own structure (borders, etc.).
from __future__ import annotations
import re
import textwrap
from uframe.chars import (
@@ -63,8 +64,12 @@ def paint(node: IRNode, grid: CharGrid) -> None:
weight=node.weight,
title=node.title,
title_style=title_style)
# Paint children inside the border
# Propagate box alignment/color to children that don't have their own
for child in node.children:
if node.style.align != Align.LEFT and child.style.align == Align.LEFT:
child.style.align = node.style.align
if node.style.fg and not child.style.fg:
child.style.fg = node.style.fg
paint(child, grid)
elif isinstance(node, Row):
@@ -155,9 +160,9 @@ def paint(node: IRNode, grid: CharGrid) -> None:
elif isinstance(node, ListItem):
style = _style_from_node(node)
# Parent determines bullet style — use a simple bullet for now
bullet = ""
grid.put_text(x - 2, y, bullet, style=CellStyle(fg="888"))
# Bullet to the left of the content (safe: put_text clips to bounds)
bullet_x = max(0, x - 2)
grid.put_text(bullet_x, y, "", style=CellStyle(fg="888"))
# Wrap content
wrapped = textwrap.wrap(node.content, width=w) if node.content else [""]
for i, line in enumerate(wrapped):
@@ -357,9 +362,7 @@ def _paint_table(node: Table, grid: CharGrid, x: int, y: int, w: int) -> None:
# Check for @color{hex}{text} modifiers in cell content
if "@" in cell_text:
spans = []
import re as _re
pattern = _re.compile(r"@color\{([0-9a-fA-F]{3})\}\{([^}]*)\}")
pattern = re.compile(r"@color\{([0-9a-fA-F]{3})\}\{([^}]*)\}")
pos = 0
styled_parts: list[tuple[str, CellStyle]] = []
for m in pattern.finditer(cell_text):