mix-test.watch icon indicating copy to clipboard operation
mix-test.watch copied to clipboard

Update `maybe_clear_terminal` to remove scrollback

Open codeOfRobin opened this issue 3 years ago • 4 comments

IO.ANSI.clear + home seem to not clear scrollback (atleast on macOS), i.e. it prints "one screen height" of blank space and resets the cursor to the first position. A little bit of digging through ANSI escape codes led me to this solution.

PS: I'm not sure if this is the best approach/if there's a way to get the right sequence out from the IO.ANSI library, I'm still an Elixir beginner 😅

codeOfRobin avatar Apr 02 '21 00:04 codeOfRobin

Steps to test:

  1. Add {:mix_test_watch, git: "git://github.com/codeOfRobin/mix-test.watch", only: :dev, runtime: false}, to your mix.exs.
  2. Run mix test.watch and try making a few changes
  3. You shouldn't have your scrollback anymore in Terminal

codeOfRobin avatar Apr 02 '21 00:04 codeOfRobin

I opened #136 yesterday, and then I noticed this PR.

Is this still open because the project is stale or because the ANSI sequence does not work on all terminals?

For me, this works:

clear && printf '\e[3J'

which should be:

IO.puts(IO.ANSI.clear() <> "\e[3J")

in Elixir.

What can we do to have this PR merged?

Another possible issue with the PR may be that not everyone wants their scroll-back cleared. This could be addressed with a configuration option.

cc @lpil could we get some guidance? Are you accepting contributions?

petros avatar Sep 01 '22 07:09 petros

I noticed that IO.ANSI isn't going to support clearing scrollback: https://github.com/elixir-lang/elixir/pull/10030

Perhaps there could be a second config like config :mix_test_watch, clear_scrollback: <option>, where option could be :macos_terminal, :macos_iterm, any random escape sequence, nil, or false? (And if there were other common escape sequences, they could be added as options?)

eahanson avatar May 08 '24 19:05 eahanson

I created a new PR that allows you to specify the ANSI sequence for clearing the scrollback buffer, along with two presets: :macos_terminal and :macos_iterm2

https://github.com/lpil/mix-test.watch/pull/145

eahanson avatar May 10 '24 23:05 eahanson