toes diff pager
This commit is contained in:
parent
725f893592
commit
89ea6f586a
|
|
@ -74,6 +74,7 @@ const Time = define('Time', {
|
||||||
const RunButton = define('RunButton', {
|
const RunButton = define('RunButton', {
|
||||||
base: 'button',
|
base: 'button',
|
||||||
padding: '4px 10px',
|
padding: '4px 10px',
|
||||||
|
marginTop: '10px',
|
||||||
fontSize: '12px',
|
fontSize: '12px',
|
||||||
backgroundColor: theme('colors-primary'),
|
backgroundColor: theme('colors-primary'),
|
||||||
color: 'white',
|
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 color from 'kleur'
|
||||||
|
|
||||||
import pkg from '../../package.json'
|
import pkg from '../../package.json'
|
||||||
|
import { withPager } from './pager'
|
||||||
import {
|
import {
|
||||||
cleanApp,
|
cleanApp,
|
||||||
configShow,
|
configShow,
|
||||||
|
|
@ -187,7 +188,7 @@ program
|
||||||
.command('diff')
|
.command('diff')
|
||||||
.helpGroup('Sync:')
|
.helpGroup('Sync:')
|
||||||
.description('Show diff of changed files')
|
.description('Show diff of changed files')
|
||||||
.action(diffApp)
|
.action(() => withPager(diffApp))
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('sync')
|
.command('sync')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user