How can we clear the screen in Iex on Windows?

Please, how can we clear the screen in Iex on Windows

The documented method in Iex help does not work:

  • clear/0 - clears the screen

stack overflow.squite

+5
source share
4 answers

I found this to be possible because the native terminal in Windows 10 supports ANSI colors and escape sequences. The only thing you need to enable in the iex shell.

According to https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/io/ansi.ex#L41 this parameter is configurable. As a quick fix, simply enter your iex session with the following code:

Application.put_env(:elixir, :ansi_enabled, true)

To make it permanent, you can configure the iex shell in the ~/.iex.exs ( https://hexdocs.pm/iex/IEx.html#module-configuring-the-shell ). Just paste the following into a file:

IEx.configure [colors: [enabled: true]]

+5
source

Yes, we cannot clear it on Windows, as far as I know. If there is one output that we can output to an I / O device for cleaning screens in Windows, I would like to know and add this function to Windows. :)

+3
source

Your best option (if this is a real problem for you, not annoyance) is to use an alternative Windows shell that supports ANSI Escape Sequences. See this S 0 question , why can't you just use ANSI Escape sequences in the Windows Cmd shell. An alternative to a single shell that supports ANSI, ConEmu . Setting up ConEmu on your computer is left as an exercise for the reader.

+3
source

You can use ANSI codes directly in iex on Windows with consoles that support them (e.g. ConEmu or the Windows 10 console.)

This will clear the screen in iex :

 iex> IO.write "\e[H\e[J"; IEx.dont_display_result 

Explanation:

  • IO.write is output to the console without a new line
  • \e[ is a prefix for ANSI CSI codes
  • H is the CSI Cursor Position position code with no arguments, by default moves the cursor to row 1, column 1
  • J is the CSI ED - Erase Display code without arguments, by default clears the screen from the current cursor position.
  • IEx.dont_display_result prevents the display of the result :ok IO.write after clearing the screen.

You can also clear the screen using IO.ANSI , rather than raw escape codes:

iex> IO.write [IO.ANSI.home, IO.ANSI.clear]; IEx.dont_display_result

Basically this is how clear/1 implemented .

+3
source

All Articles