deno icon indicating copy to clipboard operation
deno copied to clipboard

fix(cli): Make --watcher CLEAR_SCREEN clear scrollback buffer as well as visible screen

Open chrisveness opened this issue 1 year ago • 5 comments

The --watch option should clear the screen scrollback buffer as well as the screen itself.

On Ubuntu (22.04 Jammy) the 'clear' command generates "\x1B[H\x1B[2J\x1B[3J"; that is:

  • \E[H - cursor home
  • \E[2J - clear entire screen
  • \E[3J - clear entire screen & scrollback buffer.

By contrast, Deno defined CLEAR_SCREEN as "\x1B[2J\x1B[1;1H", which fails to clear the scrollback buffer.

The "\E[H\E[2J\E[3J" sequence works on MacOS (Sonoma) (using printf); I'm not able to test on Windows.

chrisveness avatar Oct 02 '24 18:10 chrisveness

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 02 '24 18:10 CLAassistant

Thanks for the PR, could you give some context on why you think it's a desirable change? This functionality was modelled based on what other frameworks are doing (like vitest).

bartlomieju avatar Oct 02 '24 22:10 bartlomieju

@bartlomieju, the Node.js file watcher for file changes (node --watch) clears the scrollback buffer as well as the visible part of the screen.

If I have a lot of logged output, when the watch option restarts the process, with Node.js I can scroll back to the top of the screen to see the start of the current process. With the current Deno watcher (deno --watch), the start of the process will be buried somewhere in the middle of the scrollback buffer.

I note there has been discussion about test behaviour previously, but I believe this is unrelated to, and I assume would not affect, considerations around testing.

chrisveness avatar Oct 03 '24 10:10 chrisveness

@bartlomieju did that explanation make sense? Do you want any further information?

chrisveness avatar Oct 11 '24 08:10 chrisveness

@bartlomieju The Node.js File Watcher apparently uses "\x1Bc" (ESC c – Reset to Initial State (RIS)) to clear the screen on file change:

I don't know if this might be preferable to "\x1B[H\x1B[2J\x1B[3J" – either way would appear to work well.

As I mentioned, this PR is unrelated to testing; Node.js is the obvious comparison (I don't know what bun does).

chrisveness avatar Oct 21 '24 12:10 chrisveness

Maybe fixes https://github.com/denoland/deno/issues/26514?

bartlomieju avatar Oct 26 '24 21:10 bartlomieju

Okay I can see change in VSCode terminal. This should actually fix https://github.com/denoland/deno/issues/26514.

bartlomieju avatar Oct 26 '24 22:10 bartlomieju