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 codesH is the CSI Cursor Position position code with no arguments, by default moves the cursor to row 1, column 1J 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 .
source share