2017-02-15 189 views
0

我需要移動一個FIGlet輸出(例如移動到終端的中心)。我怎樣才能做到這一點? 我試過如何移動figlet輸出

(tput sc ; tput cup 23 45 ; figlet text; tput rc) 

但它不起作用。

使用figlet不是強制性的,可以使用任何將文本轉換爲「ascii art」的程序。

謝謝!

Upd1:對不起,夥計們。 「居中」只是一個例子。一般來說,有必要對我來說,這個文本固定行列數轉移,像

tput cup 10 10 

回答

1

定心很簡單:

figlet -w $(tput cols) -c hello 
  • -c意味着中心
  • -w num設置的線寬爲figlet
  • tput cols返回當前終端

的列在一般情況下,你可以使用-wline width設置一些數字,讓說40和使用-c,你會得到的文本移動。 ..

$ figlet -w 30 -c hello 
    _   _ _  
    | |__ ___| | | ___ 
    | '_ \/_ \ | |/ _ \ 
    | | | | __/ | | (_) | 
    |_| |_|\___|_|_|\___/ 

$ figlet -w 50 -c hello 
       _   _ _  
       | |__ ___| | | ___ 
       | '_ \/_ \ | |/ _ \ 
       | | | | __/ | | (_) | 
       |_| |_|\___|_|_|\___/ 

此外,還可以輸出通過添加一些空格開始通過sed

figlet hello | sed 's/^/    /' 
轉移,例如

or perl

figlet hello | perl -nle 'print " " x 30 . $_' 
+0

謝謝! sed或perl表達,我需要! – antonid

0
~$ echo $'\r\r\r\r\r\r'; figlet '       text' 

          _   _ 
          | |_ _____ _| |_ 
          | __/ _ \ \//__| 
          | || __/> <| |_ 
          \__\___/_/\_\\__| 

~$