Skip to content

Commit b70a0f8

Browse files
feat(tui): add custom logo slots
1 parent 5183ea4 commit b70a0f8

7 files changed

Lines changed: 241 additions & 6 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Plugin } from "@opencode/plugin/tui"
2+
3+
const logo = `█▀▀▀ █ █ █▀▀▀ ▀▀█▀▀ █▀▀█ █▄ ▄█
4+
█ █ █ ▀▀▀█ █ █ █ █ ▀ █
5+
▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀ ▀▀▀▀ ▀ ▀`
6+
7+
export default Plugin.define({
8+
id: "local.custom-logo",
9+
setup(context) {
10+
return context.ui.slot({
11+
replace: "home.logo",
12+
render: () => (
13+
<text fg={context.theme.text.base} selectable={false}>
14+
{logo}
15+
</text>
16+
),
17+
})
18+
},
19+
})

‎packages/plugin/src/tui/context.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,15 @@ export interface SlotMap {
192192
readonly app: Readonly<Record<string, never>>
193193
readonly "home.footer": Readonly<Record<string, never>>
194194
readonly "home.footer.status": Readonly<Record<string, never>>
195+
readonly "home.logo": Readonly<Record<string, never>>
195196
readonly "prompt.footer": PromptFooterInput
196197
readonly "prompt.footer.status": PromptFooterInput
197198
readonly "prompt.footer.file": PromptFooterInput
198199
readonly "session.composer.top": { readonly sessionID: string }
199200
readonly "session.panel": PanelInput
200201
readonly "sidebar.content": { readonly sessionID: string }
201202
readonly "sidebar.footer": { readonly sessionID: string }
203+
readonly "stats.logo": Readonly<Record<string, never>>
202204
}
203205
export type SlotPath = keyof SlotMap
204206

‎packages/tui/src/feature-plugins/system/stats.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useTerminalDimensions } from "@opentui/solid"
66
import { createMemo, createResource, createSignal, For, Show } from "solid-js"
77
import { Logo } from "../../component/logo"
88
import { useTheme } from "../../context/theme"
9+
import { Slot } from "../../plugin/render"
910
import { tint } from "../../theme/color"
1011
import { statsMetrics, statsNumber } from "./stats-data"
1112

