Textual
Type: Python Framework Role in Styrene: TUI framework for styrened.tui
Textual is a Python framework for building terminal user interfaces (TUIs). It provides a modern, reactive programming model with CSS-like styling.
Why Styrene Uses Textual
| Requirement | Textual Capability |
|---|---|
| Cross-platform TUI | Works on Linux, macOS, Windows, SSH |
| Rich widgets | Tables, trees, tabs, modals, progress bars |
| Async-native | Built on asyncio, handles RNS callbacks naturally |
| CSS styling | Themeable, consistent look |
| Active development | Regular releases, responsive maintainer |
Architecture
┌─────────────────────────────────────────┐
│ Textual Application │
├─────────────────────────────────────────┤
│ Screens (Provision, Dashboard, etc.) │
├─────────────────────────────────────────┤
│ Widgets (DataTable, ProgressBar, etc.) │
├─────────────────────────────────────────┤
│ Message Bus (reactive events) │
├─────────────────────────────────────────┤
│ Terminal Driver (output rendering) │
└─────────────────────────────────────────┘
Styrene TUI Screens
See styrene-tui-vision for the full screen inventory. Key widget usage:
| Screen | Widgets Used |
|---|---|
| Dashboard | DataTable, StatusPanel |
| Chat | Markdown, Input, ListView |
| Device Detail | Tabs, Static, Input |
| Settings | TabbedContent, Switch, Input |
Reactive Pattern
Textual uses message passing for UI updates:
class FleetDevice(Widget):
"""A device in the fleet list."""
status = reactive("unknown")
def watch_status(self, new_status: str) -> None:
"""Called when status changes."""
self.update_styles()
This integrates well with LXMF callbacks:
async def on_status_response(self, message: StatusResponse) -> None:
"""Handle status response from styrened."""
device = self.query_one(f"#device-{message.device_id}")
device.status = message.status # Triggers reactive update
CSS Styling
Textual uses TCSS (Textual CSS):
FleetDevice {
height: 3;
padding: 1;
border: solid green;
}
FleetDevice.-offline {
border: solid red;
opacity: 0.7;
}
Styrene uses the Imperial CRT theme (phosphor green on dark).
Dev Mode
Textual provides a dev console:
textual run --dev styrene-tui
Features:
- Live CSS reloading
- Widget inspector
- Event log
- Screenshot capture
Resources
- Textual Documentation
- GitHub: Textualize/textual
- Textual Gallery — Example apps
Related
- styrene-tui-vision — TUI design and status