Add branch name prefix to spinner output

This commit is contained in:
Chris Wanstrath 2026-02-19 19:22:24 -08:00
parent e23e84655d
commit 9b6245d9c9
2 changed files with 14 additions and 13 deletions

View File

@ -19,8 +19,8 @@ program.name("sandlot").description("Branch-based development with git worktrees
// ── save helper ───────────────────────────────────────────────────── // ── save helper ─────────────────────────────────────────────────────
/** Stage all changes, generate a commit message, and commit. Returns true on success. */ /** Stage all changes, generate a commit message, and commit. Returns true on success. */
async function saveChanges(worktree: string, message?: string): Promise<boolean> { async function saveChanges(worktree: string, branch: string, message?: string): Promise<boolean> {
const spin = spinner("Staging changes") const spin = spinner("Staging changes", branch)
await $`git -C ${worktree} add .`.nothrow().quiet() await $`git -C ${worktree} add .`.nothrow().quiet()
@ -148,7 +148,7 @@ program
process.exit(1) process.exit(1)
} }
const spin = spinner("Creating worktree") const spin = spinner("Creating worktree", branch)
try { try {
await git.createWorktree(branch, worktreeAbs, root) await git.createWorktree(branch, worktreeAbs, root)
await mkdir(join(root, '.sandlot'), { recursive: true }) await mkdir(join(root, '.sandlot'), { recursive: true })
@ -186,7 +186,7 @@ program
await vm.claude(worktreeAbs, { prompt, print: opts.print }) await vm.claude(worktreeAbs, { prompt, print: opts.print })
} }
if (opts.save !== false) await saveChanges(worktreeAbs) if (opts.save !== false) await saveChanges(worktreeAbs, branch)
}) })
// ── sandlot list ────────────────────────────────────────────────────── // ── sandlot list ──────────────────────────────────────────────────────
@ -302,7 +302,7 @@ program
await state.setSession(root, { ...session, prompt: effectivePrompt }) await state.setSession(root, { ...session, prompt: effectivePrompt })
} }
const spin = spinner("Starting container") const spin = spinner("Starting container", branch)
await vm.ensure((msg) => { spin.text = msg }) await vm.ensure((msg) => { spin.text = msg })
if (opts.print) { if (opts.print) {
@ -319,7 +319,7 @@ program
await vm.claude(session.worktree, { prompt, print: opts.print }) await vm.claude(session.worktree, { prompt, print: opts.print })
} }
if (opts.save !== false) await saveChanges(session.worktree) if (opts.save !== false) await saveChanges(session.worktree, branch)
}) })
// ── sandlot review <branch> ────────────────────────────────────────── // ── sandlot review <branch> ──────────────────────────────────────────
@ -338,7 +338,7 @@ program
process.exit(1) process.exit(1)
} }
const spin = spinner("Starting container") const spin = spinner("Starting container", branch)
await vm.ensure((msg) => { spin.text = msg }) await vm.ensure((msg) => { spin.text = msg })
const prompt = "You're a grumpy old senior software engineer. Take a look at the diff between this branch and main, then let me know your thoughts. My co-worker made these changes." const prompt = "You're a grumpy old senior software engineer. Take a look at the diff between this branch and main, then let me know your thoughts. My co-worker made these changes."
@ -398,7 +398,7 @@ program
// Resolve conflicts with Claude // Resolve conflicts with Claude
console.log(`◆ Merge conflicts in ${conflicts.length} file(s). Resolving with Claude...`) console.log(`◆ Merge conflicts in ${conflicts.length} file(s). Resolving with Claude...`)
const spin = spinner("Starting container") const spin = spinner("Starting container", branch)
try { try {
await vm.ensure((msg) => { spin.text = msg }) await vm.ensure((msg) => { spin.text = msg })
@ -462,7 +462,7 @@ program
process.exit(1) process.exit(1)
} }
const ok = await saveChanges(session.worktree, message) const ok = await saveChanges(session.worktree, branch, message)
if (!ok) process.exit(1) if (!ok) process.exit(1)
}) })

View File

@ -1,9 +1,10 @@
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
export function spinner(text: string) { export function spinner(text: string, prefix?: string) {
const tag = prefix ? `\x1b[2m[${prefix}]\x1b[22m ` : ""
let i = 0 let i = 0
const id = setInterval(() => { const id = setInterval(() => {
process.stderr.write(`\r\x1b[2K${frames[i++ % frames.length]} ${text}`) process.stderr.write(`\r\x1b[2K${frames[i++ % frames.length]} ${tag}${text}`)
}, 80) }, 80)
return { return {
@ -12,11 +13,11 @@ export function spinner(text: string) {
}, },
succeed(msg: string) { succeed(msg: string) {
clearInterval(id) clearInterval(id)
process.stderr.write(`\r\x1b[2K✔ ${msg}\n`) process.stderr.write(`\r\x1b[2K✔ ${tag}${msg}\n`)
}, },
fail(msg: string) { fail(msg: string) {
clearInterval(id) clearInterval(id)
process.stderr.write(`\r\x1b[2K✖ ${msg}\n`) process.stderr.write(`\r\x1b[2K✖ ${tag}${msg}\n`)
}, },
stop() { stop() {
clearInterval(id) clearInterval(id)