GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode/packages/plugin/src/tui.ts at dev · DavidJFelix/opencode Expand file tree/ Copy pathtui.tsMore file actions 634 lines (568 loc) · 16.3 KB / Copy pathtui.tsFile metadata and controls634 lines (568 loc) · 16.3 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 import type { AgentPart, OpencodeClient, Event, FilePart, LspStatus, McpStatus, Todo, Message, Part, Provider, PermissionRequest, QuestionRequest, Session, SessionStatus, TextPart, Config as SdkConfig, } from "@opencode-ai/sdk/v2" import type { CliRenderer, KeyEvent, RGBA, Renderable, SlotMode } from "@opentui/core" import type { Binding, Keymap } from "@opentui/keymap" import { createBindingLookup as createKeymapBindingLookup, type BindingConfig, type CreateBindingLookupOptions, type KeySequenceFormatPart, type SequenceBindingLike, } from "@opentui/keymap/extras" import type { JSX, SolidPlugin } from "@opentui/solid" import type { Config as PluginConfig, PluginOptions } from "./index.js" export type { CliRenderer, KeyEvent, Renderable, SlotMode } from "@opentui/core" export { stringifyKeySequence, stringifyKeyStroke } from "@opentui/keymap" export type { Binding, KeyLike, KeySequencePart, KeyStringifyInput, StringifyOptions } from "@opentui/keymap" export { formatCommandBindings, formatKeySequence } from "@opentui/keymap/extras" export type { BindingConfig, BindingLookup, BindingValue, CreateBindingLookupOptions, FormatCommandBindingsOptions, FormatKeySequenceOptions, KeySequenceFormatPart, SequenceBindingLike, } from "@opentui/keymap/extras" export function createBindingLookup( config: BindingConfig<Renderable, KeyEvent> | undefined, options?: CreateBindingLookupOptions<Renderable, KeyEvent>, ) { return createKeymapBindingLookup<Renderable, KeyEvent>(config ?? {}, options) } export type TuiRouteCurrent = | { name: "home" } | { name: "session" params: { sessionID: string prompt?: unknown } } | { name: string params?: Record<string, unknown> } export type TuiRouteDefinition = { name: string render: (input: { params?: Record<string, unknown> }) => JSX.Element } export type TuiKeys = { formatSequence: (parts: readonly KeySequenceFormatPart[] | undefined) => string formatBindings: (bindings: readonly SequenceBindingLike[] | undefined) => string | undefined } export type TuiKeymap = Keymap<Renderable, KeyEvent> export type TuiModeApi = { current: () => string push: (mode: string) => () => void } /** * Legacy `api.command` shape kept so v1 plugins can initialize. Remove in v2. * * @deprecated Use `api.keymap.registerLayer({ commands, bindings })` instead. */ export type TuiCommand = { title: string value: string description?: string category?: string keybind?: string suggested?: boolean hidden?: boolean enabled?: boolean slash?: { name: string aliases?: string[] } onSelect?: (dialog?: TuiDialogStack) => void | Promise<void> } /** * Legacy `api.command` API kept so v1 plugins can initialize. Remove in v2. * * @deprecated Use `api.keymap.registerLayer`, `api.keymap.dispatchCommand`, and * `api.keymap.dispatchCommand("command.palette.show")` instead. */ export type TuiCommandApi = { /** @deprecated Use `api.keymap.registerLayer({ commands, bindings })` instead. */ register: (cb: () => TuiCommand[]) => () => void /** @deprecated Use `api.keymap.dispatchCommand(name)` instead. */ trigger: (value: string) => void /** @deprecated Use `api.keymap.dispatchCommand("command.palette.show")` instead. */ show: () => void } export type TuiDialogProps = { size?: "medium" | "large" | "xlarge" onClose: () => void children?: JSX.Element } export type TuiDialogStack = { replace: (render: () => JSX.Element, onClose?: () => void) => void clear: () => void setSize: (size: "medium" | "large" | "xlarge") => void readonly size: "medium" | "large" | "xlarge" readonly depth: number readonly open: boolean } export type TuiDialogAlertProps = { title: string message: string onConfirm?: () => void } export type TuiDialogConfirmProps = { title: string message: string onConfirm?: () => void onCancel?: () => void } export type TuiDialogPromptProps = { title: string description?: () => JSX.Element placeholder?: string value?: string busy?: boolean busyText?: string onConfirm?: (value: string) => void onCancel?: () => void } export type TuiDialogSelectOption<Value = unknown> = { title: string value: Value description?: string footer?: JSX.Element | string category?: string disabled?: boolean onSelect?: () => void } export type TuiDialogSelectProps<Value = unknown> = { title: string placeholder?: string options: TuiDialogSelectOption<Value>[] flat?: boolean onMove?: (option: TuiDialogSelectOption<Value>) => void onFilter?: (query: string) => void onSelect?: (option: TuiDialogSelectOption<Value>) => void skipFilter?: boolean current?: Value } export type TuiPromptInfo = { input: string mode?: "normal" | "shell" parts: ( | Omit<FilePart, "id" | "messageID" | "sessionID"> | Omit<AgentPart, "id" | "messageID" | "sessionID"> | (Omit<TextPart, "id" | "messageID" | "sessionID"> & { source?: { text: { start: number end: number value: string } } }) )[] } export type TuiPromptRef = { focused: boolean current: TuiPromptInfo set(prompt: TuiPromptInfo): void reset(): void blur(): void focus(): void submit(): void } export type TuiPromptProps = { sessionID?: string visible?: boolean disabled?: boolean onSubmit?: () => void ref?: (ref: TuiPromptRef | undefined) => void hint?: JSX.Element right?: JSX.Element showPlaceholder?: boolean placeholders?: { normal?: string[] shell?: string[] } } export type TuiToast = { variant?: "info" | "success" | "warning" | "error" title?: string message: string duration?: number } export type TuiAttentionWhen = "always" | "focused" | "blurred" export const TuiAttentionSoundNames = ["default", "question", "permission", "error", "done", "subagent_done"] as const export type TuiAttentionSoundName = (typeof TuiAttentionSoundNames)[number] export type TuiAttentionSound = | boolean | { name?: TuiAttentionSoundName volume?: number when?: TuiAttentionWhen } export type TuiAttentionNotification = | boolean | { when?: TuiAttentionWhen } export type TuiAttentionSoundPack = { id: string name?: string sounds: Partial<Record<TuiAttentionSoundName, string>> } export type TuiAttentionSoundPackInfo = { id: string name?: string active: boolean builtin: boolean } export type TuiAttentionSoundboardActivateOptions = { persist?: boolean } export type TuiAttentionSoundboard = { registerPack(pack: TuiAttentionSoundPack): () => void activate(id: string, options?: TuiAttentionSoundboardActivateOptions): boolean current(): string list(): ReadonlyArray<TuiAttentionSoundPackInfo> } export type TuiAttentionNotifyInput = { title?: string message: string notification?: TuiAttentionNotification sound?: TuiAttentionSound } export type TuiAttentionNotifySkipReason = | "attention_disabled" | "empty_message" | "blurred" | "focused" | "focus_unknown" | "renderer_destroyed" export type TuiAttentionNotifyResult = { ok: boolean notification: boolean sound: boolean skipped?: TuiAttentionNotifySkipReason } export type TuiAttention = { notify(input: TuiAttentionNotifyInput): Promise<TuiAttentionNotifyResult> soundboard: TuiAttentionSoundboard } export type TuiThemeCurrent = { readonly primary: RGBA readonly secondary: RGBA readonly accent: RGBA readonly error: RGBA readonly warning: RGBA readonly success: RGBA readonly info: RGBA readonly text: RGBA readonly textMuted: RGBA readonly selectedListItemText: RGBA readonly background: RGBA readonly backgroundPanel: RGBA readonly backgroundElement: RGBA readonly backgroundMenu: RGBA readonly border: RGBA readonly borderActive: RGBA readonly borderSubtle: RGBA readonly diffAdded: RGBA readonly diffRemoved: RGBA readonly diffContext: RGBA readonly diffHunkHeader: RGBA readonly diffHighlightAdded: RGBA readonly diffHighlightRemoved: RGBA readonly diffAddedBg: RGBA readonly diffRemovedBg: RGBA readonly diffContextBg: RGBA readonly diffLineNumber: RGBA readonly diffAddedLineNumberBg: RGBA readonly diffRemovedLineNumberBg: RGBA readonly markdownText: RGBA readonly markdownHeading: RGBA readonly markdownLink: RGBA readonly markdownLinkText: RGBA readonly markdownCode: RGBA readonly markdownBlockQuote: RGBA readonly markdownEmph: RGBA readonly markdownStrong: RGBA readonly markdownHorizontalRule: RGBA readonly markdownListItem: RGBA readonly markdownListEnumeration: RGBA readonly markdownImage: RGBA readonly markdownImageText: RGBA readonly markdownCodeBlock: RGBA readonly syntaxComment: RGBA readonly syntaxKeyword: RGBA readonly syntaxFunction: RGBA readonly syntaxVariable: RGBA readonly syntaxString: RGBA readonly syntaxNumber: RGBA readonly syntaxType: RGBA readonly syntaxOperator: RGBA readonly syntaxPunctuation: RGBA readonly thinkingOpacity: number } export type TuiTheme = { readonly current: TuiThemeCurrent readonly selected: string has: (name: string) => boolean set: (name: string) => boolean install: (jsonPath: string) => Promise<void> mode: () => "dark" | "light" readonly ready: boolean } export type TuiKV = { get: <Value = unknown>(key: string, fallback?: Value) => Value set: (key: string, value: unknown) => void readonly ready: boolean } export type TuiState = { readonly ready: boolean readonly config: SdkConfig readonly provider: ReadonlyArray<Provider> readonly path: { state: string config: string worktree: string directory: string } readonly vcs: { branch?: string; default_branch?: string } | undefined session: { count: () => number get: (sessionID: string) => Session | undefined diff: (sessionID: string) => ReadonlyArray<TuiSidebarFileItem> todo: (sessionID: string) => ReadonlyArray<TuiSidebarTodoItem> messages: (sessionID: string) => ReadonlyArray<Message> status: (sessionID: string) => SessionStatus | undefined permission: (sessionID: string) => ReadonlyArray<PermissionRequest> question: (sessionID: string) => ReadonlyArray<QuestionRequest> } part: (messageID: string) => ReadonlyArray<Part> lsp: () => ReadonlyArray<TuiSidebarLspItem> mcp: () => ReadonlyArray<TuiSidebarMcpItem> } type TuiBindingLookupView = { readonly bindings: ReadonlyArray<Binding<Renderable, KeyEvent>> get: (command: string) => ReadonlyArray<Binding<Renderable, KeyEvent>> has: (command: string) => boolean gather: (name: string, commands: readonly string[]) => ReadonlyArray<Binding<Renderable, KeyEvent>> pick: (name: string, commands: readonly string[]) => Binding<Renderable, KeyEvent>[] omit: (name: string, commands: readonly string[]) => Binding<Renderable, KeyEvent>[] } type TuiAttentionConfigView = { enabled: boolean notifications: boolean sound: boolean volume: number sound_pack: string sounds: Partial<Record<TuiAttentionSoundName, string>> } type TuiConfigView = Pick<PluginConfig, "$schema" | "theme" | "plugin"> & NonNullable<PluginConfig["tui"]> & { leader_timeout: number attention: TuiAttentionConfigView plugin_enabled?: Record<string, boolean> keybinds: TuiBindingLookupView } export type TuiApp = { readonly version: string } type Frozen<Value> = Value extends (...args: never[]) => unknown ? Value : Value extends ReadonlyArray<infer Item> ? ReadonlyArray<Frozen<Item>> : Value extends object ? { readonly [Key in keyof Value]: Frozen<Value[Key]> } : Value export type TuiSidebarMcpItem = { name: string status: McpStatus["status"] error?: string } export type TuiSidebarLspItem = Pick<LspStatus, "id" | "root" | "status"> export type TuiSidebarTodoItem = Pick<Todo, "content" | "status"> export type TuiSidebarFileItem = { file: string additions: number deletions: number } export type TuiHostSlotMap = { app: {} app_bottom: {} home_logo: {} home_prompt: { ref?: (ref: TuiPromptRef | undefined) => void } home_prompt_right: {} session_prompt: { session_id: string visible?: boolean disabled?: boolean on_submit?: () => void ref?: (ref: TuiPromptRef | undefined) => void } session_prompt_right: { session_id: string } home_bottom: {} home_footer: {} sidebar_title: { session_id: string title: string share_url?: string } sidebar_content: { session_id: string } sidebar_footer: { session_id: string } } export type TuiSlotMap<Slots extends Record<string, object> = {}> = TuiHostSlotMap & Slots type TuiSlotShape<Name extends string, Slots extends Record<string, object>> = Name extends keyof TuiHostSlotMap ? TuiHostSlotMap[Name] : Name extends keyof Slots ? Slots[Name] : Record<string, unknown> export type TuiSlotProps<Name extends string = string, Slots extends Record<string, object> = {}> = { name: Name mode?: SlotMode children?: JSX.Element } & TuiSlotShape<Name, Slots> export type TuiSlotContext = { theme: TuiTheme } type SlotCore<Slots extends Record<string, object> = {}> = SolidPlugin<TuiSlotMap<Slots>, TuiSlotContext> export type TuiSlotPlugin<Slots extends Record<string, object> = {}> = Omit<SlotCore<Slots>, "id"> & { id?: never } export type TuiSlots = { register: { (plugin: TuiSlotPlugin): string <Slots extends Record<string, object>>(plugin: TuiSlotPlugin<Slots>): string } } export type TuiEventBus = { on: <Type extends Event["type"]>(type: Type, handler: (event: Extract<Event, { type: Type }>) => void) => () => void } export type TuiDispose = () => void | Promise<void> export type TuiLifecycle = { readonly signal: AbortSignal onDispose: (fn: TuiDispose) => () => void } export type TuiPluginState = "first" | "updated" | "same" export type TuiPluginEntry = { id: string source: "file" | "npm" | "internal" spec: string target: string requested?: string version?: string modified?: number first_time: number last_time: number time_changed: number load_count: number fingerprint: string } export type TuiPluginMeta = TuiPluginEntry & { state: TuiPluginState } export type TuiPluginStatus = { id: string source: TuiPluginEntry["source"] spec: string target: string enabled: boolean active: boolean } export type TuiPluginInstallOptions = { global?: boolean } export type TuiPluginInstallResult = | { ok: true dir: string tui: boolean } | { ok: false message: string missing?: boolean } export type TuiWorkspace = { current: () => string | undefined set: (workspaceID?: string) => void } export type TuiPluginApi = { app: TuiApp attention: TuiAttention /** * Legacy `api.command` API kept so v1 plugins can initialize. Remove in v2. * * @deprecated Use `api.keymap.registerLayer`, `api.keymap.dispatchCommand`, and * `api.keymap.dispatchCommand("command.palette.show")` instead. */ command?: TuiCommandApi keys: TuiKeys keymap: TuiKeymap mode: TuiModeApi route: { register: (routes: TuiRouteDefinition[]) => () => void navigate: (name: string, params?: Record<string, unknown>) => void readonly current: TuiRouteCurrent } ui: { Dialog: (props: TuiDialogProps) => JSX.Element DialogAlert: (props: TuiDialogAlertProps) => JSX.Element DialogConfirm: (props: TuiDialogConfirmProps) => JSX.Element DialogPrompt: (props: TuiDialogPromptProps) => JSX.Element DialogSelect: <Value = unknown>(props: TuiDialogSelectProps<Value>) => JSX.Element Slot: <Name extends string>(props: TuiSlotProps<Name>) => JSX.Element | null Prompt: (props: TuiPromptProps) => JSX.Element toast: (input: TuiToast) => void dialog: TuiDialogStack } readonly tuiConfig: Frozen<TuiConfigView> kv: TuiKV state: TuiState theme: TuiTheme client: OpencodeClient event: TuiEventBus renderer: CliRenderer slots: TuiSlots plugins: { list: () => ReadonlyArray<TuiPluginStatus> activate: (id: string) => Promise<boolean> deactivate: (id: string) => Promise<boolean> add: (spec: string) => Promise<boolean> install: (spec: string, options?: TuiPluginInstallOptions) => Promise<TuiPluginInstallResult> } lifecycle: TuiLifecycle } export type TuiPlugin = (api: TuiPluginApi, options: PluginOptions | undefined, meta: TuiPluginMeta) => Promise<void> export type TuiPluginModule = { id?: string tui: TuiPlugin server?: never } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |