2.8 KiB
2.8 KiB
06. Add Theme Loader for JSON Files and Custom Themes
meta: id: theme-refactoring-06 feature: theme-refactoring-json-format priority: P1 depends_on: [theme-refactoring-02, theme-refactoring-04] tags: [implementation, loading]
objective:
- Create theme loader to load JSON theme files
- Support loading custom themes from multiple directories
- Provide API for theme discovery and loading
- Handle theme file validation
deliverables:
src/utils/theme-loader.ts- Theme loader utilitiessrc/utils/custom-themes.ts- Custom theme loading logic
steps:
-
Step 6.1: Create
src/utils/theme-loader.ts- Implement
loadTheme(name: string): Promise<ThemeJson> - Implement
loadThemeFromPath(path: string): Promise<ThemeJson> - Implement
getAllThemes(): Promise<Record<string, ThemeJson>> - Add error handling for missing or invalid theme files
- Implement
-
Step 6.2: Create
src/utils/custom-themes.ts- Implement
getCustomThemes()function - Scan for theme files in multiple directories:
~/.config/podtui/themes/./.podtui/themes/- Project root
./themes/
- Support custom theme files with
.jsonextension - Return merged theme registry
- Implement
-
Step 6.3: Add theme file validation
- Validate theme JSON structure
- Check required properties (
defs,theme) - Validate color references in
defs - Add warning for optional properties
-
Step 6.4: Implement theme discovery
- List all available theme files
- Provide theme metadata (name, description)
- Support theme aliases (e.g., "catppuccin" -> "catppuccin.json")
tests:
-
Unit:
- Test
loadThemewith existing theme files - Test
loadThemewith missing theme files - Test
loadThemeFromPathwith custom paths - Test
getAllThemesreturns all available themes - Test
getCustomThemesscans multiple directories - Test theme file validation
- Test
-
Integration/e2e:
- Test loading all available themes
- Test custom theme loading from directories
- Verify theme discovery works correctly
acceptance_criteria:
src/utils/theme-loader.tsfile exists with loading functionssrc/utils/custom-themes.tsfile exists with custom theme logic- Custom themes can be loaded from multiple directories
- Theme validation prevents invalid files
- Theme discovery API is functional
validation:
- Run:
bun run typecheck- Should pass - Run:
bun test src/utils/theme-loader.test.ts - Run:
bun test src/utils/custom-themes.test.ts - Test loading all available themes manually
- Test custom theme loading from directories
notes:
- Use opencode's
getCustomThemespattern as reference - Support both local and global theme directories
- Add comprehensive error messages for invalid theme files
- Reference:
/home/mike/code/PodTui/opencode/packages/opencode/src/cli/cmd/tui/context/theme.tsx(lines 394-419)