From 89ea6f586ad2ab1dcf4fb6e7623f82dd2c847cb4 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 10 Feb 2026 08:09:00 -0800 Subject: [PATCH] toes diff pager --- apps/cron/20260201-000000/index.tsx | 1 + src/cli/pager.ts | 35 +++++++++++++++++++++++++++++ src/cli/setup.ts | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/cli/pager.ts diff --git a/apps/cron/20260201-000000/index.tsx b/apps/cron/20260201-000000/index.tsx index 53af2d6..6acdad3 100644 --- a/apps/cron/20260201-000000/index.tsx +++ b/apps/cron/20260201-000000/index.tsx @@ -74,6 +74,7 @@ const Time = define('Time', { const RunButton = define('RunButton', { base: 'button', padding: '4px 10px', + marginTop: '10px', fontSize: '12px', backgroundColor: theme('colors-primary'), color: 'white', diff --git a/src/cli/pager.ts b/src/cli/pager.ts new file mode 100644 index 0000000..d77d070 --- /dev/null +++ b/src/cli/pager.ts @@ -0,0 +1,35 @@ +export async function withPager(fn: () => Promise | void): Promise { + if (!process.stdout.isTTY) { + await fn() + return + } + + const lines: string[] = [] + const originalLog = console.log + + console.log = (...args: unknown[]) => { + lines.push(args.map(a => typeof a === 'string' ? a : String(a)).join(' ')) + } + + try { + await fn() + } finally { + console.log = originalLog + } + + if (lines.length === 0) return + + const text = lines.join('\n') + '\n' + const rows = process.stdout.rows || 24 + const lineCount = text.split('\n').length - 1 + + if (lineCount > rows) { + Bun.spawnSync(['less', '-R'], { + stdin: Buffer.from(text), + stdout: 'inherit', + stderr: 'inherit', + }) + } else { + process.stdout.write(text) + } +} diff --git a/src/cli/setup.ts b/src/cli/setup.ts index 0c6e2ad..590c11d 100644 --- a/src/cli/setup.ts +++ b/src/cli/setup.ts @@ -3,6 +3,7 @@ import { program } from 'commander' import color from 'kleur' import pkg from '../../package.json' +import { withPager } from './pager' import { cleanApp, configShow, @@ -187,7 +188,7 @@ program .command('diff') .helpGroup('Sync:') .description('Show diff of changed files') - .action(diffApp) + .action(() => withPager(diffApp)) program .command('sync')