From 1e89608d11bd66f353a96efdeaadc9880309cc35 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Mon, 23 Feb 2026 21:28:23 -0800 Subject: [PATCH] Add stat formatting with colorized diff indicators --- src/commands/web.ts | 17 ++++++++++++++++- src/git.ts | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/commands/web.ts b/src/commands/web.ts index 1f4b95b..757d3e1 100644 --- a/src/commands/web.ts +++ b/src/commands/web.ts @@ -25,7 +25,7 @@ export async function action(branch: string) { .replaceAll("{{BRANCH}}", escapeHtml(branch)) .replace("{{PROMPT_SECTION}}", () => session.prompt ? `

${escapeHtml(session.prompt)}

` : "") .replace("{{LOG_SECTION}}", () => log ? `

Commits

${escapeHtml(log)}
` : "") - .replace("{{STAT_SECTION}}", () => stat ? `

Stats

${escapeHtml(stat)}
` : "") + .replace("{{STAT_SECTION}}", () => stat ? `

Stats

${formatStat(stat)}
` : "") .replace("{{DIFF_JSON}}", () => diffJson) const tmpPath = `/tmp/sandlot-${branch}.html` @@ -33,6 +33,21 @@ export async function action(branch: string) { await $`open ${tmpPath}`.nothrow().quiet() } +function formatStat(raw: string): string { + // strip leading space from lines to match the unindented first line + const trimmed = raw.split("\n").map(l => l.startsWith(" ") ? l.slice(1) : l).join("\n") + const escaped = escapeHtml(trimmed) + // colorize + and - in the bar portion (after the |) + return escaped.split("\n").map(line => { + const pipe = line.indexOf("|") + if (pipe === -1) return line + return line.slice(0, pipe + 1) + + line.slice(pipe + 1) + .replace(/\+/g, '+') + .replace(/-/g, '-') + }).join("\n") +} + function escapeHtml(str: string): string { return str .replace(/&/g, "&") diff --git a/src/git.ts b/src/git.ts index 7afd7de..5aee49f 100644 --- a/src/git.ts +++ b/src/git.ts @@ -198,7 +198,7 @@ export async function commitLog(range: string, cwd: string): Promise { /** Get a diff stat summary for a revision range. Returns empty string on failure. */ export async function diffStat(range: string, cwd: string): Promise { - const result = await $`git diff --stat ${range}`.cwd(cwd).nothrow().quiet() + const result = await $`git diff --stat --stat-width=68 ${range}`.cwd(cwd).nothrow().quiet() if (result.exitCode !== 0) return "" return result.text().trim() }