mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
23 lines
826 B
TypeScript
23 lines
826 B
TypeScript
import type { Attention } from "@opencode/plugin/tui/context"
|
|
import { useRenderer } from "@opentui/solid"
|
|
import { createContext, onCleanup, useContext, type ParentProps } from "solid-js"
|
|
import { createTuiAttention } from "../attention"
|
|
import { useConfig } from "../config"
|
|
|
|
const AttentionContext = createContext<Attention>()
|
|
|
|
export function AttentionProvider(props: ParentProps) {
|
|
const config = useConfig()
|
|
const attention = createTuiAttention({
|
|
renderer: useRenderer(),
|
|
config: config.data,
|
|
})
|
|
onCleanup(() => attention.dispose())
|
|
return <AttentionContext.Provider value={attention}>{props.children}</AttentionContext.Provider>
|
|
}
|
|
|
|
export function useAttention() {
|
|
const attention = useContext(AttentionContext)
|
|
if (!attention) throw new Error("AttentionProvider is missing")
|
|
return attention
|
|
}
|