Updates
This commit is contained in:
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user