UNPKG

buroventures-harald-code

Version:

Harald Code - AI-powered coding assistant CLI

79 lines 3.28 kB
/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { useState, useCallback, useEffect } from 'react'; import { themeManager } from '../themes/theme-manager.js'; import { MessageType } from '../types.js'; import process from 'node:process'; export const useThemeCommand = (loadedSettings, setThemeError, addItem) => { const [isThemeDialogOpen, setIsThemeDialogOpen] = useState(false); // Check for invalid theme configuration on startup useEffect(() => { const effectiveTheme = loadedSettings.merged.theme; if (effectiveTheme && !themeManager.findThemeByName(effectiveTheme)) { setIsThemeDialogOpen(true); setThemeError(`Theme "${effectiveTheme}" not found.`); } else { setThemeError(null); } }, [loadedSettings.merged.theme, setThemeError]); const openThemeDialog = useCallback(() => { if (process.env.NO_COLOR) { addItem({ type: MessageType.INFO, text: 'Theme configuration unavailable due to NO_COLOR env variable.', }, Date.now()); return; } setIsThemeDialogOpen(true); }, [addItem]); const applyTheme = useCallback((themeName) => { if (!themeManager.setActiveTheme(themeName)) { // If theme is not found, open the theme selection dialog and set error message setIsThemeDialogOpen(true); setThemeError(`Theme "${themeName}" not found.`); } else { setThemeError(null); // Clear any previous theme error on success } }, [setThemeError]); const handleThemeHighlight = useCallback((themeName) => { applyTheme(themeName); }, [applyTheme]); const handleThemeSelect = useCallback((themeName, scope) => { try { // Merge user and workspace custom themes (workspace takes precedence) const mergedCustomThemes = { ...(loadedSettings.user.settings.customThemes || {}), ...(loadedSettings.workspace.settings.customThemes || {}), }; // Only allow selecting themes available in the merged custom themes or built-in themes const isBuiltIn = themeManager.findThemeByName(themeName); const isCustom = themeName && mergedCustomThemes[themeName]; if (!isBuiltIn && !isCustom) { setThemeError(`Theme "${themeName}" not found in selected scope.`); setIsThemeDialogOpen(true); return; } loadedSettings.setValue(scope, 'theme', themeName); // Update the merged settings if (loadedSettings.merged.customThemes) { themeManager.loadCustomThemes(loadedSettings.merged.customThemes); } applyTheme(loadedSettings.merged.theme); // Apply the current theme setThemeError(null); } finally { setIsThemeDialogOpen(false); // Close the dialog } }, [applyTheme, loadedSettings, setThemeError]); return { isThemeDialogOpen, openThemeDialog, handleThemeSelect, handleThemeHighlight, }; }; //# sourceMappingURL=useThemeCommand.js.map