如何重置/清除erlang终端

时间:2016-06-15 08:23:48

标签: terminal erlang reset

我正在尝试重置提示,忘记所有变量并从第1行开始提示>
我知道以下内置函数

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

但是当我编写以下命令时,它确实忘记了所有变量,但它没有“重置”屏幕,只是清除屏幕,就像终端中的clear命令一样。

在Linux中,我只输入reset,但我找不到等效的命令或内置函数来执行该操作。

我也试过io:format(os:cmd("reset")).,但收到错误。

我现在的解决方案是退出erlang终端,然后重新打开它,但我确信有更简单的方法可以做到这一点。

3 个答案:

答案 0 :(得分:5)

您在类Unix系统上使用的大多数终端都支持VT100 hardware-reset转义序列。您可以在程序中使用它,如下所示:

io:format("\ec").

io:format("\e[H\e[J").    %% "clear screen" and moving cursor to the begin of the line
尽管做到这两点并不会有害。此外,它不会影响您的变量,因此您仍然可以

f().                      %% forget all

结合这些:

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

应该是你想要的。

答案 1 :(得分:5)

有点棘手的方法是通过按ctrl-g然后sc

来启动新的shell
$ 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>

当然,这并没有清除屏幕。您必须使用自己的控制台机制(我在OSX上使用iTerm而我只需点击cmd-k

答案 2 :(得分:1)

正如@Brujo Benavides前面提到的那样。这样做的方法是退出当前的erl shell并启动一个新的。您可以使用不那么棘手的halt().函数。

相关问题