feat: simplify theme usage with bundled theme names#231
Conversation
Allow users to specify themes by name instead of full path: ralph-tui run --theme dracula Changes: - Add resolveThemePath() to detect theme names vs file paths - Rename themes: bright-theme.json -> bright.json, high-contrast-theme.json -> high-contrast.json - Add new bundled themes: catppuccin, dracula, solarized-light - Update CLI help text and documentation - Bump version to 0.6.0
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
WalkthroughAdds bundled theme support and three new theme JSON assets; theme loading now accepts either a bundled theme name or a filesystem path via Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ThemeResolver
participant FS as FileSystem
participant App as TUI
User->>CLI: run command with --theme "dracula" or "/path/to/theme.json"
CLI->>ThemeResolver: loadThemeFile(themeInput)
ThemeResolver->>ThemeResolver: resolveThemePath(themeInput)
alt Bundled name
ThemeResolver->>FS: read <themes_dir>/dracula.json
FS-->>ThemeResolver: theme JSON
else File path
ThemeResolver->>FS: read "/path/to/theme.json"
FS-->>ThemeResolver: theme JSON
end
ThemeResolver->>ThemeResolver: validate & merge with defaults
ThemeResolver-->>CLI: ThemeColors
CLI->>App: initializeTheme(ThemeColors)
App-->>User: start TUI with selected theme
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #231 +/- ##
==========================================
+ Coverage 45.07% 45.10% +0.02%
==========================================
Files 84 84
Lines 24402 24437 +35
==========================================
+ Hits 11000 11023 +23
- Misses 13402 13414 +12
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/tui/theme.ts`:
- Around line 389-405: The bundled-theme detection in getThemesDir uses a
POSIX-only '/dist/' substring check on currentDir; update it to a
path-segment-aware check so it works on Windows (backslashes) too: use
path.sep-aware comparisons or path methods to detect a 'dist' segment (e.g.,
split currentDir by path.sep and check if any segment === 'dist', or use
path.basename(currentDir) === 'dist' or currentDir.endsWith(`${path.sep}dist`)).
Modify the if that references currentDir.includes('/dist/') ||
currentDir.endsWith('/dist') to use one of these path-segment checks while
keeping the rest of getThemesDir and its return paths unchanged; refer to the
getThemesDir function and currentDir variable when making the change.
🧹 Nitpick comments (2)
src/tui/theme.ts (1)
407-430: Provide a clearer error for unknown bundled names.
Fail fast with a message listing valid options when a simple name is not inBUNDLED_THEMES, rather than a file‑not‑found path error.♻️ Optional refactor
if (isSimpleName) { + if (!BUNDLED_THEMES.includes(themeInput as BundledThemeName)) { + throw new Error( + `Unknown bundled theme '${themeInput}'. Available themes: ${BUNDLED_THEMES.join(', ')}` + ); + } // Resolve as bundled theme const themesDir = getThemesDir(); return join(themesDir, `${themeInput}.json`); }src/commands/run.tsx (1)
358-358: Avoid duplicating bundled theme names in help text.
Optional: derive the list fromBUNDLED_THEMESto prevent drift when themes change.♻️ Optional refactor
-import { initializeTheme } from '../tui/theme.js'; +import { initializeTheme, BUNDLED_THEMES } from '../tui/theme.js';export function printRunHelp(): void { - console.log(` + const bundledThemes = BUNDLED_THEMES.join(', '); + console.log(` @@ - --theme <name|path> Theme name (bright, catppuccin, dracula, high-contrast, solarized-light) or path to custom JSON theme file + --theme <name|path> Theme name (${bundledThemes}) or path to custom JSON theme file
Use path.sep to split the directory path into segments and check if 'dist' is among them, instead of POSIX-only substring matching.
Add tests for: - BUNDLED_THEMES constant (contains all 5 theme names) - resolveThemePath() function (theme name vs file path detection) - Loading bundled themes by name (dracula, catppuccin, etc.) - initializeTheme with bundled theme names Achieves 98.37% line coverage on theme.ts (up from ~58%).
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/tui/theme.test.ts`:
- Around line 827-833: The test's suffix assertion is OS-dependent; update the
'resolves relative path from cwd' test to build an OS-agnostic expected suffix
(e.g., use Node's path.join('themes', 'custom.json') or path.sep to construct
expectedSuffix) and assert against that instead of the hardcoded
'themes/custom.json'; import or reference the path module and use
resolveThemePath and expectedSuffix (or normalize both strings) so the assertion
works on Windows and POSIX systems.
feat: simplify theme usage with bundled theme names
Summary
-themesuffix)Usage
Bundled Themes
brightcatppuccindraculahigh-contrastsolarized-lightTest plan
ralph-tui run --theme draculaand verify theme loadsralph-tui run --theme catppuccinand verify theme loadsralph-tui run --theme solarized-lightand verify light theme renders correctlyralph-tui run --theme ./assets/themes/bright.jsonto verify full paths still work--helpshows updated theme documentationSummary by CodeRabbit
New Features
Documentation
Tests
Version
✏️ Tip: You can customize this high-level summary in your review settings.