From db8b4ef1e90fb54606e018761d6dad7146006524 Mon Sep 17 00:00:00 2001 From: David Hill Date: Tue, 6 Jan 2026 21:40:24 +0000 Subject: [PATCH] fix: style multiple commands in input --- .../cli/cmd/tui/component/prompt/index.tsx | 22 +++++++++++++++++++ .../src/cli/cmd/tui/context/theme.tsx | 7 ++++++ 2 files changed, 29 insertions(+) diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index 4558914cb7..5a5431aa83 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -89,7 +89,9 @@ export function Prompt(props: PromptProps) { const fileStyleId = syntax().getStyleId("extmark.file")! const agentStyleId = syntax().getStyleId("extmark.agent")! const pasteStyleId = syntax().getStyleId("extmark.paste")! + const commandStyleId = syntax().getStyleId("extmark.command")! let promptPartTypeId: number + let commandHighlightRef = 0 sdk.event.on(TuiEvent.PromptAppend.type, (evt) => { input.insertText(evt.properties.text) @@ -397,6 +399,25 @@ export function Prompt(props: PromptProps) { ) } + function highlightSlashCommands() { + // Remove previous command highlights + input.removeHighlightsByRef(commandHighlightRef) + commandHighlightRef++ + + const text = input.plainText + // Match all slash commands (e.g. /help, /status, /compact) + const regex = /\/[a-zA-Z_][a-zA-Z0-9_-]*/g + let match: RegExpExecArray | null + while ((match = regex.exec(text)) !== null) { + input.addHighlightByCharRange({ + start: match.index, + end: match.index + match[0].length, + styleId: commandStyleId, + hlRef: commandHighlightRef, + }) + } + } + command.register(() => [ { title: "Stash prompt", @@ -772,6 +793,7 @@ export function Prompt(props: PromptProps) { setStore("prompt", "input", value) autocomplete.onInput(value) syncExtmarksWithPromptParts() + highlightSlashCommands() }} keyBindings={textareaKeybindings()} onKeyDown={async (e) => { diff --git a/packages/opencode/src/cli/cmd/tui/context/theme.tsx b/packages/opencode/src/cli/cmd/tui/context/theme.tsx index 14d10ad601..000725afe1 100644 --- a/packages/opencode/src/cli/cmd/tui/context/theme.tsx +++ b/packages/opencode/src/cli/cmd/tui/context/theme.tsx @@ -679,6 +679,13 @@ function getSyntaxRules(theme: Theme) { bold: true, }, }, + { + scope: ["extmark.command"], + style: { + foreground: theme.accent, + bold: true, + }, + }, { scope: ["comment"], style: {