Update Manpage
This commit is contained in:
+81
-10
@@ -89,11 +89,61 @@ function bareOsEmitRaw(ctx, chunk) {
|
||||
|
||||
/** Plain-text manual formatter (prepended before src/man.js; no import in /bin/man). */
|
||||
|
||||
function bareManParseWidth(env) {
|
||||
const BARE_MAN_WIDTH_MIN = 40
|
||||
const BARE_MAN_WIDTH_MAX = 200
|
||||
const BARE_MAN_WIDTH_DEFAULT = 72
|
||||
|
||||
/**
|
||||
* @param {number} n
|
||||
* @returns {number}
|
||||
*/
|
||||
function bareManClampWidth(n) {
|
||||
return Math.max(BARE_MAN_WIDTH_MIN, Math.min(n, BARE_MAN_WIDTH_MAX))
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, unknown> | null | undefined} ctx
|
||||
* @returns {number | null} usable column count, or null if unknown
|
||||
*/
|
||||
function bareManTryTerminalColumns(ctx) {
|
||||
if (!ctx || typeof ctx !== 'object') return null
|
||||
if (ctx.bareOsStdoutCaptured) return null
|
||||
const streams = []
|
||||
if (ctx.stdout) streams.push(ctx.stdout)
|
||||
if (ctx.replStdout && ctx.replStdout !== ctx.stdout) streams.push(ctx.replStdout)
|
||||
for (const s of streams) {
|
||||
if (
|
||||
s &&
|
||||
s.isTTY &&
|
||||
typeof s.columns === 'number' &&
|
||||
Number.isFinite(s.columns) &&
|
||||
s.columns > 0
|
||||
) {
|
||||
return bareManClampWidth(s.columns)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, string | undefined> | null | undefined} env
|
||||
* @param {Record<string, unknown> | null | undefined} ctx
|
||||
*/
|
||||
function bareManParseWidth(env, ctx) {
|
||||
const raw = env && env.MANWIDTH != null ? String(env.MANWIDTH).trim() : ''
|
||||
const n = raw ? Number.parseInt(raw, 10) : 72
|
||||
if (!Number.isFinite(n)) return 72
|
||||
return Math.max(40, Math.min(n, 200))
|
||||
if (raw) {
|
||||
const n = Number.parseInt(raw, 10)
|
||||
if (!Number.isFinite(n)) return BARE_MAN_WIDTH_DEFAULT
|
||||
return bareManClampWidth(n)
|
||||
}
|
||||
const fromTTY = bareManTryTerminalColumns(ctx)
|
||||
if (fromTTY != null) return fromTTY
|
||||
const colRaw = env && env.COLUMNS != null ? String(env.COLUMNS).trim() : ''
|
||||
if (colRaw) {
|
||||
const c = Number.parseInt(colRaw, 10)
|
||||
if (Number.isFinite(c) && c > 0) return bareManClampWidth(c)
|
||||
}
|
||||
return BARE_MAN_WIDTH_DEFAULT
|
||||
}
|
||||
|
||||
function bareManUseAnsi(ctx) {
|
||||
@@ -298,14 +348,18 @@ function bareManRenderPage(page, ctx, width) {
|
||||
}
|
||||
|
||||
async function run(ctx, argv) {
|
||||
const env = ctx.env || {}
|
||||
const width = bareManParseWidth(env)
|
||||
const env = Object.assign(
|
||||
{},
|
||||
ctx.vfs && ctx.vfs.env && typeof ctx.vfs.env === 'object' ? ctx.vfs.env : {},
|
||||
ctx.env && typeof ctx.env === 'object' ? ctx.env : {}
|
||||
)
|
||||
const width = bareManParseWidth(env, ctx)
|
||||
const args = argv.slice(1)
|
||||
|
||||
function usage() {
|
||||
ctx.console.error(
|
||||
'usage: man [-k keyword] [-f name] [-l] [-w] [[section] name]\n' +
|
||||
' Section 1: /bin; section 7: handbook + developer guide (man handbook, man devguide).\n' +
|
||||
' Section 1: /bin; section 7: handbook + user manual + developer guide + docs/ (man handbook, man users-manual, man devguide, man docs).\n' +
|
||||
' 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.'
|
||||
)
|
||||
@@ -396,12 +450,21 @@ async function run(ctx, argv) {
|
||||
}
|
||||
|
||||
if (mode === 'list') {
|
||||
const CAT_ORDER = ['coreutils', 'extra', 'handbook', 'devguide']
|
||||
const CAT_ORDER = [
|
||||
'coreutils',
|
||||
'extra',
|
||||
'handbook',
|
||||
'usersmanual',
|
||||
'devguide',
|
||||
'docs'
|
||||
]
|
||||
const CAT_HEADING = {
|
||||
coreutils: 'Section 1 — /bin utilities',
|
||||
extra: 'Section 1 — Git and shell',
|
||||
handbook: 'Section 7 — Handbook',
|
||||
devguide: 'Section 7 — Developer guide'
|
||||
usersmanual: 'Section 7 — User manual',
|
||||
devguide: 'Section 7 — Developer guide',
|
||||
docs: 'Section 7 — Documentation (docs/)'
|
||||
}
|
||||
function listCategoryOf(p) {
|
||||
const c = p.listCategory
|
||||
@@ -409,13 +472,21 @@ async function run(ctx, argv) {
|
||||
c === 'coreutils' ||
|
||||
c === 'extra' ||
|
||||
c === 'handbook' ||
|
||||
c === 'devguide'
|
||||
c === 'usersmanual' ||
|
||||
c === 'devguide' ||
|
||||
c === 'docs'
|
||||
)
|
||||
return c
|
||||
if (p.section === 7) {
|
||||
const n = p.name
|
||||
if (n.startsWith('devguide-') || n === 'bare-os-developer-guide')
|
||||
return 'devguide'
|
||||
if (n.startsWith('docs-') || n === 'bare-os-docs') return 'docs'
|
||||
if (
|
||||
n.startsWith('users-manual-') ||
|
||||
n === 'bare-os-users-manual'
|
||||
)
|
||||
return 'usersmanual'
|
||||
return 'handbook'
|
||||
}
|
||||
if (p.name === 'git' || p.name === 'bare-os-shell') return 'extra'
|
||||
|
||||
Reference in New Issue
Block a user