📚 coms-tui

@sullux/coms-tui

A lightweight, zero-dependency, purely functional Textual User Interface (TUI) console for the Coms platform.

Designed around standard Unix pipeline methodologies and modern reactive patterns (similar to Elm or React's functional loops), the console provides a high-performance, double-buffered screen rendering experience with absolutely zero screen flicker and a zero-class, zero-this implementation footprint.

Core Architectural Design

Unlike conventional OOP terminal dashboards that inherit from complex stateful components (like pi-tui or blessed), @sullux/coms-tui operates as a strict state machine of pure functions:

  1. State: A plain, immutable-by-convention JavaScript object carrying contacts, sorted conversations, message logs, selected threads, and input fields.
  2. State Updates: A pure functional reducer function (updateStateWithEvent(state, event)) that merges incoming Event Lake schema envelopes into the app state chronologically.
  3. Pure Projection Views: A pure layout builder (renderApp(state, width, height)) that maps the state object directly onto a 2D coordinate cell array of size [height][width].
  4. Double-Buffered Blitter (ScreenRenderer): A custom renderer that compares the newly computed 2D cell grid with the previous frame's grid. It only emits standard ANSI escape sequences to reposition the cursor and overwrite characters where cell changes actually exist. This eliminates terminal flicker and minimizes IPC stream congestion over standard SSH or serial shells.

Folder Topography

packages/coms-tui/
├── bin/
│   └── tui.js           # Executable entrypoint (raw keybindings, socket links, and render loop)
├── lib/
│   ├── app.js           # Pure functional layout builders and state event updates
│   └── renderer.js      # Double-buffered screen manager and functional grid primitives
└── package.json         # Workspace manifest

Running the Terminal Console

Ensure that the central Event Lake is running and accessible (defaulting to /tmp/coms-lake.sock):

# Start the central Event Lake server first (if not already running)
yarn workspace @sullux/coms-lake start

# Launch the interactive terminal console
yarn workspace @sullux/coms-tui start

Shortcuts & Controls

  • Tab: Switch focus between the Left Sidebar (Conversations) and the Bottom Input Box (Reply).
  • Up / Down Arrow keys (while focused on Left Sidebar): Navigate through chronological conversations. Selecting a thread immediately marks it as read and populates the right panel with its corresponding messages.
  • Enter (while focused on Bottom Input Box): Publishes the typed message as a coms.interaction.emitted event to the local Event Lake (which any active email/Slack connector daemons will pick up and dispatch instantly).
  • Ctrl + Q or Ctrl + C: Cleanly restores normal terminal scrollback buffers, reveals the standard hardware cursor, and exits the process.

Theme And Styling

Developer note: see the LCARS Web Theme for inspiration.