Add ANSI color coding to session list output
This commit is contained in:
parent
1edc7b92fb
commit
b9630e12c6
21
src/cli.ts
21
src/cli.ts
|
|
@ -211,22 +211,33 @@ program
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const icons: Record<string, string> = { idle: "◌", active: "◯", dirty: "◎", saved: "●" }
|
const reset = "\x1b[0m"
|
||||||
|
const dim = "\x1b[2m"
|
||||||
|
const bold = "\x1b[1m"
|
||||||
|
const green = "\x1b[32m"
|
||||||
|
const yellow = "\x1b[33m"
|
||||||
|
const cyan = "\x1b[36m"
|
||||||
|
const white = "\x1b[37m"
|
||||||
|
|
||||||
|
const icons: Record<string, string> = { idle: `${dim}◌${reset}`, active: `${green}◯${reset}`, dirty: `${yellow}◎${reset}`, saved: `${cyan}●${reset}` }
|
||||||
|
const branchColors: Record<string, string> = { idle: dim, active: green, dirty: yellow, saved: cyan }
|
||||||
const branchWidth = Math.max(6, ...sessions.map((s) => s.branch.length))
|
const branchWidth = Math.max(6, ...sessions.map((s) => s.branch.length))
|
||||||
const cols = process.stdout.columns || 80
|
const cols = process.stdout.columns || 80
|
||||||
const prefixWidth = branchWidth + 4
|
const prefixWidth = branchWidth + 4
|
||||||
|
|
||||||
console.log(` ${"BRANCH".padEnd(branchWidth)} PROMPT`)
|
console.log(` ${dim}${"BRANCH".padEnd(branchWidth)} PROMPT${reset}`)
|
||||||
|
|
||||||
for (const s of sessions) {
|
for (const s of sessions) {
|
||||||
const prompt = s.prompt ?? ""
|
const prompt = s.prompt ?? ""
|
||||||
const icon = icons[statuses[s.branch]]
|
const status = statuses[s.branch]
|
||||||
|
const icon = icons[status]
|
||||||
|
const bc = branchColors[status]
|
||||||
const maxPrompt = cols - prefixWidth
|
const maxPrompt = cols - prefixWidth
|
||||||
const truncated = maxPrompt > 3 && prompt.length > maxPrompt ? prompt.slice(0, maxPrompt - 3) + "..." : prompt
|
const truncated = maxPrompt > 3 && prompt.length > maxPrompt ? prompt.slice(0, maxPrompt - 3) + "..." : prompt
|
||||||
console.log(`${icon} ${s.branch.padEnd(branchWidth)} ${truncated}`)
|
console.log(`${icon} ${bc}${s.branch.padEnd(branchWidth)}${reset} ${dim}${truncated}${reset}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\n◌ idle · ◯ active · ◎ unsaved · ● saved`)
|
console.log(`\n${dim}◌ idle${reset} · ${green}◯ active${reset} · ${yellow}◎ unsaved${reset} · ${cyan}● saved${reset}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// ── sandlot open <branch> ─────────────────────────────────────────────
|
// ── sandlot open <branch> ─────────────────────────────────────────────
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user