fix(tui): show background shell completion (#36534)

This commit is contained in:
Kit Langton 2026-07-12 21:01:36 -04:00 committed by GitHub
commit c0ed0106b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 8 deletions

View file

@ -63,6 +63,24 @@ export function truncate(str: string, len: number): string {
return str.slice(0, len - 1) + "…"
}
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
export function truncateWidth(str: string, width: number): string {
if (width <= 0) return ""
if (Bun.stringWidth(str) <= width) return str
if (width === 1) return "…"
const result: string[] = []
let used = 0
for (const item of graphemeSegmenter.segment(str)) {
const next = Bun.stringWidth(item.segment)
if (used + next > width - 1) break
result.push(item.segment)
used += next
}
return result.join("") + "…"
}
export function truncateLeft(str: string, len: number): string {
if (str.length <= len) return str
return "…" + str.slice(-(len - 1))