The internal servers have no access to outside package repositories and run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual 6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a plain checkout runs with no pip and no network. - dsflow/: the single script split into a package (pure moves of the backend sections); action rules moved to ops.py, free of Textual - dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer, modal dialogs, filter, themes, mouse support - tests/test_ui.py: headless UI tests through Textual's pilot - tools/vendor.py (refresh vendor/), tools/screenshots.py (README images) - README, CLAUDE.md, TODO and the feature doc updated for the new layout, the Python 3.8.1 floor and the vendoring rules Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set runs under `python -I -S` on both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
254 lines
3.6 KiB
Python
Vendored
254 lines
3.6 KiB
Python
Vendored
from __future__ import annotations
|
||
|
||
from rich.console import Console, ConsoleOptions, RenderResult
|
||
from rich.measure import Measurement
|
||
from rich.segment import Segment
|
||
from rich.style import Style, StyleType
|
||
|
||
DIGITS = " 0123456789+-^x:ABCDEF$£€()"
|
||
DIGITS3X3_BOLD = """\
|
||
|
||
|
||
|
||
┏━┓
|
||
┃ ┃
|
||
┗━┛
|
||
╺┓
|
||
┃
|
||
╺┻╸
|
||
╺━┓
|
||
┏━┛
|
||
┗━╸
|
||
╺━┓
|
||
━┫
|
||
╺━┛
|
||
╻ ╻
|
||
┗━┫
|
||
╹
|
||
┏━╸
|
||
┗━┓
|
||
╺━┛
|
||
┏━╸
|
||
┣━┓
|
||
┗━┛
|
||
╺━┓
|
||
┃
|
||
╹
|
||
┏━┓
|
||
┣━┫
|
||
┗━┛
|
||
┏━┓
|
||
┗━┫
|
||
╺━┛
|
||
|
||
╺╋╸
|
||
|
||
|
||
╺━╸
|
||
|
||
^
|
||
|
||
|
||
|
||
×
|
||
|
||
|
||
:
|
||
|
||
╭─╮
|
||
├─┤
|
||
╵ ╵
|
||
┌─╮
|
||
├─┤
|
||
└─╯
|
||
╭─╮
|
||
│
|
||
╰─╯
|
||
┌─╮
|
||
│ │
|
||
└─╯
|
||
╭─╴
|
||
├─
|
||
╰─╴
|
||
╭─╴
|
||
├─
|
||
╵
|
||
╭╫╮
|
||
╰╫╮
|
||
╰╫╯
|
||
╭─╮
|
||
╪═
|
||
┷━╸
|
||
╭─╮
|
||
╪═
|
||
╰─╯
|
||
╭╴
|
||
│
|
||
╰╴
|
||
╶╮
|
||
│
|
||
╶╯
|
||
""".splitlines()
|
||
|
||
|
||
DIGITS3X3 = """\
|
||
|
||
|
||
|
||
╭─╮
|
||
│ │
|
||
╰─╯
|
||
╶╮
|
||
│
|
||
╶┴╴
|
||
╶─╮
|
||
┌─┘
|
||
╰─╴
|
||
╶─╮
|
||
─┤
|
||
╶─╯
|
||
╷ ╷
|
||
╰─┤
|
||
╵
|
||
╭─╴
|
||
╰─╮
|
||
╶─╯
|
||
╭─╴
|
||
├─╮
|
||
╰─╯
|
||
╶─┐
|
||
│
|
||
╵
|
||
╭─╮
|
||
├─┤
|
||
╰─╯
|
||
╭─╮
|
||
╰─┤
|
||
╶─╯
|
||
|
||
╶┼╴
|
||
|
||
|
||
╶─╴
|
||
|
||
^
|
||
|
||
|
||
|
||
×
|
||
|
||
|
||
:
|
||
|
||
╭─╮
|
||
├─┤
|
||
╵ ╵
|
||
┌─╮
|
||
├─┤
|
||
└─╯
|
||
╭─╮
|
||
│
|
||
╰─╯
|
||
┌─╮
|
||
│ │
|
||
└─╯
|
||
╭─╴
|
||
├─
|
||
╰─╴
|
||
╭─╴
|
||
├─
|
||
╵
|
||
╭╫╮
|
||
╰╫╮
|
||
╰╫╯
|
||
╭─╮
|
||
╪═
|
||
┷━╸
|
||
╭─╮
|
||
╪═
|
||
╰─╯
|
||
╭╴
|
||
│
|
||
╰╴
|
||
╶╮
|
||
│
|
||
╶╯
|
||
""".splitlines()
|
||
|
||
|
||
class Digits:
|
||
"""Renders a 3X3 unicode 'font' for numerical values.
|
||
|
||
Args:
|
||
text: Text to display.
|
||
style: Style to apply to the digits.
|
||
|
||
"""
|
||
|
||
REPLACEMENTS = str.maketrans({".": "•"})
|
||
|
||
def __init__(self, text: str, style: StyleType = "") -> None:
|
||
self._text = text
|
||
self._style = style
|
||
|
||
def __rich_console__(
|
||
self, console: Console, options: ConsoleOptions
|
||
) -> RenderResult:
|
||
style = console.get_style(self._style)
|
||
yield from self.render(style)
|
||
|
||
def render(self, style: Style) -> RenderResult:
|
||
"""Render with the given style
|
||
|
||
Args:
|
||
style: Rich Style.
|
||
|
||
Returns:
|
||
Result of render.
|
||
"""
|
||
digit_pieces: list[list[str]] = [[], [], []]
|
||
row1 = digit_pieces[0].append
|
||
row2 = digit_pieces[1].append
|
||
row3 = digit_pieces[2].append
|
||
|
||
if style.bold:
|
||
digits = DIGITS3X3_BOLD
|
||
else:
|
||
digits = DIGITS3X3
|
||
|
||
for character in self._text.translate(self.REPLACEMENTS):
|
||
try:
|
||
position = DIGITS.index(character) * 3
|
||
except ValueError:
|
||
row1(" ")
|
||
row2(" ")
|
||
row3(character)
|
||
else:
|
||
row1(digits[position].ljust(3))
|
||
row2(digits[position + 1].ljust(3))
|
||
row3(digits[position + 2].ljust(3))
|
||
|
||
new_line = Segment.line()
|
||
for line in digit_pieces:
|
||
yield Segment("".join(line), style + Style(meta={"offset": (0, 0)}))
|
||
yield new_line
|
||
|
||
@classmethod
|
||
def get_width(cls, text: str) -> int:
|
||
"""Calculate the width without rendering.
|
||
|
||
Args:
|
||
text: Text which may be displayed in the `Digits` widget.
|
||
|
||
Returns:
|
||
width of the text (in cells).
|
||
"""
|
||
width = sum(3 if character in DIGITS else 1 for character in text)
|
||
return width
|
||
|
||
def __rich_measure__(
|
||
self, console: Console, options: ConsoleOptions
|
||
) -> Measurement:
|
||
width = self.get_width(self._text)
|
||
return Measurement(width, width)
|