This commit is contained in:
Raven Scott
2026-04-03 19:13:20 -04:00
parent 8002a66f6e
commit 04d903beb8
24 changed files with 564 additions and 74 deletions
+38 -3
View File
@@ -274,9 +274,10 @@ async function run(ctx, argv) {
function usage() {
ctx.console.error(
'usage: man [-k keyword] [-f name] [-l] [[section] name]\n' +
'usage: man [-k keyword] [-f name] [-l] [-w] [[section] name]\n' +
' Section 1: /bin; section 7: handbook + developer guide (man handbook, man devguide).\n' +
' Data: /share/man/man.json on the system drive.'
' Data: /share/man/man.json on the system drive.\n' +
' Long pages: set PAGER=bare-slice and optional MAN_SLICE=N (default 24) for section breaks.'
)
ctx.exitCode = 2
}
@@ -318,6 +319,10 @@ async function run(ctx, argv) {
mode = 'list'
continue
}
if (a === '-w' || a === '--where' || a === '--path') {
ctx.console.log('/share/man/man.json')
return
}
if (a.startsWith('-')) {
ctx.console.error('man: unknown option: ' + a)
ctx.exitCode = 2
@@ -474,5 +479,35 @@ async function run(ctx, argv) {
ctx.exitCode = 1
return
}
ctx.console.log(bareManRenderPage(page, ctx, width).replace(/\n$/, ''))
const rendered = bareManRenderPage(page, ctx, width).replace(/\n$/, '')
if (bareManSlicePage(rendered, env, ctx.console)) return
ctx.console.log(rendered)
}
/**
* @param {string} text
* @param {Record<string, string>} env
* @param {{ log: (s: string) => void }} cons
*/
function bareManSlicePage(text, env, cons) {
const pager = env.PAGER || ''
if (pager !== 'bare-slice' && pager !== 'bare_slice') return false
const raw = env.MAN_SLICE || '24'
const n = Number.parseInt(String(raw), 10)
const sliceLines = Number.isFinite(n) && n > 0 ? n : 24
const lines = text.split('\n')
const total = lines.length
for (let i = 0; i < total; i += sliceLines) {
const chunk = lines.slice(i, i + sliceLines).join('\n')
cons.log(chunk)
if (i + sliceLines < total) {
const hi = Math.min(i + sliceLines, total)
cons.log('')
cons.log(
`--- man: lines ${i + 1}-${hi} of ${total} (PAGER=bare-slice) ---`
)
cons.log('')
}
}
return true
}