Skip to content

Commit 9311bd5

Browse files
committed
feat(tui): add header/footer/shortcuts toggle for small screen optimization
Add System commands to toggle header, footer, and shortcuts visibility via command palette (ctrl+p). All preferences persist across restarts. - All toggle commands under System category in app.tsx - Available globally (home + session pages) - When footer hidden: compact status shown in prompt info line - When footer visible: detailed status in bottom section Fixes anomalyco#5277
1 parent cd16d31 commit 9311bd5

4 files changed

Lines changed: 205 additions & 97 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ function App() {
169169
const local = useLocal()
170170
const kv = useKV()
171171
const command = useCommandDialog()
172+
const [shortcutsHidden, setShortcutsHidden] = createSignal(kv.get("shortcuts_hidden", false))
173+
const [headerHidden, setHeaderHidden] = createSignal(kv.get("header_hidden", false))
174+
const [footerHidden, setFooterHidden] = createSignal(kv.get("footer_hidden", false))
172175
const sdk = useSDK()
173176
const toast = useToast()
174177
const { theme, mode, setMode } = useTheme()
@@ -450,6 +453,45 @@ function App() {
450453
dialog.clear()
451454
},
452455
},
456+
{
457+
title: shortcutsHidden() ? "Show shortcuts" : "Hide shortcuts",
458+
value: "app.shortcuts.toggle",
459+
category: "System",
460+
onSelect: (dialog) => {
461+
setShortcutsHidden((prev) => {
462+
const next = !prev
463+
kv.set("shortcuts_hidden", next)
464+
return next
465+
})
466+
dialog.clear()
467+
},
468+
},
469+
{
470+
title: headerHidden() ? "Show header" : "Hide header",
471+
value: "app.header.toggle",
472+
category: "System",
473+
onSelect: (dialog) => {
474+
setHeaderHidden((prev) => {
475+
const next = !prev
476+
kv.set("header_hidden", next)
477+
return next
478+
})
479+
dialog.clear()
480+
},
481+
},
482+
{
483+
title: footerHidden() ? "Show footer" : "Hide footer",
484+
value: "app.footer.toggle",
485+
category: "System",
486+
onSelect: (dialog) => {
487+
setFooterHidden((prev) => {
488+
const next = !prev
489+
kv.set("footer_hidden", next)
490+
return next
491+
})
492+
dialog.clear()
493+
},
494+
},
453495
{
454496
title: "Suspend terminal",
455497
value: "terminal.suspend",

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

Lines changed: 149 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useDialog } from "@tui/ui/dialog"
2727
import { DialogProvider as DialogProviderConnect } from "../dialog-provider"
2828
import { DialogAlert } from "../../ui/dialog-alert"
2929
import { useToast } from "../../ui/toast"
30+
import { useKV } from "../../context/kv"
3031

