MCPcopy Create free account
hub / github.com/anus-dev/ANUS / useThemeCommand

Function useThemeCommand

packages/cli/src/ui/hooks/useThemeCommand.ts:24–111  ·  view source on GitHub ↗
(
  loadedSettings: LoadedSettings,
  setThemeError: (error: string | null) => void,
  addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void,
)

Source from the content-addressed store, hash-verified

22}
23
24export const useThemeCommand = (
25 loadedSettings: LoadedSettings,
26 setThemeError: (error: string | null) => void,
27 addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void,
28): UseThemeCommandReturn => {
29 const [isThemeDialogOpen, setIsThemeDialogOpen] = useState(false);
30
31 // Check for invalid theme configuration on startup
32 useEffect(() => {
33 const effectiveTheme = loadedSettings.merged.theme;
34 if (effectiveTheme && !themeManager.findThemeByName(effectiveTheme)) {
35 setIsThemeDialogOpen(true);
36 setThemeError(`Theme "${effectiveTheme}" not found.`);
37 } else {
38 setThemeError(null);
39 }
40 }, [loadedSettings.merged.theme, setThemeError]);
41
42 const openThemeDialog = useCallback(() => {
43 if (process.env['NO_COLOR']) {
44 addItem(
45 {
46 type: MessageType.INFO,
47 text: 'Theme configuration unavailable due to NO_COLOR env variable.',
48 },
49 Date.now(),
50 );
51 return;
52 }
53 setIsThemeDialogOpen(true);
54 }, [addItem]);
55
56 const applyTheme = useCallback(
57 (themeName: string | undefined) => {
58 if (!themeManager.setActiveTheme(themeName)) {
59 // If theme is not found, open the theme selection dialog and set error message
60 setIsThemeDialogOpen(true);
61 setThemeError(`Theme "${themeName}" not found.`);
62 } else {
63 setThemeError(null); // Clear any previous theme error on success
64 }
65 },
66 [setThemeError],
67 );
68
69 const handleThemeHighlight = useCallback(
70 (themeName: string | undefined) => {
71 applyTheme(themeName);
72 },
73 [applyTheme],
74 );
75
76 const handleThemeSelect = useCallback(
77 (themeName: string | undefined, scope: SettingScope) => {
78 try {
79 // Merge user and workspace custom themes (workspace takes precedence)
80 const mergedCustomThemes = {
81 ...(loadedSettings.user.settings.customThemes || {}),

Callers 1

AppFunction · 0.85

Calls 4

findThemeByNameMethod · 0.80
setActiveThemeMethod · 0.80
loadCustomThemesMethod · 0.80
setValueMethod · 0.45

Tested by

no test coverage detected