This commit is contained in:
Raven Scott
2026-04-27 21:56:22 -04:00
parent ff9ab499a2
commit 38e632e4b2
9 changed files with 60 additions and 6 deletions
+18
View File
@@ -88,12 +88,30 @@ function bareOsEmitRaw(ctx, chunk) {
}
async function run(ctx, argv) {
for (const a of argv.slice(1)) {
if (a === '--help' || a === '-h') {
ctx.console.error('Usage: clear')
return
}
if (a.startsWith('-')) {
ctx.console.error('clear: invalid option')
ctx.exitCode = 1
return
}
}
/* Keep in sync with packages/bare-os-booter/lib/terminal-escapes.js XTERM_CLEAR_SCROLLBACK_AND_VIEWPORT */
const seq = '\x1b[H\x1b[3J\x1b[2J\x1b[0m'
const term = String(ctx.vfs?.env?.TERM || globalThis.process?.env?.TERM || '')
if (term === 'dumb') return
if (typeof ctx.writeScreen === 'function') {
ctx.writeScreen(seq)
return
}
if (bareOsEmitRaw(ctx, seq)) return
globalThis.console.clear?.()
const ps = globalThis.process?.stdout
if (ps && typeof ps.write === 'function') {