Skip to content

Commit 0de5f1f

Browse files
authored
feat(tui): make prompt size responsive and configurable (anomalyco#28255)
1 parent 7703786 commit 0de5f1f

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,11 +1464,15 @@ export function Prompt(props: PromptProps) {
14641464
}),
14651465
}
14661466
})
1467+
const maxHeight = createMemo(
1468+
() => tuiConfig.prompt?.max_height ?? Math.max(6, Math.floor(dimensions().height / 3)),
1469+
)
14671470

14681471
return (
14691472
<>
1470-
<box ref={(r: BoxRenderable) => (anchor = r)} visible={props.visible !== false}>
1473+
<box ref={(r: BoxRenderable) => (anchor = r)} visible={props.visible !== false} width="100%">
14711474
<box
1475+
width="100%"
14721476
border={["left"]}
14731477
borderColor={borderHighlight()}
14741478
customBorderChars={{
@@ -1483,14 +1487,16 @@ export function Prompt(props: PromptProps) {
14831487
flexShrink={0}
14841488
backgroundColor={theme.backgroundElement}
14851489
flexGrow={1}
1490+
width="100%"
14861491
>
14871492
<textarea
1493+
width="100%"
14881494
placeholder={placeholderText()}
14891495
placeholderColor={theme.textMuted}
14901496
textColor={leader() ? theme.textMuted : theme.text}
14911497
focusedTextColor={leader() ? theme.textMuted : theme.text}
14921498
minHeight={1}
1493-
maxHeight={6}
1499+
maxHeight={maxHeight()}
14941500
onContentChange={() => {
14951501
const value = input.plainText
14961502
setStore("prompt", "input", value)

‎packages/opencode/src/cli/cmd/tui/config/tui-schema.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ export const Attention = Schema.Struct({
6161
sounds: Schema.optional(TuiAttentionSounds),
6262
}).annotate({ description: "Attention notification and sound settings" })
6363

64+
const PromptSize = Schema.Int.check(Schema.isGreaterThan(0))
65+
66+
export const Prompt = Schema.Struct({
67+
max_height: Schema.optional(PromptSize).annotate({ description: "Prompt textarea max height" }),
68+
max_width: Schema.optional(Schema.Union([PromptSize, Schema.Literal("auto")])).annotate({
69+
description: "Home prompt max width: a positive integer for a fixed cap, or 'auto' to scale with terminal width",
70+
}),
71+
}).annotate({ description: "Prompt size settings" })
72+
6473
export const TuiInfo = Schema.Struct({
6574
$schema: Schema.optional(Schema.String),
6675
theme: Schema.optional(Schema.String),
@@ -69,6 +78,7 @@ export const TuiInfo = Schema.Struct({
6978
plugin_enabled: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
7079
leader_timeout: Schema.optional(KeymapLeaderTimeout),
7180
attention: Schema.optional(Attention),
81+
prompt: Schema.optional(Prompt),
7282
scroll_speed: Schema.optional(ScrollSpeed).annotate({
7383
description: "TUI scroll speed",
7484
}),

‎packages/opencode/src/cli/cmd/tui/routes/home.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Prompt, type PromptRef } from "@tui/component/prompt"
2-
import { createEffect, createSignal, onMount } from "solid-js"
2+
import { createEffect, createMemo, createSignal, onMount } from "solid-js"
33
import { Logo } from "../component/logo"
44
import { useSync } from "../context/sync"
55
import { Toast } from "../ui/toast"
@@ -9,6 +9,8 @@ import { usePromptRef } from "../context/prompt"
99
import { useLocal } from "../context/local"
1010
import { TuiPluginRuntime } from "@/cli/cmd/tui/plugin/runtime"
1111
import { useEditorContext } from "@tui/context/editor"
12+
import { useTerminalDimensions } from "@opentui/solid"
13+
import { useTuiConfig } from "../context/tui-config"
1214

1315
let once = false
1416
const placeholder = {
@@ -24,6 +26,13 @@ export function Home() {
2426
const args = useArgs()
2527
const local = useLocal()
2628
const editor = useEditorContext()
29+
const dimensions = useTerminalDimensions()
30+
const tuiConfig = useTuiConfig()
31+
const promptMaxWidth = createMemo(() => {
32+
const configured = tuiConfig.prompt?.max_width
33+
if (configured === "auto") return Math.max(75, Math.floor(dimensions().width * 0.7))
34+
return configured ?? 75
35+
})
2736
let sent = false
2837

2938
onMount(() => {
@@ -67,7 +76,7 @@ export function Home() {
6776
</TuiPluginRuntime.Slot>
6877
</box>
6978
<box height={1} minHeight={0} flexShrink={1} />
70-
<box width="100%" maxWidth={75} zIndex={1000} paddingTop={1} flexShrink={0}>
79+
<box width="100%" maxWidth={promptMaxWidth()} zIndex={1000} paddingTop={1} flexShrink={0}>
7180
<TuiPluginRuntime.Slot name="home_prompt" mode="replace" ref={bind}>
7281
<Prompt ref={bind} right={<TuiPluginRuntime.Slot name="home_prompt_right" />} placeholders={placeholder} />
7382
</TuiPluginRuntime.Slot>

0 commit comments

Comments
 (0)