diff --git a/src/cli.ts b/src/cli.ts index eaa1baf..1eb352a 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -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}`) } })