@@ -66,9 +67,11 @@ export function StatsPoster(props: { stats: SessionStatsInfo }) {
6667
</text>
6768
<text fg={theme.text.muted}>{dates()}</text>
6869
</box>
69-
<Show when={!compact()}>
70-
<Logo />
71-
</Show>
70+
<Slot path="stats.logo">
71+
<Show when={!compact()}>
72+
<Logo />
73+
</Show>
74+
</Slot>
7275
<box alignItems="center" gap={1}>
7376
<Show
7477
when={large()}

‎packages/tui/src/routes/home.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export function Home() {
9494
setLogoWidth(this.width)
9595
}}
9696
>
97-
<Logo />
97+
<Slot path="home.logo">
98+
<Logo />
99+
</Slot>
98100
</box>
99101
<box height={1} flexShrink={0} />
100102
<UpdateNotification width={logoWidth()} />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Plugin } from "@opencode/plugin/tui"
2+
3+
const logo = `█▀▀ █ █ █▀▀ ▀█▀ █▀█ █▄█
4+
█ █ █ ▀▀█ █ █ █ █▀█
5+
▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █`
6+
7+
export default Plugin.define({
8+
id: "acme.custom-logo",
9+
setup(context) {
10+
const render = () => (
11+
<box alignItems="center">
12+
<text fg={context.theme.text.base} selectable={false}>
13+
{logo}
14+
</text>
15+
<text fg={context.theme.text.muted}>Your coding companion</text>
16+
</box>
17+
)
18+
19+
context.ui.slot({ replace: "home.logo", render })
20+
context.ui.slot({ replace: "stats.logo", render })
21+
},
22+
})
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { beforeEach, expect, test } from "bun:test"
2+
import { InputRenderable } from "@opentui/core"
3+
import path from "node:path"
4+
import { takeDraft } from "../src/component/prompt/draft-stash"
5+
import { createAppFixture } from "./fixture/app"
6+
import { json } from "./fixture/tui-client"
7+
8+
const sizes = [
9+
{ width: 100, height: 42 },
10+
{ width: 36, height: 30 },
11+
]
12+
13+
const exampleLogo = "█▀▀ █ █ █▀▀ ▀█▀ █▀█ █▄█"
14+
15+
const customLogo = "█▀▀▀ █ █ █▀▀▀ ▀▀█▀▀ █▀▀█ █▄ ▄█"
16+
17+
beforeEach(() => {
18+
takeDraft(undefined)
19+
})
20+
21+
test.each(sizes)("custom logos replace home and stats and restore on disable (%j)", async (size) => {
22+
await using setup = await createAppFixture({
23+
...size,
24+
config: {
25+
animations: false,
26+
tabs: { mode: "off" },
27+
plugins: ["-local.custom-logo", path.join(import.meta.dir, "fixture/plugin/custom-logo")],
28+
},
29+
fetch: stats,
30+
})
31+
await setup.ready
32+
await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("Ask anything"))
33+
expect(setup.captureCharFrame()).toContain("█ █ █ ▀▀█ █ █ █ █▀█")
34+
expect(setup.captureCharFrame()).toContain("▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █")
35+
expect(setup.captureCharFrame()).toContain("Your coding companion")
36+
expect(setup.captureCharFrame()).not.toContain("█▀▀█ █▀▀█ █▀▀█ █▀▀▄")
37+
38+
await openStats(setup)
39+
await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("TOKENS"))
40+
expect(setup.captureCharFrame()).toContain("█ █ █ ▀▀█ █ █ █ █▀█")
41+
expect(setup.captureCharFrame()).toContain("▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █")
42+
expect(setup.captureCharFrame()).toContain("Your coding companion")
43+
expect(setup.captureCharFrame()).not.toContain("█▀▀█ █▀▀█ █▀▀█ █▀▀▄")
44+
setup.mockInput.pressEscape()
45+
await setup.waitForFrame((frame) => frame.includes("Ask anything") && !frame.includes("TOKENS"))
46+
47+
await openPlugin(setup)
48+
await setup.waitForFrame((frame) => frame.includes("disable"))
49+
setup.mockInput.pressEnter()
50+
await setup.waitForFrame((frame) => frame.includes("inactive"))
51+
setup.mockInput.pressEscape()
52+
await setup.waitForFrame((frame) => frame.includes("█▀▀█") && frame.includes("Ask anything"))
53+
expect(setup.captureCharFrame()).not.toContain(exampleLogo)
54+
55+
await openStats(setup)
56+
await setup.waitForFrame((frame) => frame.includes("TOKENS"))
57+
expect(setup.captureCharFrame()).not.toContain(exampleLogo)
58+
expect(setup.captureCharFrame().includes("█▀▀█")).toBe(size.height >= 38)
59+
setup.mockInput.pressEscape()
60+
await setup.waitForFrame((frame) => frame.includes("Ask anything") && !frame.includes("TOKENS"))
61+
62+
await openPlugin(setup)
63+
await setup.waitForFrame((frame) => frame.includes("inactive"))
64+
setup.mockInput.pressEnter()
65+
await setup.waitForFrame((frame) => frame.includes("disable"))
66+
setup.mockInput.pressEscape()
67+
await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("Ask anything"))
68+
await openStats(setup)
69+
await setup.waitForFrame((frame) => frame.includes(exampleLogo) && frame.includes("TOKENS"))
70+
})
71+
72+
test.each(sizes)("built-in logos remain without a custom plugin (%j)", async (size) => {
73+
await using setup = await createAppFixture({
74+
...size,
75+
config: { animations: false, tabs: { mode: "off" }, plugins: ["-local.custom-logo"] },
76+
fetch: stats,
77+
})
78+
await setup.ready
79+
await setup.waitForFrame((frame) => frame.includes("█▀▀█") && frame.includes("Ask anything"))
80+
await openStats(setup)
81+
await setup.waitForFrame((frame) => frame.includes("TOKENS"))
82+
expect(setup.captureCharFrame().includes("█▀▀█")).toBe(size.height >= 38)
83+
})
84+
85+
test.each(sizes)("project plugin shows CUSTOM glyphs on Home and keeps the stats logo (%j)", async (size) => {
86+
await using setup = await createAppFixture({
87+
...size,
88+
config: {
89+
animations: false,
90+
tabs: { mode: "off" },
91+
plugins: ["local.custom-logo"],
92+
},
93+
fetch: stats,
94+
})
95+
await setup.ready
96+
await setup.waitForFrame((frame) => frame.includes(customLogo) && frame.includes("Ask anything"))
97+
expect(setup.captureCharFrame()).toContain("█ █ █ ▀▀▀█ █ █ █ █ ▀ █")
98+
expect(setup.captureCharFrame()).toContain("▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀ ▀▀▀▀ ▀ ▀")
99+
expect(setup.captureCharFrame()).not.toContain("█▀▀█ █▀▀█ █▀▀█ █▀▀▄")
100+
await openStats(setup)
101+
await setup.waitForFrame((frame) => frame.includes("TOKENS"))
102+
expect(setup.captureCharFrame()).not.toContain(customLogo)
103+
expect(setup.captureCharFrame().includes("█▀▀█")).toBe(size.height >= 38)
104+
})
105+
106+
function stats(url: URL) {
107+
if (url.pathname !== "/api/experimental/session/stats") return undefined
108+
return json({
109+
data: {
110+
range: { from: new Date(new Date().getFullYear(), 0, 1).getTime(), to: Date.now() },
111+
sessions: 123,
112+
subagents: 0,
113+
prompts: 1,
114+
steps: 1,
115+
tokens: { input: 10, output: 5, reasoning: 2, cache: { read: 20, write: 0 } },
116+
cost: 0,
117+
tools: { mode: "none" },
118+
activeDays: 1,
119+
streak: 1,
120+
activity: [],
121+
models: [],
122+
},
123+
})
124+
}
125+
126+
async function openStats(setup: Awaited<ReturnType<typeof createAppFixture>>) {
127+
await setup.mockInput.typeText("/stats")
128+
await setup.waitForFrame((frame) => frame.includes("Usage statistics"))
129+
setup.mockInput.pressEnter()
130+
}
131+
132+
async function openPlugin(setup: Awaited<ReturnType<typeof createAppFixture>>) {
133+
await setup.mockInput.typeText("/plugins")
134+
await setup.waitForFrame((frame) => frame.includes("/plugins"))
135+
setup.mockInput.pressEnter()
136+
await setup.waitForFrame((frame) => frame.includes("Plugins"))
137+
await setup.waitFor(() => setup.renderer.currentFocusedEditor instanceof InputRenderable)
138+
await setup.mockInput.typeText("custom-logo")
139+
}

