Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app/src/custom-elements.d.ts
2 changes: 1 addition & 1 deletion packages/enterprise/src/custom-elements.d.ts
25 changes: 25 additions & 0 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DialogWorkspaceList } from "@tui/component/dialog-workspace-list"
import { KeybindProvider } from "@tui/context/keybind"
import { ThemeProvider, useTheme } from "@tui/context/theme"
import { Home } from "@tui/routes/home"
import { Memory } from "@tui/routes/memory"
import { Session } from "@tui/routes/session"
import { PromptHistoryProvider } from "./component/prompt/history"
import { FrecencyProvider } from "./component/prompt/frecency"
Expand Down Expand Up @@ -279,6 +280,11 @@ function App() {
// Truncate title to 40 chars max
const title = session.title.length > 40 ? session.title.slice(0, 37) + "..." : session.title
renderer.setTerminalTitle(`OC | ${title}`)
return
}

if (route.data.type === "memory") {
renderer.setTerminalTitle("OC | Memory")
}
})

Expand Down Expand Up @@ -563,6 +569,22 @@ function App() {
},
category: "System",
},
{
title: "View memory",
value: "memory.view",
category: "System",
slash: {
name: "memory",
},
onSelect: (dialog) => {
if (route.data.type === "memory") return
route.navigate({
type: "memory",
back: { ...route.data },
})
dialog.clear()
},
},
{
title: "Help",
value: "help.show",
Expand Down Expand Up @@ -774,6 +796,9 @@ function App() {
<Match when={route.data.type === "session"}>
<Session />
</Match>
<Match when={route.data.type === "memory"}>
<Memory />
</Match>
</Switch>
</box>
)
Expand Down
18 changes: 16 additions & 2 deletions packages/opencode/src/cli/cmd/tui/context/keybind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import { useTuiConfig } from "./tui-config"

export type KeybindKey = keyof NonNullable<TuiConfig.Info["keybinds"]> & string

export const { use: useKeybind, provider: KeybindProvider } = createSimpleContext({
type KeybindContext = {
all: Record<string, Keybind.Info[]>
leader: boolean
captureLeader(enabled: boolean): void
parse(evt: ParsedKey): Keybind.Info
match(key: KeybindKey, evt: ParsedKey): boolean | undefined
print(key: KeybindKey): string
}

export const { use: useKeybind, provider: KeybindProvider } = createSimpleContext<KeybindContext, {}>({
name: "Keybind",
init: () => {
const config = useTuiConfig()
Expand All @@ -22,8 +31,10 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex
})
const [store, setStore] = createStore({
leader: false,
capture: 0,
})
const renderer = useRenderer()
const captured = () => store.capture > 0

let focus: Renderable | null
let timeout: NodeJS.Timeout
Expand Down Expand Up @@ -51,7 +62,7 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex
}

useKeyboard(async (evt) => {
if (!store.leader && result.match("leader", evt)) {
if (!store.leader && !captured() && result.match("leader", evt)) {
leader(true)
return
}
Expand All @@ -73,6 +84,9 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex
get leader() {
return store.leader
},
captureLeader(enabled: boolean) {
setStore("capture", (count) => Math.max(0, count + (enabled ? -1 : 1)))
},
parse(evt: ParsedKey): Keybind.Info {
// Handle special case for Ctrl+Underscore (represented as \x1F)
if (evt.name === "\x1F") {
Expand Down
7 changes: 6 additions & 1 deletion packages/opencode/src/cli/cmd/tui/context/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export type SessionRoute = {
initialPrompt?: PromptInfo
}

export type Route = HomeRoute | SessionRoute
export type MemoryRoute = {
type: "memory"
back: HomeRoute | SessionRoute
}

export type Route = HomeRoute | SessionRoute | MemoryRoute

export const { use: useRoute, provider: RouteProvider } = createSimpleContext({
name: "Route",
Expand Down
Loading
Loading