How do I reset/clear erlang terminal

2019-05-30 14:42发布

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.

4条回答
走好不送
2楼-- · 2019-05-30 15:08

To clear the erl shell

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

查看更多
在下西门庆
3楼-- · 2019-05-30 15:15

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 .

查看更多
萌系小妹纸
4楼-- · 2019-05-30 15:19

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.

查看更多
倾城 Initia
5楼-- · 2019-05-30 15:31

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)

查看更多
登录 后发表回答