From 75a989a7b69bfdfdf69e5f0365027c5b27d8bfc6 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 26 Jun 2024 20:01:01 +0100 Subject: [PATCH] feat(phoenix): Make `clear` clear scrollback unless `-x` is given From what I understand, we shouldn't need both `\x1B[2J` and `\x1B[3J` sequences to clear everything, but xterm.js would not correctly clear the visible region with only `\x1B[3J`. So, we have both. --- packages/phoenix/src/puter-shell/coreutils/clear.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/phoenix/src/puter-shell/coreutils/clear.js b/packages/phoenix/src/puter-shell/coreutils/clear.js index d38bf87692..4e17963a86 100644 --- a/packages/phoenix/src/puter-shell/coreutils/clear.js +++ b/packages/phoenix/src/puter-shell/coreutils/clear.js @@ -21,11 +21,19 @@ export default { usage: 'clear', description: 'Clear the terminal output.', args: { - // TODO: add 'none-parser' $: 'simple-parser', - allowPositionals: false + allowPositionals: false, + options: { + 'keep-scrollback': { + description: 'Only clear the visible portion of the screen, and keep the scrollback.', + type: 'boolean', + short: 'x', + } + }, }, execute: async ctx => { await ctx.externs.out.write('\x1B[H\x1B[2J'); + if (!ctx.locals.values['keep-scrollback']) + await ctx.externs.out.write('\x1B[H\x1B[3J'); } };