‎services/www/src/docs/content/build/plugins/cli.mdx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ context.keymap.layer(() => ({
479479

480480
## Slots
481481

482-
Slots insert or replace JSX at `app`, `home.footer`, `home.footer.status`, `prompt.footer`, `prompt.footer.status`,
483-
`prompt.footer.file`, `session.composer.top`, `sidebar.content`, or `sidebar.footer`.
482+
Slots insert or replace JSX at `app`, `home.footer`, `home.footer.status`, `home.logo`, `prompt.footer`, `prompt.footer.status`,
483+
`prompt.footer.file`, `session.composer.top`, `sidebar.content`, `sidebar.footer`, or `stats.logo`.
484484

485485
```tsx
486486
return context.ui.slot({
@@ -506,6 +506,54 @@ after OpenCode's health indicators and before the version.
506506
context.ui.slot({ append: "home.footer.status", render: () => <text>SYNCED</text> })
507507
```
508508

509+
### Custom logo
510+
511+
Replace `home.logo` to show your own logo on the home screen, and `stats.logo` to show it on the `/stats` page.
512+
Create a local CLI plugin with a JSX entrypoint. Use a multiline string for block-glyph art; `<text>` preserves its
513+
spaces and line breaks:
514+
515+
```tsx title=".opencode/plugins/custom-logo/tui.tsx"
516+
import { Plugin } from "@opencode/plugin/tui"
517+
518+
const logo = `█▀▀ █ █ █▀▀ ▀█▀ █▀█ █▄█
519+
█ █ █ ▀▀█ █ █ █ █▀█
520+
▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █`
521+
522+
export default Plugin.define({
523+
id: "acme.custom-logo",
524+
setup(context) {
525+
const render = () => (
526+
<box alignItems="center">
527+
<text fg={context.theme.text.base} selectable={false}>
528+
{logo}
529+
</text>
530+
<text fg={context.theme.text.muted}>Your coding companion</text>
531+
</box>
532+
)
533+
534+
context.ui.slot({ replace: "home.logo", render })
535+
context.ui.slot({ replace: "stats.logo", render })
536+
},
537+
})
538+
```
539+
540+
The logo spells `CUSTOM` in block glyphs:
541+
542+
```text
543+
█▀▀ █ █ █▀▀ ▀█▀ █▀█ █▄█
544+
█ █ █ ▀▀█ █ █ █ █▀█
545+
▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀▀▀ █ █
546+
```
547+
548+
OpenCode discovers the plugin automatically under `.opencode/plugins/`. Restart the CLI, check the home screen,
549+
then run `/stats` to see both replacements. See [Configure CLI plugins](/cli/plugins) for other loading options.
550+
551+
- Register only the slot you want to change; the other keeps its built-in logo.
552+
- Keep your JSX small enough for narrow terminals. Custom content controls its own sizing and visibility, including
553+
on compact stats pages where the built-in logo is hidden.
554+
- Disabling the plugin or disposing its slot registrations restores the built-in content. If multiple plugins replace
555+
the same slot, the last enabled replacement wins.
556+
509557
### Session panels
510558

511559
Register a contribution to `session.panel`, then open the panel from a command. The host owns sizing, focus, and

0 commit comments

Comments
 (0)