Skip to content

Textual Adapters

Widget adapters live under lazy_cuh.widgets. They render existing pure models and emit framework messages upward.

from rich.text import Text
from lazy_cuh import ListViewModel, NavigableItem, TextViewModel, TextViewSpec, WrapMode
from lazy_cuh.widgets import ListViewWidget, TextViewWidget
model = ListViewModel(
items=(NavigableItem(id="one", label=Text("first")),),
)
widget = ListViewWidget(model)
text_widget = TextViewWidget(
TextViewModel(
"read-only output",
spec=TextViewSpec(width=40, wrap_mode=WrapMode.WRAP),
)
)

Adapters should stay thin:

  • semantic state belongs in lazy-cuh models or downstream app controllers
  • key handling should map to framework events or commands
  • Textual lifecycle code should not duplicate render or navigation logic

Current adapters cover keybars, list views, tree views, read-only text views, shell panel/tab synchronization, and modal flows.

The widget package intentionally exposes a small set of Textual-facing pieces:

  • widgets: KeybarWidget, ListViewWidget, TreeViewWidget, TextViewWidget, and ModalWidget
  • host/adapters: ModalHost and ShellViewAdapter
  • adapter specs: PanelWidgetSpec and ContentWidgetSpec
  • widget messages: ItemActionMessage, ItemHighlightedMessage, ItemSelectedMessage, and ModalResultMessage
  • widget action enum: NavigableAction

The package also exposes render_model_lines(), render_tree_lines(), and render_text_lines() for custom Textual adapters that want to reuse the same model-to-Text bridge without subclassing the built-in widgets. center_modal_offset() is a low-level layout helper for modal-like adapters.

Everything under lazy_cuh.widgets may import Textual. Pure app state, commands, action metadata, panel specs, and view models should come from the root package or focused non-widget packages.

lazy_cuh.styles.LAZY_CUH_CSS contains the default transparent terminal-style Textual CSS used by the bundled examples. Apps can compose it with their own layout rules:

from lazy_cuh.styles import LAZY_CUH_CSS
class Demo(App):
CSS = LAZY_CUH_CSS + """
#main {
height: 1fr;
}
"""

The shared CSS should hold framework defaults such as transparent backgrounds, scrollbar colors, and keybar text color. App-specific dimensions, panel IDs, and layout rules should stay in the app.