Search code examples
terminalerlangreset

How do I reset/clear erlang terminal


I'm trying to get the prompt reset, forget all the variables and start the prompt from line 1>
I'm aware of the following built-in functions

f().                      %% forget all
io:format("\e[H\e[J").    %% "clear screen" and moving cursor to the begin of the line

but when I'm writing the following commands, it does forget all the variables, but it doesn't "reset" the screen, just clear the screen, like clear command in the terminal.

in Linux, I just type reset, but I couldn't find equivalent command or built in function for erlang to do that.

I also tried io:format(os:cmd("reset")). but I received error.

my solution for now is to quit the erlang terminal, and reopen it again, but I'm sure there is much easier ways to do that.


Solution

  • A somewhat tricky way to do it would be to just start a new shell by pressing ctrl-g and then s, c

    $ erl
    Erlang/OTP 18 [erts-7.3] [source-d2a6d81] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
    
    Eshell V7.3  (abort with ^G)
    1> A = 1.
    1
    2>
    User switch command
     --> s
     --> c
    Eshell V7.3  (abort with ^G)
    1> A.
    * 1: variable 'A' is unbound
    2>
    

    Of course that doesn't clear the screen. You have to use your own console mechanisms for that (I use iTerm on OSX and I just hit cmd-k for that)