Truncate prompt column in session list to fit terminal width
This commit is contained in:
parent
e5085d50ed
commit
40b04f159e
|
|
@ -175,10 +175,16 @@ program
|
|||
|
||||
const branchWidth = Math.max(6, ...sessions.map((s) => s.branch.length))
|
||||
const worktreeWidth = Math.max(8, ...sessions.map((s) => tilde(s.worktree).length + 1))
|
||||
const cols = process.stdout.columns || 80
|
||||
const prefixWidth = branchWidth + 2 + worktreeWidth + 2
|
||||
|
||||
console.log(`${"BRANCH".padEnd(branchWidth)} ${"WORKTREE".padEnd(worktreeWidth)} PROMPT`)
|
||||
for (const s of sessions) {
|
||||
const wt = tilde(s.worktree) + "/"
|
||||
console.log(`${s.branch.padEnd(branchWidth)} ${wt.padEnd(worktreeWidth)} ${s.prompt ?? ""}`)
|
||||
const prompt = s.prompt ?? ""
|
||||
const maxPrompt = cols - prefixWidth
|
||||
const truncated = maxPrompt > 3 && prompt.length > maxPrompt ? prompt.slice(0, maxPrompt - 3) + "..." : prompt
|
||||
console.log(`${s.branch.padEnd(branchWidth)} ${wt.padEnd(worktreeWidth)} ${truncated}`)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user