0

I used toilet to write a simple pipeline to print out my username everytime I open the console and I wanted to be able to get it to slide consistently since the printed word is a few rows tall.

toilet -t -f ivrit 'rob93c' | lolcat

Script output

I tried to use this script to make it shift but I'm clearly missing something since it doesn't move

while true; do echo ' ' && toilet -t -f ivrit 'rob93c' | lolcat
sleep 1
done
  • I'm not aware of any tool that will do that for you directly - what have you tried? – Anya Shenanigans Mar 15 '19 at 15:39
  • Visiting the web page for `toilet` shows that it creates ASCII art for the letters of the word it is given. The [`lolcat`](https://github.com/busyloop/lolcat) command gives you a rainbow effect on text. So, you presumably need to capture the output from `toilet` into a file, and then display it through `lolcat`, then edit the file to add a blank at the beginning of each line, and send that through `lolcat`, and so on. A residual problem is positioning the repeat occurrences so that they start on the same line of the terminal each time. It also has to wrap after a while. What did you try? – Jonathan Leffler Mar 15 '19 at 15:44
  • I was thinking of using a process similar to the one to [add a progress bar](https://stackoverflow.com/questions/238073/how-to-add-a-progress-bar-to-a-shell-script) but with spaces instead of `#` @JonathanLeffler – Roberto Cella Mar 15 '19 at 15:58
  • 1
    So, what problem did you run into when you tried it? What code did you use? – Jonathan Leffler Mar 15 '19 at 16:02
  • 1
    BTW, while I'm answering this, note that it's not currently what we consider a good question; a good question resolves around a single, specific, narrow technical problem you encountered while trying to implement your code, and has everything unrelated to that problem factored out. – Charles Duffy Mar 15 '19 at 16:33

1 Answers1

1
slide() {
  local -a content
  local line prefixed_line cut_line

  readarray -t content || return                         # read our stdin into an array
  for ((prefix=0; prefix<=COLUMNS; prefix++)); do        # loop increasing # of spaces
    for line in "${content[@]}"; do                      # for lines in our input array...
      printf -v prefixed_line "%${prefix}s%s" '' "$line" # first add spaces in front
      cut_line=${prefixed_line:0:$COLUMNS}               # then trim to fit on one line
      printf '%s\n' "$cut_line"                          # finally, print our trimmed line
    done
    tput cuu "${#content[@]}"                            # move the cursor back up
  done
}

Used as:

toilet -t -f ivrit 'rob93c' | lolcat | slide

...or, to allow someone without all those tools installed to test:

printf '%s\n' 'one' '  two' '   three' | slide
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441