如何重置/清除erlang终端

Mat*_*roh 1 terminal erlang reset

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

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

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

在Linux中,我只是键入reset,但我找不到等效的命令或内置函数为erlang做到这一点.

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

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

小智 9

清除erl外壳

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


Tho*_*key 5

您将在类Unix系统上使用的大多数终端支持VT100 硬件重置转义序列.您可以在程序中使用它,如下所示:

io:format("\ec").
Run Code Online (Sandbox Code Playgroud)

这是不是

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

虽然做两者都不会有害.此外,它不会影响您的变量,所以您仍然会这样做

f().                      %% forget all
Run Code Online (Sandbox Code Playgroud)

结合这些:

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

应该是你的意图.


小智 5

一个有点棘手的方法是通过按ctrl-g启动一个新的shell然后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>
Run Code Online (Sandbox Code Playgroud)

当然,这并不清楚屏幕.你必须使用你自己的控制台机制(我在OSX上使用iTerm,我只是cmd-k为了这个)

  • 您可以使用 `k` 杀死原始 shell。所以它是^G k⏎ s⏎ c⏎。 (2认同)