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 ? `` : "") - .replace("{{STAT_SECTION}}", () => stat ? `` : "") + .replace("{{STAT_SECTION}}", () => 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