toes diff pager
This commit is contained in:
parent
725f893592
commit
89ea6f586a
|
|
@ -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',
|
||||
|
|
|
|||
35
src/cli/pager.ts
Normal file
35
src/cli/pager.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
export async function withPager(fn: () => Promise<void> | void): Promise<void> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user