Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update maybe_clear_terminal to remove scrollback #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

codeOfRobin
Copy link

@codeOfRobin codeOfRobin commented Apr 2, 2021

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 馃槄

`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](https://askubuntu.com/questions/25077/how-to-really-clear-the-terminal) led me to this solution. 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.
@codeOfRobin
Copy link
Author

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

@@ -2,6 +2,8 @@ defmodule MixTestWatch.Runner do
@moduledoc false

alias MixTestWatch.Config

@clear_ansi_escape_sequence "\x1bc"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work for me on macOS in iTerm2 until I changed it to \e[2J\e[3J\e[H.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange 馃 maybe this is one of those things that is terminal emulator dependent?

@petros
Copy link

petros commented Sep 1, 2022

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?

@eahanson
Copy link

eahanson commented May 8, 2024

I noticed that IO.ANSI isn't going to support clearing scrollback: elixir-lang/elixir#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
Copy link

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

#145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants