home / skills / a5c-ai / babysitter / textual-scaffolder

This skill generates Python Textual TUI project structures with widgets, screens, and CSS styling to accelerate terminal UI development.

npx playbooks add skill a5c-ai/babysitter --skill textual-scaffolder

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
4.0 KB
---
name: textual-scaffolder
description: Generate Textual (Python) TUI application structure with widgets, screens, and CSS styling.
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
---

# Textual Scaffolder

Generate Textual TUI applications with Python and modern async patterns.

## Capabilities

- Generate Textual project structure
- Create custom widgets and screens
- Set up CSS-based styling
- Implement reactive attributes
- Create component composition
- Set up testing with textual.testing

## Usage

Invoke this skill when you need to:
- Build terminal UIs in Python
- Create interactive CLI with CSS styling
- Implement multi-screen TUI applications
- Set up Textual project structure

## Inputs

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| projectName | string | Yes | Project name |
| screens | array | No | Screen definitions |
| widgets | array | No | Custom widget definitions |

## Generated Patterns

### Main Application

```python
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Static, Button, Input
from textual.containers import Container, Horizontal, Vertical
from textual.screen import Screen

class MainScreen(Screen):
    """Main application screen."""

    CSS = """
    MainScreen {
        layout: grid;
        grid-size: 2;
        grid-gutter: 1;
    }

    #sidebar {
        width: 30;
        background: $surface;
        border: solid $primary;
    }

    #content {
        background: $surface;
        border: solid $secondary;
    }
    """

    def compose(self) -> ComposeResult:
        yield Header()
        yield Container(
            Static("Sidebar", id="sidebar"),
            Static("Content", id="content"),
        )
        yield Footer()


class MyApp(App):
    """Main TUI application."""

    BINDINGS = [
        ("q", "quit", "Quit"),
        ("d", "toggle_dark", "Toggle dark mode"),
    ]

    CSS_PATH = "styles.tcss"

    def on_mount(self) -> None:
        self.push_screen(MainScreen())

    def action_toggle_dark(self) -> None:
        self.dark = not self.dark


if __name__ == "__main__":
    app = MyApp()
    app.run()
```

### Custom Widget

```python
from textual.widget import Widget
from textual.reactive import reactive
from textual.message import Message

class Counter(Widget):
    """A counter widget with increment/decrement."""

    value = reactive(0)

    class Changed(Message):
        """Counter value changed."""
        def __init__(self, value: int) -> None:
            self.value = value
            super().__init__()

    def render(self) -> str:
        return f"Count: {self.value}"

    def increment(self) -> None:
        self.value += 1
        self.post_message(self.Changed(self.value))

    def decrement(self) -> None:
        self.value -= 1
        self.post_message(self.Changed(self.value))
```

### CSS Styles (styles.tcss)

```css
Screen {
    background: $surface;
}

Header {
    dock: top;
    background: $primary;
}

Footer {
    dock: bottom;
    background: $primary;
}

Button {
    margin: 1;
}

Button:hover {
    background: $primary-lighten-1;
}

Input {
    margin: 1;
    border: tall $secondary;
}

Input:focus {
    border: tall $primary;
}

.error {
    color: $error;
}

.success {
    color: $success;
}
```

### Data Table Widget

```python
from textual.widgets import DataTable
from textual.app import ComposeResult

class DataScreen(Screen):
    def compose(self) -> ComposeResult:
        yield DataTable()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_columns("Name", "Email", "Role")
        table.add_rows([
            ("Alice", "[email protected]", "Admin"),
            ("Bob", "[email protected]", "User"),
            ("Charlie", "[email protected]", "User"),
        ])
```

## Dependencies

```toml
[project]
dependencies = [
    "textual>=0.40.0",
]

[project.optional-dependencies]
dev = [
    "textual-dev>=1.0.0",
]
```

## Target Processes

- tui-application-framework
- interactive-form-implementation
- dashboard-monitoring-tui

Overview

This skill generates a complete Textual (Python) TUI application scaffold including app entry, screens, widgets, and CSS styling. It produces idiomatic async-ready structures, reactive widgets, and testing hooks so you can rapidly prototype or ship terminal UIs. The output is ready to drop into a Python project and extend with business logic.

How this skill works

The skill analyzes input parameters (projectName, screens, widgets) and emits Python modules for the main App, Screen classes, custom Widget classes, and a styles.tcss file. It wires reactive attributes, message patterns, and component composition so screens and widgets communicate predictably. It also provides example DataTable usage and optional textual.testing setup to accelerate testability.

When to use it

  • Start a new Textual-based terminal UI project in Python
  • Scaffold multi-screen TUI applications with navigation and layout
  • Create custom reactive widgets with message events
  • Bootstrap styling using CSS variables and theme-aware selectors
  • Generate testable components and DataTable-driven dashboards

Best practices

  • Define Screen layout and CSS in parallel so structure and style stay synchronized
  • Model component state with reactive attributes and send typed Message classes for events
  • Keep widgets focused: single responsibility for rendering and event propagation
  • Use CSS variables for theme colors to enable dark/light toggles consistently
  • Add textual.testing scaffolds and simple mount tests for each screen/widget

Example use cases

  • Admin dashboard showing tables, filters, and status panels for monitoring services
  • Interactive form-driven CLI tools with validation and keyboard shortcuts
  • Small terminal apps like timers, counters, or note managers using custom widgets
  • Data exploration TUI that lists rows in a DataTable with selectable detail screens
  • Prototype an operator console with header/footer and toggleable dark mode

FAQ

What inputs are required?

Provide projectName. screens and widgets are optional arrays describing screen/widget names, elements, and props.

Does the scaffold include styling?

Yes. It generates a styles.tcss with global rules, component selectors, and example utility classes for error/success states.

Is generated code testable?

Yes. The scaffold includes patterns compatible with textual.testing and suggests dev dependencies to run component tests.