Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | "use client" |
| 2 | |
| 3 | import { |
| 4 | TERMINAL_THEMES, |
| 5 | type TerminalTheme, |
| 6 | } from "@/lib/terminal-themes" |
| 7 | import * as React from "react" |
| 8 | |
| 9 | function readThemeFromElement(element: Element | null): TerminalTheme { |
| 10 | if (!element) return "default" |
| 11 | |
| 12 | for (const theme of TERMINAL_THEMES) { |
| 13 | if (theme === "default") continue |
| 14 | if (element.classList.contains(`terminal-theme-${theme}`)) return theme |
| 15 | } |
| 16 | |
| 17 | return "default" |
| 18 | } |
| 19 | |
| 20 | /** Reads the active palette from the nearest `.terminal-theme` ancestor. */ |
| 21 | export function useDetectedTerminalTheme() { |
| 22 | const ref = React.useRef<HTMLDivElement>(null) |
| 23 | const [theme, setTheme] = React.useState<TerminalTheme>("default") |
| 24 | |
| 25 | React.useLayoutEffect(() => { |
| 26 | const root = ref.current?.closest(".terminal-theme") |
| 27 | if (!root) { |
| 28 | setTheme("default") |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | const sync = () => setTheme(readThemeFromElement(root)) |
| 33 | sync() |
| 34 | |
| 35 | const observer = new MutationObserver(sync) |
| 36 | observer.observe(root, { attributes: true, attributeFilter: ["class"] }) |
| 37 | return () => observer.disconnect() |
| 38 | }, []) |
| 39 | |
| 40 | return { ref, theme } |
| 41 | } |