Merge branch 'v2' into oc-resolve-model

This commit is contained in:
Simon Klee 2026-07-28 20:56:05 +02:00 committed by GitHub
commit c3820b4462
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
75 changed files with 2328 additions and 1682 deletions

View file

@ -0,0 +1,24 @@
import type { Attention } from "@opencode-ai/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,
update: config.update,
})
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
}

View file

@ -1,4 +1,4 @@
import type { KeymapCommand, KeymapLayer } from "@opencode-ai/plugin/tui/context"
import type { KeymapActive, KeymapCommand, KeymapLayer, KeymapPending } from "@opencode-ai/plugin/tui/context"
import { InputRenderable, TextareaRenderable, type KeyEvent, type Renderable } from "@opentui/core"
import { stringifyKeyStroke, type Binding, type CommandContext } from "@opentui/keymap"
import {
@ -255,13 +255,19 @@ function useShortcuts() {
const commands = keymap.getCommands({ visibility: "registered" }).map((command) => command.name)
const bindings = keymap.getCommandBindings({ visibility: "registered", commands })
return new Map(
commands.map((id) => [
id,
{
first: formatKeySequence(bindings.get(id)?.[0]?.sequence, formatOptions(value.config)),
all: formatCommandBindings(bindings.get(id) ?? [], formatOptions(value.config)),
},
]),
commands.map((id) => {
const current = bindings.get(id) ?? []
return [
id,
{
first: formatKeySequence(current[0]?.sequence, formatOptions(value.config)),
all: formatCommandBindings(current, formatOptions(value.config)),
list: current
.map((binding) => formatKeySequence(binding.sequence, formatOptions(value.config)))
.filter((shortcut): shortcut is string => shortcut !== undefined),
},
]
}),
)
})
return {
@ -271,6 +277,9 @@ function useShortcuts() {
all(id: string) {
return shortcuts().get(id)?.all
},
list(id: string) {
return shortcuts().get(id)?.list ?? []
},
}
}
@ -328,6 +337,41 @@ function useActiveKeys() {
return useKeymapSelector((keymap) => keymap.getActiveKeys({ includeMetadata: true }))
}
function useState() {
const value = useValue()
const commands = useCommands()
const pending = usePendingSequence()
const active = useActiveKeys()
return {
commands,
pending: (): readonly KeymapPending[] =>
pending().map((item) => ({
key: formatKeySequence([item], formatOptions(value.config)) ?? "",
...(item.tokenName ? { token: item.tokenName } : {}),
})),
active: (): readonly KeymapActive[] =>
active().map((item) => ({
key:
formatKeySequence(
[{ stroke: item.stroke, display: item.display, tokenName: item.tokenName }],
formatOptions(value.config),
) ?? "",
...(typeof item.commandAttrs?.title === "string" ? { title: item.commandAttrs.title } : {}),
...(typeof item.bindingAttrs?.desc === "string"
? { description: item.bindingAttrs.desc }
: typeof item.commandAttrs?.desc === "string"
? { description: item.commandAttrs.desc }
: {}),
...(typeof item.commandAttrs?.category === "string"
? { group: item.commandAttrs.category }
: typeof item.bindingAttrs?.group === "string"
? { group: item.bindingAttrs.group }
: {}),
continues: item.continues,
})),
}
}
function useValue() {
const value = useContext(Context)
if (!value) throw new Error("Keymap.Provider is missing")
@ -344,6 +388,7 @@ export const Keymap = {
useCommands,
usePendingSequence,
useActiveKeys,
useState,
} as const
function createMode(keymap: OpenTuiKeymap) {

View file

@ -1,5 +1,6 @@
import { CliRenderEvents, SyntaxStyle, type TerminalColors } from "@opentui/core"
import { useRenderer } from "@opentui/solid"
import { generateSyntax, resolveThemeDocument, themeModes } from "@opencode-ai/theme/tui"
import {
DEFAULT_THEMES,
addTheme,
@ -14,12 +15,9 @@ import {
type Theme,
type ThemeDocumentSource,
} from "../theme"
import { generateSyntax } from "../theme/v2/syntax"
import { generateSystem, terminalMode } from "../theme/system"
import { discoverThemes, themeDirectories } from "../theme/discovery"
import { createComponentTheme, type ComponentTheme } from "../theme/v2/component"
import { resolveThemeDocument } from "../theme/v2/resolve"
import { themeModes } from "../theme/v2/select"
import { createComponentTheme, type ComponentTheme } from "../theme/component"
import { createEffect, createMemo, onCleanup, onMount, type Accessor, type ParentProps } from "solid-js"
import { createStore, produce } from "solid-js/store"
import { createSimpleContext } from "./helper"