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
23 changes: 21 additions & 2 deletions packages/tui/src/component/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { RGBA, TextAttributes } from "@opentui/core"
import { For, type JSX } from "solid-js"
import { For, Show, type JSX } from "solid-js"
import { useTerminalDimensions } from "@opentui/solid"
import { useConfig } from "../config"
import { stringWidth } from "../util/string-width"
import { useTheme } from "../context/theme"
import { tint } from "../theme/color"
import { go, logo } from "../logo"

export function Logo() {
const theme = useTheme()
const config = useConfig()
// `false` hides the logo; an array of lines replaces it. Custom lines render as
// plain text and are hidden when the widest one doesn't fit, as the built-in
// logo falls back on narrow terminals.
const custom = () => config.data.logo
const customFits = (lines: readonly string[]) =>
Math.max(0, ...lines.map((line) => stringWidth(line))) <= dimensions().width - 4
const dimensions = useTerminalDimensions()

const renderLine = (line: string, fg: RGBA, bold: boolean): JSX.Element[] => {
Expand Down Expand Up @@ -51,7 +60,17 @@ export function Logo() {

return (
<box>
{dimensions().height < 12 ? null : dimensions().width < 22 ? (
{dimensions().height < 12 || custom() === false ? null : Array.isArray(custom()) ? (
Comment thread
martinwangjian marked this conversation as resolved.
Resolved
<Show when={customFits(custom() as readonly string[])}>
<For each={custom() as readonly string[]}>
{(line) => (
<text fg={theme.text.base} attributes={TextAttributes.BOLD} selectable={false}>
{line}
</text>
)}
</For>
</Show>
) : dimensions().width < 22 ? (
<For each={go.right.slice(1)}>
{(line) => <box flexDirection="row">{renderLine(line, theme.text.base, true)}</box>}
</For>
Expand Down
4 changes: 4 additions & 0 deletions packages/tui/src/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ export const Info = Schema.Struct({
description: "Experimental features that may change or be removed at any time",
}),
animations: Schema.optional(Schema.Boolean).annotate({ description: "Enable interface animations" }),
logo: Schema.optional(Schema.Union([Schema.Literal(false), Schema.Array(Schema.String)])).annotate({
description:
"Logo on the home screen and /stats: false hides it, or lines of plain text that replace it. Hidden when wider than the terminal",
}),
highlights: Schema.optional(Schema.Boolean).annotate({
description: "Show the release highlights once after OpenCode updates",
}),
Expand Down
3 changes: 2 additions & 1 deletion packages/tui/src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ function UpdateNotification(props: { width: number }) {
flexShrink={0}
flexDirection="row"
justifyContent="center"
width={props.width}
// The logo can be hidden by config, leaving no width to match.
width={props.width > 0 ? props.width : undefined}
maxWidth="100%"
gap={1}
backgroundColor={hovered() ? theme.background.action.primary.hovered : undefined}
Expand Down
43 changes: 43 additions & 0 deletions packages/tui/test/logo-config.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect, test } from "bun:test"
import { createAppFixture } from "./fixture/app"

// The first row of the built-in home logo.
const BUILT_IN_LOGO = "█▀▀█ █▀▀█ █▀▀█ █▀▀▄"

test("logo lines from the config replace the built-in home logo", async () => {
await using setup = await createAppFixture({
config: { animations: false, logo: ["ACME CODE", "internal build"] },
})
await setup.ready
await setup.waitForFrame((frame) => frame.includes("ACME CODE") && frame.includes("internal build"))
expect(setup.captureCharFrame()).not.toContain(BUILT_IN_LOGO)
})

test("logo false hides the home logo and keeps the home screen", async () => {
await using setup = await createAppFixture({ config: { animations: false, logo: false } })
await setup.ready
await setup.waitForFrame((frame) => frame.includes("ctrl+p commands"))
expect(setup.captureCharFrame()).not.toContain(BUILT_IN_LOGO)
})

test("without a logo setting the built-in home logo is shown", async () => {
await using setup = await createAppFixture({ config: { animations: false } })
await setup.ready
await setup.waitForFrame((frame) => frame.includes(BUILT_IN_LOGO))
})

test("custom logo lines render as plain text", async () => {
await using setup = await createAppFixture({ config: { animations: false, logo: ["acme_code, v1 ^~"] } })
await setup.ready
await setup.waitForFrame((frame) => frame.includes("acme_code, v1 ^~"))
})

test("a custom logo wider than the terminal is hidden", async () => {
const wide = "ACME".repeat(20)
await using setup = await createAppFixture({ width: 60, config: { animations: false, logo: [wide] } })
await setup.ready
await setup.waitForFrame((frame) => frame.includes("ctrl+p"))
const frame = setup.captureCharFrame()
expect(frame).not.toContain("ACMEACME")
expect(frame).not.toContain(BUILT_IN_LOGO)
})
10 changes: 10 additions & 0 deletions services/site/src/docs/content/cli/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ Choose a theme, control interface motion, and override the terminal cursor:
| `animations` | boolean | Enables interface animations. |
| `cursor.style` | `block`, `underline`, `line`, `default` | Sets the cursor shape. `default` preserves the terminal's cursor shape. |
| `cursor.blinking` | boolean | Controls cursor blinking. It has no effect when the style is `default`. |
| `logo` | `false` or array of strings | Hides the logo on the home screen and `/stats`, or replaces it. |

</div>

See [Theme](/cli/theme) for selecting and creating themes.

To show your own logo on the home screen and `/stats`, list its lines. They render as plain text, and the logo is hidden
when its widest line doesn't fit the terminal. Set `"logo": false` to hide it.

```json title="cli.json"
{
"logo": ["▄▀█ █▀▀ █▀▄▀█ █▀▀", "█▀█ █▄▄ █ ▀ █ ██▄"]
}
```

## Input

Configure mouse capture, scrolling, editor context, pastes, and prompt image previews:
Expand Down
Loading