Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Gaurav-Gosain/tuios/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TUIOS is built on the Model-View-Update (MVU) pattern using Bubble Tea v2, providing a clean separation between state, rendering, and event handling. The architecture follows a layered design with distinct responsibilities for window management, terminal emulation, and rendering.MVU Pattern
The core application follows Bubble Tea’s Model-View-Update pattern:Model
TheOS struct in internal/app/os.go represents the entire application state:
- Windows: Collection of terminal window instances
- Workspaces: 9 independent virtual desktops
- Mode: Modal interaction (Window Management vs Terminal)
- Animations: Active window animations
- Notifications: Temporary UI messages
View
OS.View() in internal/app/render.go generates the visual output:
internal/app/render.go:146-186 for the full implementation.
Update
OS.Update() in internal/app/update.go handles all events:
internal/app/update.go:1-100 for event routing logic.
Directory Structure
Key Technologies
Bubble Tea v2
MVU framework for terminal UIs- Event-driven architecture
- Declarative view rendering
- Built-in mouse and keyboard support
- Alt-screen and focus reporting
charm.land/bubbletea/v2
Lipgloss v2
Styling and layout- Style composition and caching
- Border rendering
- Color management (ANSI, RGB, truecolor)
- Canvas-based layer composition
charm.land/lipgloss/v2
Wish v2
SSH server framework- Per-session isolation
- Middleware-based architecture
- Built on Bubble Tea
- Automatic PTY allocation
charm.land/wish/v2
See internal/server/ssh.go for SSH implementation.
go-pty (xpty)
Cross-platform PTY support- Unix:
/dev/ptmxwith termios - Windows: ConPTY API
- Automatic shell detection
- Window size (SIGWINCH) handling
internal/terminal/pty_unix.go and pty_windows.go.
Ultraviolet
Terminal emulation base- VT100/ANSI parser
- Screen buffer management
- CSI sequence handling
- Scrollback support
github.com/charmbracelet/ultraviolet
Data Flow
Input Flow
Terminal Mode: Events forwarded directly to the focused window’s PTY. Window Management Mode: Events trigger window operations (create, close, focus, snap, resize). Seeinternal/input/handler.go:19-83 for routing logic.
Output Flow
Polling goroutines continuously read from PTY and feed bytes to the VT emulator. Seeinternal/terminal/window.go and internal/vt/emulator.go.
Rendering Pipeline
- Viewport Culling: Skip off-screen windows (
internal/app/render.go:57-64) - Cache Check: Reuse cached layers if content unchanged (
render.go:83-86) - Content Rendering: Build cell content from VT buffer (
render.go:99) - Style Application: Apply cached Lipgloss styles (
internal/app/stylecache.go:120-153) - Layer Composition: Stack by Z-index with Lipgloss compositor (
render.go:142) - Overlay Addition: Dock, status bar, notifications (
render.go:133-140)
Modal System
TUIOS uses two primary modes for input handling:Window Management Mode
Default mode for window manipulation:- Create/close windows
- Focus navigation
- Drag and resize with mouse
- Workspace switching
- Tiling commands
Ctrl+B by default) activates sub-modes:
Ctrl+B, w: Workspace prefixCtrl+B, m: Minimize prefixCtrl+B, t: Tiling prefix
internal/input/keyboard.go for keybinding implementation.
Terminal Mode
Activated when a window is focused (pressi or click window content):
- All input forwarded to focused window’s PTY
Ctrl+Bprefix still accessible for TUIOS commands- Mouse events passed through to terminal (if app supports mouse mode)
Esc to return to Window Management Mode.
Thread Safety
Bubble Tea provides a single-threaded event loop, but TUIOS has concurrent components:PTY Polling Goroutines
Per-window goroutines read from PTY and update VT emulator:internal/terminal/window.go for PTY lifecycle.
Channel-Based Communication
For daemon mode, channels pass messages to the event loop:StateSyncChan: State updates from other clientsClientEventChan: Client join/leave eventsWindowExitChan: PTY exit signals
internal/app/os.go:114-115 for channel definitions.
Related Documentation
- Components - Core component details
- Performance - Optimization techniques
- Configuration - Customization options