Matt. Stroh
Matt. Stroh

Reputation: 914

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.

Upvotes: 5

Views: 7523

Answers (5)

kbridge4096
kbridge4096

Reputation: 941

Or do a more thorough clear. This will clear your terminal's buffer:

io:format("\033\143").

Which equals to either of the following shell commands:

printf "\033\143"
tput reset

The latter requires you have ncurses installed.

Upvotes: 0

user3256372
user3256372

Reputation:

To clear the erl shell

io:format(os:cmd(clear)).

Upvotes: 15

Godfather
Godfather

Reputation: 59

As @Brujo Benavides mentioned earlier . The way to do that is to exit the current erl shell and start a new . You can use the halt(). function which is less tricky .

Upvotes: 1

Brujo Benavides
Brujo Benavides

Reputation: 1958

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)

Upvotes: 8

Thomas Dickey
Thomas Dickey

Reputation: 54524

Most of the terminals you would use on a Unix-like system support the VT100 hardware-reset escape sequence. You could use that in your program like this:

io:format("\ec").

That is instead of

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

although it would not hurt to do both. Also, it does not affect your variables, so you would still do

f().                      %% forget all

Combining these:

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

should be what you intended.

Upvotes: 8

Related Questions