Skip to content

feat(tui): add cortex-tui-components crate for standardized UI components#467

Merged
echobt merged 1 commit intomasterfrom
feature/cortex-tui-components
Jan 28, 2026
Merged

feat(tui): add cortex-tui-components crate for standardized UI components#467
echobt merged 1 commit intomasterfrom
feature/cortex-tui-components

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Jan 28, 2026

Summary

Create a new cortex-tui-components crate that provides reusable, high-level TUI components built on top of cortex-core's theme system.

Motivation

The existing TUI code has 100+ direct ratatui imports with redundant patterns for dropdowns, scrolling lists, borders, and input handling. This library consolidates those patterns into standardized, reusable components.

Key Features

Component Trait System

Unified interface for all interactive components:

pub trait Component {
    type Output;
    fn render(&self, area: Rect, buf: &mut Buffer);
    fn handle_key(&mut self, key: KeyEvent) -> ComponentResult<Self::Output>;
    fn focus_state(&self) -> FocusState;
    fn key_hints(&self) -> Vec<(&'static str, &'static str)>;
}

20+ Reusable Modules

Module Description
borders 4 border styles (Rounded, Single, Double, ASCII) with RoundedBorder widget
focus FocusManager for tab navigation with wrap-around
scroll ScrollState and scrollbar rendering utilities
key_hints KeyHintsBar for displaying keyboard shortcuts
text StyledText builder and TextStyle presets
input TextInput with grapheme-aware cursor positioning
selector Full-featured selection list with search, shortcuts, disabled items
form 5 field types: Text, Secret, Number, Toggle, Select
modal ModalStack for nested dialogs
dropdown Dropdown state and rendering
checkbox Checkbox component
radio Radio button group
list Simple list with selection
toast Toast notifications with auto-expiry
spinner Loading spinners with multiple styles
panel Slide-in panels (left/right)
popup Popup positioning utilities
card Card container with title and hints

Theme Integration

Uses cortex-core's Ocean/Cyan theme constants:

  • CYAN_PRIMARY, BORDER, BORDER_FOCUS
  • SURFACE_0, SURFACE_1, SURFACE_2
  • TEXT, TEXT_DIM, TEXT_MUTED

Testing

  • 73 unit tests covering all major components
  • All tests pass
  • cargo check and cargo fmt clean

Future Work

Gradually migrate existing TUI widgets to use these components to reduce code duplication.

Checklist

  • Code compiles (cargo check)
  • Tests pass (cargo test -p cortex-tui-components)
  • Formatted (cargo fmt)
  • No breaking changes to existing code

…ents

Create a new component library crate that provides reusable, high-level
TUI components built on top of cortex-core's theme system.

## Key Features

- **Component Trait System**: Unified interface for all interactive
  components with render(), handle_key(), focus_state(), and key_hints()

- **20+ Reusable Modules**:
  - borders: 4 border styles (Rounded, Single, Double, ASCII)
  - focus: FocusManager for tab navigation
  - scroll: ScrollState and scrollbar rendering
  - key_hints: KeyHintsBar for keyboard shortcuts
  - text: StyledText builder and TextStyle presets
  - input: TextInput with grapheme-aware cursor
  - selector: Full-featured selection list with search
  - form: 5 field types (Text, Secret, Number, Toggle, Select)
  - modal: ModalStack for nested dialogs
  - dropdown, checkbox, radio, list, toast, spinner, panel, popup, card

- **Theme Integration**: Uses cortex-core's Ocean/Cyan theme constants

- **73 Unit Tests**: Comprehensive test coverage

This library is designed to reduce raw ratatui usage and code duplication
across the TUI, making it easier to build consistent interfaces.
@echobt echobt merged commit d96832b into master Jan 28, 2026
4 checks passed
@echobt echobt deleted the feature/cortex-tui-components branch January 28, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants