Skip to content

Commit b41051b

Browse files
committed
tweak(tui): better error msg rendering
1 parent 6f8746a commit b41051b

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/component/prompt

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Locale } from "@/util/locale"
2525
import { createColors, createFrames } from "../../ui/spinner.ts"
2626
import { useDialog } from "@tui/ui/dialog"
2727
import { DialogProvider as DialogProviderConnect } from "../dialog-provider"
28+
import { DialogAlert } from "../../ui/dialog-alert"
2829
import { useToast } from "../../ui/toast"
2930

3031
export type PromptProps = {
@@ -908,9 +909,14 @@ export function Prompt(props: PromptProps) {
908909
if (!r) return
909910
if (r.message.includes("exceeded your current quota") && r.message.includes("gemini"))
910911
return "gemini is way too hot right now"
911-
if (r.message.length > 50) return r.message.slice(0, 50) + "..."
912+
if (r.message.length > 80) return r.message.slice(0, 80) + "..."
912913
return r.message
913914
})
915+
const isTruncated = createMemo(() => {
916+
const r = retry()
917+
if (!r) return false
918+
return r.message.length > 120
919+
})
914920
const [seconds, setSeconds] = createSignal(0)
915921
onMount(() => {
916922
const timer = setInterval(() => {
@@ -922,12 +928,28 @@ export function Prompt(props: PromptProps) {
922928
clearInterval(timer)
923929
})
924930
})
931+
const handleMessageClick = () => {
932+
const r = retry()
933+
if (!r) return
934+
if (isTruncated()) {
935+
DialogAlert.show(dialog, "Retry Error", r.message)
936+
}
937+
}
938+
939+
const retryText = () => {
940+
const r = retry()
941+
if (!r) return ""
942+
const baseMessage = message()
943+
const truncatedHint = isTruncated() ? " (click to expand)" : ""
944+
const retryInfo = ` [retrying ${seconds() > 0 ? `in ${seconds()}s ` : ""}attempt #${r.attempt}]`
945+
return baseMessage + truncatedHint + retryInfo
946+
}
947+
925948
return (
926949
<Show when={retry()}>
927-
<text fg={theme.error}>
928-
{message()} [retrying {seconds() > 0 ? `in ${seconds()}s ` : ""}
929-
attempt #{retry()!.attempt}]
930-
</text>
950+
<box onMouseUp={handleMessageClick}>
951+
<text fg={theme.error}>{retryText()}</text>
952+
</box>
931953
</Show>
932954
)
933955
})()}

0 commit comments

Comments
 (0)