瀏覽代碼

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.
Sam Atkins 11 月之前
父節點
當前提交
75a989a7b6
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      packages/phoenix/src/puter-shell/coreutils/clear.js

+ 10 - 2
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');
     }
 };