feat(tui): implement live theme preview system#125
Merged
Conversation
Greptile OverviewGreptile SummaryThis PR successfully implements a live theme preview system for the TUI, allowing users to see theme changes in real-time before committing to them. Key Changes
Implementation QualityThe implementation is clean and well-structured:
The code follows existing patterns in the codebase and integrates seamlessly with the modal stack system. Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/cortex-tui/src/app/state.rs | Added preview_theme field and helper methods for theme preview state management - clean implementation |
| src/cortex-tui/src/modal/mod.rs | Added ActionContinue variant and new theme action types to enable live preview without closing modal |
| src/cortex-tui/src/modal/theme.rs | Implemented live preview with color swatches, updated tests to verify preview behavior - comprehensive implementation |
| src/cortex-tui/src/runner/event_loop/modal.rs | Implemented handlers for PreviewTheme, RevertTheme, and ConfirmTheme actions with proper state management |
Sequence Diagram
sequenceDiagram
participant User
participant ThemeSelectorModal
participant ModalStack
participant EventLoop
participant AppState
participant ThemeColors
User->>ThemeSelectorModal: Open /themes
Note over ThemeSelectorModal: Stores original_theme<br/>for potential revert
User->>ThemeSelectorModal: Press Down Arrow
ThemeSelectorModal->>ThemeSelectorModal: navigate_down()
ThemeSelectorModal->>ModalStack: ModalResult::ActionContinue(<br/>PreviewTheme("light"))
ModalStack->>EventLoop: process_modal_action(<br/>PreviewTheme("light"))
EventLoop->>AppState: start_theme_preview("light")
AppState->>AppState: set_preview_theme(Some("light"))
AppState->>ThemeColors: ThemeColors::from_name("light")
ThemeColors-->>AppState: Updated colors
Note over AppState: preview_theme = Some("light")<br/>theme_colors updated
AppState-->>User: TUI updates with<br/>light theme colors
User->>ThemeSelectorModal: Press Up Arrow
ThemeSelectorModal->>ThemeSelectorModal: navigate_up()
ThemeSelectorModal->>ModalStack: ModalResult::ActionContinue(<br/>PreviewTheme("dark"))
ModalStack->>EventLoop: process_modal_action(<br/>PreviewTheme("dark"))
EventLoop->>AppState: start_theme_preview("dark")
AppState->>ThemeColors: ThemeColors::from_name("dark")
ThemeColors-->>AppState: Updated colors
AppState-->>User: TUI updates with<br/>dark theme colors
alt User confirms selection
User->>ThemeSelectorModal: Press Enter
ThemeSelectorModal->>ModalStack: ModalResult::Action(<br/>ConfirmTheme("dark"))
ModalStack->>ModalStack: pop() - closes modal
ModalStack->>EventLoop: process_modal_action(<br/>ConfirmTheme("dark"))
EventLoop->>AppState: set_theme("dark")
Note over AppState: active_theme = "dark"<br/>preview_theme = None
EventLoop->>EventLoop: Persist to config
EventLoop-->>User: Toast: "Theme changed to: dark"
else User cancels
User->>ThemeSelectorModal: Press Esc
ThemeSelectorModal->>ModalStack: ModalResult::Action(<br/>RevertTheme)
ModalStack->>ModalStack: pop() - closes modal
ModalStack->>EventLoop: process_modal_action(<br/>RevertTheme)
EventLoop->>AppState: cancel_theme_preview()
AppState->>AppState: set_preview_theme(None)
AppState->>ThemeColors: ThemeColors::from_name(<br/>original active_theme)
ThemeColors-->>AppState: Restored colors
Note over AppState: preview_theme = None<br/>Colors reverted to original
AppState-->>User: TUI reverts to<br/>original theme
end
- Add preview_theme field to AppState for temporary theme previews - Add set_preview_theme, get_effective_theme_colors, start_theme_preview, cancel_theme_preview, and confirm_theme_preview methods - Add ModalResult::ActionContinue for live preview without closing modal - Add ModalAction variants: PreviewTheme, RevertTheme, ConfirmTheme - Update ThemeSelectorModal to emit preview actions on navigation - Add color swatch display in theme selector rows - Handle new theme actions in event loop - Update ThemePicker to use ThemeSelectorModal instead of interactive builder - Add comprehensive tests for new preview functionality
aa6f3a5 to
abe702a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a live theme preview system to the TUI, allowing users to preview theme colors in real-time before confirming their selection.
Changes
preview_themefield to AppState for temporary theme previewsset_preview_theme,get_effective_theme_colors,start_theme_preview,cancel_theme_preview,confirm_theme_previewModalResult::ActionContinuevariant for live preview without closing modalModalActionvariants:PreviewTheme,RevertTheme,ConfirmThemeThemeSelectorModalto emit preview actions on navigation (Up/Down keys)ThemeSelectorModalinstead of interactive builderHow it works
/themescommandTesting