({
onSelect,
onHighlight,
settings,
availableTerminalHeight,
terminalWidth,
}: ThemeDialogProps)
| 32 | } |
| 33 | |
| 34 | export function ThemeDialog({ |
| 35 | onSelect, |
| 36 | onHighlight, |
| 37 | settings, |
| 38 | availableTerminalHeight, |
| 39 | terminalWidth, |
| 40 | }: ThemeDialogProps): React.JSX.Element { |
| 41 | const [selectedScope, setSelectedScope] = useState<SettingScope>( |
| 42 | SettingScope.User, |
| 43 | ); |
| 44 | |
| 45 | // Track the currently highlighted theme name |
| 46 | const [highlightedThemeName, setHighlightedThemeName] = useState< |
| 47 | string | undefined |
| 48 | >(settings.merged.theme || DEFAULT_THEME.name); |
| 49 | |
| 50 | // Generate theme items filtered by selected scope |
| 51 | const customThemes = |
| 52 | selectedScope === SettingScope.User |
| 53 | ? settings.user.settings.customThemes || {} |
| 54 | : settings.merged.customThemes || {}; |
| 55 | const builtInThemes = themeManager |
| 56 | .getAvailableThemes() |
| 57 | .filter((theme) => theme.type !== 'custom'); |
| 58 | const customThemeNames = Object.keys(customThemes); |
| 59 | const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); |
| 60 | // Generate theme items |
| 61 | const themeItems = [ |
| 62 | ...builtInThemes.map((theme) => ({ |
| 63 | label: theme.name, |
| 64 | value: theme.name, |
| 65 | themeNameDisplay: theme.name, |
| 66 | themeTypeDisplay: capitalize(theme.type), |
| 67 | })), |
| 68 | ...customThemeNames.map((name) => ({ |
| 69 | label: name, |
| 70 | value: name, |
| 71 | themeNameDisplay: name, |
| 72 | themeTypeDisplay: 'Custom', |
| 73 | })), |
| 74 | ]; |
| 75 | const [selectInputKey, setSelectInputKey] = useState(Date.now()); |
| 76 | |
| 77 | // Find the index of the selected theme, but only if it exists in the list |
| 78 | const selectedThemeName = settings.merged.theme || DEFAULT_THEME.name; |
| 79 | const initialThemeIndex = themeItems.findIndex( |
| 80 | (item) => item.value === selectedThemeName, |
| 81 | ); |
| 82 | // If not found, fall back to the first theme |
| 83 | const safeInitialThemeIndex = initialThemeIndex >= 0 ? initialThemeIndex : 0; |
| 84 | |
| 85 | const scopeItems = getScopeItems(); |
| 86 | |
| 87 | const handleThemeSelect = useCallback( |
| 88 | (themeName: string) => { |
| 89 | onSelect(themeName, selectedScope); |
| 90 | }, |
| 91 | [onSelect, selectedScope], |
nothing calls this directly
no test coverage detected