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

123 lines
4.0 KiB
Python
Vendored

from __future__ import annotations
from typing import TYPE_CHECKING
from textual.geometry import NULL_OFFSET, Region, Size
from textual.layout import ArrangeResult, Layout, WidgetPlacement
if TYPE_CHECKING:
from textual.widget import Widget
class StreamLayout(Layout):
"""A cut down version of the vertical layout.
The stream layout is faster, but has a few limitations compared to the vertical layout.
- All widgets are the full width (as if their widget is `1fr`).
- All widgets have an effective height of `auto`.
- `max-height` is supported, but only if it is a units value, all other extrema rules are ignored.
- No absolute positioning.
- No overlay: screen.
- Layers are ignored.
- Non TCSS styles are ignored.
The primary use of `layout: stream` is for a long list of widgets in a scrolling container, such as
what you might expect from a LLM chat-bot. The speed improvement will only be significant with a lot of
child widgets, so stick to vertical layouts unless you see any slowdown.
"""
name = "stream"
def arrange(
self, parent: Widget, children: list[Widget], size: Size, greedy: bool = True
) -> ArrangeResult:
parent.pre_layout(self)
if not children:
return []
viewport = parent.app.viewport_size
_Region = Region
_WidgetPlacement = WidgetPlacement
placements: list[WidgetPlacement] = []
width = size.width
first_child_styles = children[0].styles
y = 0
previous_margin = first_child_styles.margin.top
null_offset = NULL_OFFSET
for widget in children:
styles = widget.styles._base_styles
margin = styles.margin
gutter_width, gutter_height = styles.gutter.totals
top, right, bottom, left = margin
y += top if top > previous_margin else previous_margin
previous_margin = bottom
height = (
widget.get_content_height(size, viewport, width - gutter_width)
+ gutter_height
)
if (max_height := styles.max_height) is not None and max_height.is_cells:
height = (
height
if height < (max_height_value := int(max_height.value))
else max_height_value
)
if (min_height := styles.min_height) is not None and min_height.is_cells:
height = (
height
if height > (min_height_value := int(min_height.value))
else min_height_value
)
placements.append(
_WidgetPlacement(
_Region(left, y, width - (left + right), height),
null_offset,
margin,
widget,
0,
False,
False,
False,
)
)
y += height
return placements
def get_content_width(self, widget: Widget, container: Size, viewport: Size) -> int:
"""Get the optimal content width by arranging children.
Args:
widget: The container widget.
container: The container size.
viewport: The viewport size.
Returns:
Width of the content.
"""
return widget.scrollable_content_region.width
def get_content_height(
self, widget: Widget, container: Size, viewport: Size, width: int
) -> int:
"""Get the content height.
Args:
widget: The container widget.
container: The container size.
viewport: The viewport.
width: The content width.
Returns:
Content height (in lines).
"""
if widget._nodes:
arrangement = widget.arrange(Size(width, 0))
height = arrangement.total_region.height
else:
height = 0
return height