[英]How can I send clear or reset with Term::Cap?
當我 output tput clear | hexdump -c
tput clear | hexdump -c
如果我在kitty
或xterm
上,我會得到不同的結果。 如何使用Term::Cap
在各個終端上生成這些終端信號?
我嘗試的是從帶有設置的文檔中直接復制粘貼,
use strict;
use warnings;
use Term::Cap;
use POSIX;
my $termios = new POSIX::Termios;
$termios->getattr;
my $ospeed = $termios->getospeed;
my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
然后我認為這應該可行,
$terminal->Tputs('clear', 1, *STDOUT );
但很可惜,它什么也沒做。
如果我為該術語提供一個不同的不存在的名稱(而不是默認為$ENV{TERM}
的undef
,我得到)
Can't find a valid termcap file at ./test.pl line 9.
所以我知道它正在查找termcap
文件並找到它。
所有 termcap 的信號名稱都是兩個字母。 為了清楚你會想要cl
$terminal->Tputs('cl', 1, *STDOUT );
您可以在man termcap
上找到完整列表,其中包含完整列表:
ch Move cursor horizontally only to column %1
cl Clear screen and cursor home
cm Cursor move to row %1 and column %2 (on screen)
感謝Thomas Dickey在評論中的回答
不知道我做錯了什么,作為我做的臨時工作
use constant CLEAR => do {
open( my $fh, '-|', qw(tput clear) );
scalar <$fh>;
};
這仍然需要啟動另一個過程,但效果很好。 如果有人知道如何以正確的方式做到這一點,我不會接受這個答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.