Skip to content
Merged
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/tui/src/feature-plugins/system/which-key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function layout(value: unknown): Layout {
return "dock"
}

function HomeHint(props: { api: TuiPluginApi; placement?: "center" | "start" }) {
export function HomeHint(props: { api: TuiPluginApi; placement?: "center" | "start" }) {
const trigger = commandShortcut(props.api, command.toggle)
const look = createMemo(() => skin(props.api))

Expand Down
48 changes: 48 additions & 0 deletions packages/tui/test/feature-plugins/which-key-home-hint.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** @jsxImportSource @opentui/solid */
import { expect, test } from "bun:test"
import { testRender, useRenderer } from "@opentui/solid"
import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui"
import { RGBA } from "@opentui/core"
import type { JSX } from "solid-js"
import type { TuiPluginApi } from "@opencode-ai/plugin/tui"
import { OpencodeKeymapProvider } from "../../src/keymap"
import { HomeHint } from "../../src/feature-plugins/system/which-key"

const api = {
theme: { current: new Proxy({}, { get: () => RGBA.fromInts(200, 200, 200) }) },
keys: { formatSequence: () => "" },
} as unknown as TuiPluginApi

function Harness(props: { children: JSX.Element }) {
return <OpencodeKeymapProvider keymap={createDefaultOpenTuiKeymap(useRenderer())}>{props.children}</OpencodeKeymapProvider>
}

async function hintIndent(placement?: "center" | "start") {
const app = await testRender(
() => (
<Harness>
<HomeHint api={api} placement={placement} />
</Harness>
),
{ width: 80, height: 10 },
)
try {
await app.renderOnce()
const line = app
.captureCharFrame()
.split("\n")
.find((row) => row.includes("shortcuts"))
expect(line).toBeDefined()
return line!.length - line!.trimStart().length
} finally {
app.renderer.destroy()
}
}

test("left-aligns the home hint when placement is start", async () => {
expect(await hintIndent("start")).toBe(0)
})

test("centers the home hint by default", async () => {
expect(await hintIndent()).toBeGreaterThan(0)
})
Loading