Featured image of post Figlet ASCII Graphics

Figlet ASCII Graphics

Creating beautiful header comments

Bomberman from here.

Introduction

1
2
3
4
5
6
7
#  ┬ ┬┬─┐┬  ┬  ┌─┐    #  ┳━┓┳━┓┏┓┓┳━┓┳━┓┳━┓┓━┓┳━┓┓━┓
#  │─┤├─ │  │  │ │    #  ┃ ┃┃━┫ ┃ ┃━┫┃━┃┃━┫┗━┓┣━ ┗━┓
#  ┘ ┴┴─┘┘─┘┘─┘┘─┘    #  ┇━┛┛ ┇ ┇ ┛ ┇┇━┛┛ ┇━━┛┻━┛━━┛

#  ┳━┓┓ ┳┓━┓  ┳━┓┏━┓┏━┓     #  ┌┐┐┬─┐┌┐┐┐ ┬┌─┐┬─┐┬┌ 
#  ┃━┫┃┃┃┗━┓  ┣━ ┃  ┏━┛     #  │││├─  │ ││││ ││┬┘├┴┐
#  ┛ ┇┗┻┇━━┛  ┻━┛┗━┛┗━━     #  ┘└┘┴─┘ ┘ └┴┘┘─┘┘└┘┘ ┘

I insert such captions in the source codes to visually separate chunks. In Terraform, for example.

Installation

Install figlet in any way suitable for your distribution.
Download additional fonts.

1
2
curl -Lo- 'https://github.com/vlasov-y/figlet-fonts/archive/refs/tags/v1.1.tar.gz' | \
sudo tar -C "$(figlet -I2)" --strip-components 1 -xpzvf -

Viewing All Fonts

1
2
3
4
find "$(figlet -I2)" -type f -name '*.*f' | while read -r i; do 
  echo "> $i"
  figlet -f "$i" "$(basename "$i")"
done | less

Function for .bashrc

Be careful here. In the overwhelming majority of fonts, there are characters that won’t display at all or will be shown incorrectly (as rectangles) for your colleagues who pulled the same code from Git. Through trial and error, I found a universal and beautiful font for myself - Rusto. There’s also RustoFat, which I actually like more, but it has its problems. 😢

1
2
3
4
5
6
7
#  ┬─┐┬ ┐┐─┐┌┐┐┌─┐
#  │┬┘│ │└─┐ │ │ │
#  ┘└┘┘─┘──┘ ┘ ┘─┘

#  ┳━┓┳ ┓┓━┓┏┓┓┏━┓┳━┓┳━┓┏┓┓
#  ┃┳┛┃ ┃┗━┓ ┃ ┃ ┃┣━ ┃━┫ ┃ 
#  ┇┗┛┇━┛━━┛ ┇ ┛━┛┇  ┛ ┇ ┇ 

The captions above were generated using my function, so your Rusto will differ slightly. Add this function to your .bashrc or .zshrc, and you can use it. Also, you’ll need to install xsel.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
rusto () {
  figlet -f rusto "$*" | sed "s@^@${P:-#  }@g; s@┆@┘@g" | tee /tmp/tt | xsel -i -b
  cat /tmp/tt
  rm -f /tmp/tt
}

rustofat () {
  figlet -f rustofat "$*" | sed "s@^@${P:-#  }@g" | tee /tmp/tt | xsel -i -b
  cat /tmp/tt
  rm -f /tmp/tt
}

What happens here? When you execute the command in the console rusto or rustofat, the text passed as arguments to the commands will be transformed, displayed on the screen, and immediately copied to the clipboard. Also, the symbol is replaced with to make Rusto completely problem-free. Additionally, # is prepended to the start of each line, allowing you to paste it directly into the source code. You can replace the hash by setting the variable P.

1
2
3
4
5
6
7
8
9
❯ rusto hello world
#  ┬ ┬┬─┐┬  ┬  ┌─┐  ┐ ┬┌─┐┬─┐┬  ┬─┐
#  │─┤├─ │  │  │ │  ││││ ││┬┘│  │ │
#  ┘ ┴┴─┘┘─┘┘─┘┘─┘  └┴┘┘─┘┘└┘┘─┘┘─┘

P='//  ' rustofat changed comment char
//  ┏━┓┳ ┳┳━┓┏┓┓┏━┓┳━┓┳━┓  ┏━┓┏━┓┏┏┓┏┏┓┳━┓┏┓┓┏┓┓  ┏━┓┳ ┳┳━┓┳━┓
//  ┃  ┃━┫┃━┫┃┃┃┃ ┳┣━ ┃ ┃  ┃  ┃ ┃┃┃┃┃┃┃┣━ ┃┃┃ ┃   ┃  ┃━┫┃━┫┃┳┛
//  ┗━┛┇ ┻┛ ┇┇┗┛┇━┛┻━┛┇━┛  ┗━┛┛━┛┛ ┇┛ ┇┻━┛┇┗┛ ┇   ┗━┛┇ ┻┛ ┇┇┗┛

Bonus

I generate the daily report form like this.

1
2
3
4
LC_ALL=C.POSIX date '+%d %B' | \
figlet | \
xargs -0 printf '```\n%s```\nNo blocks\nNo questions\nDone\\Doing:\n' | \
xsel -ib

It produces something like this.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
```
  ___   __         _                                    
 / _ \ / /_       | | __ _ _ __  _   _  __ _ _ __ _   _ 
| | | | '_ \   _  | |/ _` | '_ \| | | |/ _` | '__| | | |
| |_| | (_) | | |_| | (_| | | | | |_| | (_| | |  | |_| |
 \___/ \___/   \___/ \__,_|_| |_|\__,_|\__,_|_|   \__, |
                                                  |___/ 
```
No blocks
No questions
Done\Doing:
- Drinking tea
- Sleeping
- Writing evening report
- Emulating work

Then I add what I did and send it to Slack.

Licensed under Apache License, Version 2.0
Last updated on Oct 17, 2024 12:47 +0300
All rights reserved
Built with Hugo
Theme Stack designed by Jimmy