3132
export type PromptProps = {
3233
sessionID?: string
@@ -35,6 +36,7 @@ export type PromptProps = {
3536
ref?: (ref: PromptRef) => void
3637
hint?: JSX.Element
3738
showPlaceholder?: boolean
39+
footerVisible?: boolean
3840
}
3941

4042
export type PromptRef = {
@@ -117,6 +119,12 @@ export function Prompt(props: PromptProps) {
117119
const dialog = useDialog()
118120
const toast = useToast()
119121
const status = createMemo(() => sync.data.session_status?.[props.sessionID ?? ""] ?? { type: "idle" })
122+
const kv = useKV()
123+
const permissions = createMemo(() => {
124+
if (!props.sessionID) return []
125+
return sync.data.permission[props.sessionID] ?? []
126+
})
127+
const shortcutsVisible = createMemo(() => !kv.get("shortcuts_hidden", false))
120128
const history = usePromptHistory()
121129
const command = useCommandDialog()
122130
const renderer = useRenderer()
@@ -881,17 +889,50 @@ export function Prompt(props: PromptProps) {
881889
cursorColor={theme.text}
882890
syntaxStyle={syntax()}
883891
/>
884-
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1}>
885-
<text fg={highlight()}>
886-
{store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "}
887-
</text>
888-
<Show when={store.mode === "normal"}>
889-
<box flexDirection="row" gap={1}>
890-
<text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
891-
{local.model.parsed().model}
892-
</text>
893-
<text fg={theme.textMuted}>{local.model.parsed().provider}</text>
894-
</box>
892+
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1} justifyContent="space-between">
893+
<box flexDirection="row" gap={1}>
894+
<text fg={highlight()}>
895+
{store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "}
896+
</text>
897+
<Show when={store.mode === "normal"}>
898+
<box flexDirection="row" gap={1}>
899+
<text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
900+
{local.model.parsed().model}
901+
</text>
902+
<text fg={theme.textMuted}>{local.model.parsed().provider}</text>
903+
</box>
904+
</Show>
905+
</box>
906+
<Show when={store.mode === "normal" && props.sessionID && !props.footerVisible}>
907+
<Switch>
908+
<Match when={permissions().length > 0}>
909+
<text fg={theme.warning}>
910+
<span style={{ fg: theme.warning }}>◉</span> {permissions().length} Permission
911+
{permissions().length > 1 ? "s" : ""} pending
912+
</text>
913+
</Match>
914+
<Match when={status().type !== "idle"}>
915+
<box flexDirection="row" gap={1} flexShrink={0}>
916+
<spinner color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
917+
<text fg={store.interrupt > 0 ? theme.primary : theme.text}>
918+
esc{" "}
919+
<span style={{ fg: store.interrupt > 0 ? theme.primary : theme.textMuted }}>
920+
{store.interrupt > 0 ? "again to interrupt" : "interrupt"}
921+
</span>
922+
</text>
923+
</box>
924+
</Match>
925+
<Match when={shortcutsVisible()}>
926+
<box gap={2} flexDirection="row" flexShrink={0}>
927+
<text fg={theme.text}>
928+
{keybind.print("agent_cycle")} <span style={{ fg: theme.textMuted }}>switch agent</span>
929+
</text>
930+
<text fg={theme.text}>
931+
{keybind.print("command_list")} <span style={{ fg: theme.textMuted }}>commands</span>
932+
</text>
933+
</box>
934+
</Match>
935+
</Switch>
895936
</Show>
896937
</box>
897938
</box>
@@ -922,103 +963,117 @@ export function Prompt(props: PromptProps) {
922963
}
923964
/>
924965
</box>
925-
<box flexDirection="row" justifyContent="space-between">
926-
<Show when={status().type !== "idle"} fallback={<text />}>
927-
<box
928-
flexDirection="row"
929-
gap={1}
930-
flexGrow={1}
931-
justifyContent={status().type === "retry" ? "space-between" : "flex-start"}
932-
>
933-
<box flexShrink={0} flexDirection="row" gap={1}>
934-
{/* @ts-ignore // SpinnerOptions doesn't support marginLeft */}
935-
<spinner marginLeft={1} color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
936-
<box flexDirection="row" gap={1} flexShrink={0}>
937-
{(() => {
938-
const retry = createMemo(() => {
939-
const s = status()
940-
if (s.type !== "retry") return
941-
return s
942-
})
943-
const message = createMemo(() => {
944-
const r = retry()
945-
if (!r) return
946-
if (r.message.includes("exceeded your current quota") && r.message.includes("gemini"))
947-
return "gemini is way too hot right now"
948-
if (r.message.length > 80) return r.message.slice(0, 80) + "..."
949-
return r.message
950-
})
951-
const isTruncated = createMemo(() => {
952-
const r = retry()
953-
if (!r) return false
954-
return r.message.length > 120
955-
})
956-
const [seconds, setSeconds] = createSignal(0)
957-
onMount(() => {
958-
const timer = setInterval(() => {
959-
const next = retry()?.next
960-
if (next) setSeconds(Math.round((next - Date.now()) / 1000))
961-
}, 1000)
962-
963-
onCleanup(() => {
964-
clearInterval(timer)
966+
<Show when={store.mode === "shell"}>
967+
<box gap={2} flexDirection="row">
968+
<text fg={theme.text}>
969+
esc <span style={{ fg: theme.textMuted }}>exit shell mode</span>
970+
</text>
971+
</box>
972+
</Show>
973+
<Show when={store.mode !== "shell"}>
974+
<box flexDirection="row" justifyContent="space-between">
975+
<Show when={props.footerVisible && status().type !== "idle"} fallback={<text />}>
976+
<box
977+
flexDirection="row"
978+
gap={1}
979+
flexGrow={1}
980+
justifyContent={status().type === "retry" ? "space-between" : "flex-start"}
981+
>
982+
<box flexShrink={0} flexDirection="row" gap={1}>
983+
{/* @ts-ignore // SpinnerOptions doesn't support marginLeft */}
984+
<spinner marginLeft={1} color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
985+
<box flexDirection="row" gap={1} flexShrink={0}>
986+
{(() => {
987+
const retry = createMemo(() => {
988+
const s = status()
989+
if (s.type !== "retry") return
990+
return s
965991
})
966-
})
967-
const handleMessageClick = () => {
968-
const r = retry()
969-
if (!r) return
970-
if (isTruncated()) {
971-
DialogAlert.show(dialog, "Retry Error", r.message)
992+
const message = createMemo(() => {
993+
const r = retry()
994+
if (!r) return
995+
if (r.message.includes("exceeded your current quota") && r.message.includes("gemini"))
996+
return "gemini is way too hot right now"
997+
if (r.message.length > 80) return r.message.slice(0, 80) + "..."
998+
return r.message
999+
})
1000+
const isTruncated = createMemo(() => {
1001+
const r = retry()
1002+
if (!r) return false
1003+
return r.message.length > 120
1004+
})
1005+
const [seconds, setSeconds] = createSignal(0)
1006+
onMount(() => {
1007+
const timer = setInterval(() => {
1008+
const next = retry()?.next
1009+
if (next) setSeconds(Math.round((next - Date.now()) / 1000))
1010+
}, 1000)
1011+
1012+
onCleanup(() => {
1013+
clearInterval(timer)
1014+
})
1015+
})
1016+
const handleMessageClick = () => {
1017+
const r = retry()
1018+
if (!r) return
1019+
if (isTruncated()) {
1020+
DialogAlert.show(dialog, "Retry Error", r.message)
1021+
}
9721022
}
973-
}
9741023

975-
const retryText = () => {
976-
const r = retry()
977-
if (!r) return ""
978-
const baseMessage = message()
979-
const truncatedHint = isTruncated() ? " (click to expand)" : ""
980-
const retryInfo = ` [retrying ${seconds() > 0 ? `in ${seconds()}s ` : ""}attempt #${r.attempt}]`
981-
return baseMessage + truncatedHint + retryInfo
982-
}
1024+
const retryText = () => {
1025+
const r = retry()
1026+
if (!r) return ""
1027+
const baseMessage = message()
1028+
const truncatedHint = isTruncated() ? " (click to expand)" : ""
1029+
const retryInfo = ` [retrying ${seconds() > 0 ? `in ${seconds()}s ` : ""}attempt #${r.attempt}]`
1030+
return baseMessage + truncatedHint + retryInfo
1031+
}
9831032

984-
return (
985-
<Show when={retry()}>
986-
<box onMouseUp={handleMessageClick}>
987-
<text fg={theme.error}>{retryText()}</text>
988-
</box>
989-
</Show>
990-
)
991-
})()}
1033+
return (
1034+
<Show when={retry()}>
1035+
<box onMouseUp={handleMessageClick}>
1036+
<text fg={theme.error}>{retryText()}</text>
1037+
</box>
1038+
</Show>
1039+
)
1040+
})()}
1041+
</box>
9921042
</box>
1043+
<text fg={store.interrupt > 0 ? theme.primary : theme.text}>
1044+
esc{" "}
1045+
<span style={{ fg: store.interrupt > 0 ? theme.primary : theme.textMuted }}>
1046+
{store.interrupt > 0 ? "again to interrupt" : "interrupt"}
1047+
</span>
1048+
</text>
9931049
</box>
994-
<text fg={store.interrupt > 0 ? theme.primary : theme.text}>
995-
esc{" "}
996-
<span style={{ fg: store.interrupt > 0 ? theme.primary : theme.textMuted }}>
997-
{store.interrupt > 0 ? "again to interrupt" : "interrupt"}
998-
</span>
999-
</text>
1000-
</box>
1001-
</Show>
1002-
<Show when={status().type !== "retry"}>
1003-
<box gap={2} flexDirection="row">
1004-
<Switch>
1005-
<Match when={store.mode === "normal"}>
1050+
</Show>
1051+
<Show when={!props.sessionID && status().type === "idle" && shortcutsVisible()}>
1052+
<box flexDirection="row" justifyContent="flex-end" flexGrow={1}>
1053+
<box gap={2} flexDirection="row">
10061054
<text fg={theme.text}>
10071055
{keybind.print("agent_cycle")} <span style={{ fg: theme.textMuted }}>switch agent</span>
10081056
</text>
10091057
<text fg={theme.text}>
10101058
{keybind.print("command_list")} <span style={{ fg: theme.textMuted }}>commands</span>
10111059
</text>
1012-
</Match>
1013-
<Match when={store.mode === "shell"}>
1060+
</box>
1061+
</box>
1062+
</Show>
1063+
<Show when={props.sessionID && props.footerVisible && status().type === "idle" && shortcutsVisible()}>
1064+
<box flexDirection="row" justifyContent="flex-end" flexGrow={1}>
1065+
<box gap={2} flexDirection="row">
10141066
<text fg={theme.text}>
1015-
esc <span style={{ fg: theme.textMuted }}>exit shell mode</span>
1067+
{keybind.print("agent_cycle")} <span style={{ fg: theme.textMuted }}>switch agent</span>
10161068
</text>
1017-
</Match>
1018-
</Switch>
1019-
</box>
1020-
</Show>
1021-
</box>
1069+
<text fg={theme.text}>
1070+
{keybind.print("command_list")} <span style={{ fg: theme.textMuted }}>commands</span>
1071+
</text>
1072+
</box>
1073+
</box>
1074+
</Show>
1075+
</box>
1076+
</Show>
10221077
</box>
10231078
</>
10241079
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function Home() {
7373
promptRef.set(r)
7474
}}
7575
hint={Hint}
76+
footerVisible={false}
7677
/>
7778
</box>
7879
<Toast />

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export function Session() {
136136
return false
137137
})
138138
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
139+
const headerVisible = createMemo(() => !sidebarVisible() && !kv.get("header_hidden", false))
140+
const footerVisible = createMemo(() => !sidebarVisible() && !kv.get("footer_hidden", false))
139141

140142
const scrollAcceleration = createMemo(() => {
141143
const tui = sync.data.config.tui
@@ -959,9 +961,16 @@ export function Session() {
959961
}}
960962
>
961963
<box flexDirection="row">
962-
<box flexGrow={1} paddingBottom={1} paddingTop={1} paddingLeft={2} paddingRight={2} gap={1}>
964+
<box
965+
flexGrow={1}
966+
paddingBottom={footerVisible() ? 1 : 0}
967+
paddingTop={1}
968+
paddingLeft={2}
969+
paddingRight={2}
970+
gap={1}
971+
>
963972
<Show when={session()}>
964-
<Show when={!sidebarVisible()}>
973+
<Show when={headerVisible()}>
965974
<Header />
966975
</Show>
967976
<scrollbox
@@ -1089,9 +1098,10 @@ export function Session() {
10891098
toBottom()
10901099
}}
10911100
sessionID={route.sessionID}
1101+
footerVisible={footerVisible()}
10921102
/>
10931103
</box>
1094-
<Show when={!sidebarVisible()}>
1104+
<Show when={footerVisible()}>
10951105
<Footer />
10961106
</Show>
10971107
</Show>

0 commit comments

Comments
 (0)