fix(tui): preserve prompt separator width (#19340)

* fix(tui): preserve prompt separator width

* fix(tui): align transcript height estimates with prompt width
This commit is contained in:
asheriif 2026-05-04 18:58:40 +02:00 committed by GitHub
parent d9c090fe36
commit 0ce1b9fe20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 85 additions and 7 deletions

View file

@ -1,5 +1,7 @@
import { stringWidth } from '@hermes/ink'
import type { Role } from '../types.js'
export const COMPOSER_PROMPT_GAP_WIDTH = 1
let _seg: Intl.Segmenter | null = null
@ -162,6 +164,14 @@ export function composerPromptWidth(promptText: string) {
return Math.max(1, stringWidth(promptText)) + COMPOSER_PROMPT_GAP_WIDTH
}
export function transcriptGutterWidth(role: Role, userPrompt: string) {
return role === 'user' ? composerPromptWidth(userPrompt) : 3
}
export function transcriptBodyWidth(totalCols: number, role: Role, userPrompt: string) {
return Math.max(20, totalCols - transcriptGutterWidth(role, userPrompt) - 2)
}
export function stableComposerColumns(totalCols: number, promptWidth: number) {
// Physical render/wrap width. Always reserve outer composer padding and
// prompt prefix. Only reserve the transcript scrollbar gutter when the

View file

@ -1,5 +1,6 @@
import type { Msg } from '../types.js'
import { transcriptBodyWidth } from './inputMetrics.js'
import { boundedHistoryRenderText } from './text.js'
const hashText = (text: string) => {
@ -38,7 +39,12 @@ export const wrappedLines = (text: string, width: number) => {
export const estimatedMsgHeight = (
msg: Msg,
cols: number,
{ compact, details, limitHistory = false }: { compact: boolean; details: boolean; limitHistory?: boolean }
{
compact,
details,
limitHistory = false,
userPrompt = ''
}: { compact: boolean; details: boolean; limitHistory?: boolean; userPrompt?: string }
) => {
if (msg.kind === 'intro') {
return msg.info?.version ? 9 : 5
@ -56,7 +62,7 @@ export const estimatedMsgHeight = (
return Math.max(2, msg.todos.length + 2)
}
const bodyWidth = Math.max(20, cols - 5)
const bodyWidth = transcriptBodyWidth(cols, msg.role, userPrompt)
const text = msg.role === 'assistant' && limitHistory ? boundedHistoryRenderText(msg.text) : msg.text
let h = wrappedLines(text || ' ', bodyWidth)