Files
lucioandClaude Opus 5.5 60532a4043 Rebuild the UI on vendored Textual; make the checkout self-contained
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]>
2026-09-24 03:24:21 -07:00

109 lines
3.5 KiB
Python
Vendored

from __future__ import annotations
import re
from rich.cells import cell_len
from rich.text import Text
_TABS_SPLITTER_RE = re.compile(r"(.*?\t|.+?$)")
def get_tab_widths(line: str, tab_size: int = 4) -> list[tuple[str, int]]:
"""Splits a string line into tuples (str, int).
Each tuple represents a section of the line which precedes a tab character.
The string is the string text that appears before the tab character (excluding the tab).
The integer is the width that the tab character is expanded to.
Args:
line: The text to expand tabs in.
tab_size: Number of cells in a tab.
Returns:
A list of tuples representing the line split on tab characters,
and the widths of the tabs after tab expansion is applied.
"""
parts: list[tuple[str, int]] = []
add_part = parts.append
cell_position = 0
matches = _TABS_SPLITTER_RE.findall(line)
for match in matches:
expansion_width = 0
if match.endswith("\t"):
# Remove the tab, and check the width of the rest of the line.
match = match[:-1]
cell_position += cell_len(match)
# Now move along the line by the width of the tab.
tab_remainder = cell_position % tab_size
expansion_width = tab_size - tab_remainder
cell_position += expansion_width
add_part((match, expansion_width))
return parts
def expand_tabs_inline(line: str, tab_size: int = 4) -> str:
"""Expands tabs, taking into account double cell characters.
Args:
line: The text to expand tabs in.
tab_size: Number of cells in a tab.
Returns:
New string with tabs replaced with spaces.
"""
tab_widths = get_tab_widths(line, tab_size)
return "".join(
[part + expansion_width * " " for part, expansion_width in tab_widths]
)
def expand_text_tabs_from_widths(line: Text, tab_widths: list[int]) -> Text:
"""Expand tabs to the widths defined in the `tab_widths` list.
This will return a new Text instance with tab characters expanded into a
number of spaces. Each time a tab is encountered, it's expanded into the
next integer encountered in the `tab_widths` list. Consequently, the length
of `tab_widths` should match the number of tab characters in `line`.
Args:
line: The `Text` instance to expand tabs in.
tab_widths: The widths to expand tabs to.
Returns:
A new text instance with tab characters converted to spaces.
"""
if "\t" not in line.plain:
return line
parts = line.split("\t", include_separator=True)
tab_widths_iter = iter(tab_widths)
new_parts: list[Text] = []
append_part = new_parts.append
for part in parts:
if part.plain.endswith("\t"):
part._text[-1] = part._text[-1][:-1] + " "
spaces = next(tab_widths_iter)
part.extend_style(spaces - 1)
append_part(part)
return Text("", end="").join(new_parts)
if __name__ == "__main__":
print(expand_tabs_inline("\tbar"))
print(expand_tabs_inline("\tbar\t"))
print(expand_tabs_inline("1\tbar"))
print(expand_tabs_inline("12\tbar"))
print(expand_tabs_inline("123\tbar"))
print(expand_tabs_inline("1234\tbar"))
print(expand_tabs_inline("💩\tbar"))
print(expand_tabs_inline("💩💩\tbar"))
print(expand_tabs_inline("💩💩💩\tbar"))
print(expand_tabs_inline("F💩\tbar"))
print(expand_tabs_inline("F💩O\tbar"))