Download packages/tui/src/context/runtime.tsx from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/context/runtime.tsx
- Command line
-
hf download hf://SaylorTwift/opencode/packages/tui/src/context/runtime.tsx
-
curl -L -o runtime.tsx https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/context/runtime.tsx
1.86 kB
| import { createComponent, createContext, type JSX, useContext } from "solid-js" | |
| export type TuiPaths = Readonly<{ | |
| cwd: string | |
| home: string | |
| state: string | |
| worktree: string | |
| }> | |
| export type TuiTerminalEnvironment = Readonly<{ | |
| platform: string | |
| multiplexer?: "tmux" | "screen" | |
| displayServer?: "wayland" | "x11" | |
| }> | |
| export type TuiStartup = Readonly<{ | |
| initialRoute?: unknown | |
| skipInitialLoading: boolean | |
| }> | |
| const PathsContext = createContext<TuiPaths>() | |
| const TerminalEnvironmentContext = createContext<TuiTerminalEnvironment>() | |
| const StartupContext = createContext<TuiStartup>() | |
| function provider<T>(context: ReturnType<typeof createContext<T>>, value: T, children: () => JSX.Element) { | |
| return createComponent(context.Provider, { | |
| value: Object.freeze({ ...value }), | |
| get children() { | |
| return children() | |
| }, | |
| }) | |
| } | |
| export function TuiPathsProvider(props: { value: TuiPaths; children: JSX.Element }) { | |
| return provider(PathsContext, props.value, () => props.children) | |
| } | |
| export function TuiTerminalEnvironmentProvider(props: { value: TuiTerminalEnvironment; children: JSX.Element }) { | |
| return provider(TerminalEnvironmentContext, props.value, () => props.children) | |
| } | |
| export function TuiStartupProvider(props: { value: TuiStartup; children: JSX.Element }) { | |
| return provider(StartupContext, props.value, () => props.children) | |
| } | |
| function required<T>(context: ReturnType<typeof createContext<T>>, name: string) { | |
| const value = useContext(context) | |
| if (!value) throw new Error(`${name} is missing`) | |
| return value | |
| } | |
| export function useTuiPaths() { | |
| return required(PathsContext, "TuiPathsProvider") | |
| } | |
| export function useTuiTerminalEnvironment() { | |
| return required(TerminalEnvironmentContext, "TuiTerminalEnvironmentProvider") | |
| } | |
| export function useTuiStartup() { | |
| return required(StartupContext, "TuiStartupProvider") | |
| } | |