[英]How do I reset/clear erlang terminal
我正在嘗試重置提示,忘記所有變量並從第 1 行開始提示 >
我知道以下內置函數
f(). %% forget all
io:format("\e[H\e[J"). %% "clear screen" and moving cursor to the begin of the line
但是當我編寫以下命令時,它確實忘記了所有變量,但它不會“重置”屏幕,只是清除屏幕,就像終端中的clear
命令一樣。
在 Linux 中,我只是鍵入reset
,但我找不到等效的命令或在 function 中為 erlang 內置來執行此操作。
我也試過io:format(os:cmd("reset")).
但我收到錯誤。
我現在的解決方案是退出 erlang 終端,然后重新打開它,但我相信有更簡單的方法可以做到這一點。
您將在類Unix系統上使用的大多數終端都支持VT100 硬件重置轉義序列。 您可以像下面這樣在程序中使用它:
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
應該是您想要的。
一種比較棘手的方法是通過按ctrl-g然后按s
, c
來啟動新的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
)
清除erl shell
io:format(os:cmd(clear)).
正如@Brujo Benavides之前提到的。 這樣做的方法是退出當前的erl shell並啟動一個新的。 您可以使用halt().
功能不那么棘手。
或者做一個更徹底的清除。 這將清除您終端的緩沖區:
io:format("\033\143").
這等於以下任一 shell 命令:
printf "\033\143"
tput reset
后者要求您安裝了ncurses
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.