4

I need to shift a FIGlet output (for example to the center of terminal). How can i do this? I tried

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

but it doesn't work.

It isn't obligatory to use figlet, it is possible to use any program which transforms the text to "ascii art".

thanks!

Upd1: sorry, guys. "centering" was just an example. Generally it is necessary for me to shift this text for a fixed rows and cols, like

tput cup 10 10
antonid
  • 178
  • 1
  • 9

2 Answers2

6

Centering is easy:

figlet -w $(tput cols) -c hello
  • the -c mean center
  • the -w num sets the line width for the figlet
  • the tput cols returns the columns of the current terminal

In the general, you can use the -w for setting the line width to some number, let say 40 and the use the -c and you will get the text shifted...

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

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

Also, you can shift the output by adding some spaces to the start, for example by sed

figlet hello | sed 's/^/               /'

or perl

figlet hello | perl -nle 'print " " x 30 . $_'
clt60
  • 62,119
  • 17
  • 107
  • 194
  • Figlet actually has this built in with `-t` so you can simply write `figlet -tc hello` – Cody Dec 12 '18 at 17:07
  • @Cody the `-t` just sets the output `width` to _"terminal width"_. Also, on some installations it not works and just prints error like: _"-t" is disabled, since ioctl is not fully implemented_. The OP asked for the output __shifting__ and the `-t` is definitely isn't the right solution. Read: [man figlet](http://www.figlet.org/figlet-man.html) – clt60 Dec 13 '18 at 18:41
1
~$ echo $'\r\r\r\r\r\r'; figlet '                           text'

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

~$
Ra_
  • 264
  • 2
  • 7