How to Customize ASCII Art Banners with Figlet

LinuxLinuxBeginner
Practice Now

Introduction

Figlet is a powerful open-source tool that allows you to transform regular text into visually striking ASCII art banners in the terminal. Whether you need to create attention-grabbing headers, logos, or simply add a touch of creativity to your command-line projects, Figlet makes it easy to do so. This tutorial will guide you through the basics of using Figlet, customizing your banners, and exploring advanced techniques to take your ASCII art to the next level.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/InputandOutputRedirectionGroup(["`Input and Output Redirection`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/BasicSystemCommandsGroup -.-> linux/clear("`Screen Clearing`") linux/BasicSystemCommandsGroup -.-> linux/printf("`Text Formatting`") linux/InputandOutputRedirectionGroup -.-> linux/tee("`Output Multiplexing`") subgraph Lab Skills linux/echo -.-> lab-419328{{"`How to Customize ASCII Art Banners with Figlet`"}} linux/clear -.-> lab-419328{{"`How to Customize ASCII Art Banners with Figlet`"}} linux/printf -.-> lab-419328{{"`How to Customize ASCII Art Banners with Figlet`"}} linux/tee -.-> lab-419328{{"`How to Customize ASCII Art Banners with Figlet`"}} end

Introducing Figlet: ASCII Art in the Terminal

Figlet is a popular open-source tool that allows you to create ASCII art text banners in the terminal. It is a powerful utility that can transform regular text into eye-catching, stylized text displays. Figlet is particularly useful for creating attention-grabbing headers, logos, or simply adding a touch of creativity to your terminal-based projects.

One of the key advantages of Figlet is its simplicity. To use it, you simply need to provide the text you want to transform, and Figlet will automatically generate the corresponding ASCII art. This makes it an excellent choice for quickly adding visual flair to your command-line applications, scripts, or even personal projects.

$ figlet "Hello, World!"
 _   _      _ _        __        __         _     _
| | | | ___| | | ___   \ \      / /__  _ __| | __| |
| |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |
|  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |
|_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

In the example above, we use the figlet command to transform the text "Hello, World!" into an ASCII art banner. The resulting output is a visually striking representation of the message, which can be easily incorporated into terminal-based applications or scripts.

Figlet supports a wide range of font styles, allowing you to customize the appearance of your ASCII art to suit your needs. You can explore the available font options by running the figlet -f command, which will list all the installed fonts on your system.

$ figlet -f
standard
big
block
digital
slant
smslant
smshadow
smscript
script

By using different font styles, you can create a variety of visual effects and experiment with different aesthetics for your terminal-based projects.

In the next section, we'll dive deeper into customizing Figlet banners to suit your specific requirements.

Customizing Figlet Banners

While the default Figlet output is already visually striking, you can further customize the appearance of your ASCII art banners to match your specific needs. Figlet provides a range of options and configuration settings that allow you to fine-tune the text formatting, font styles, and overall presentation.

One of the key ways to customize Figlet banners is by selecting different font styles. As mentioned earlier, you can list all the available font options by running the figlet -f command. Once you've identified the font you want to use, you can apply it to your Figlet output by using the -f or --font flag followed by the font name.

$ figlet -f slant "Hello, World!"
 _   _      _ _        __        __         _     _
| | | | ___| | | ___   \ \      / /__  _ __| | __| |
| |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |
|  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |
|_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

In the example above, we use the slant font to create the ASCII art banner for the text "Hello, World!".

Another useful feature of Figlet is the ability to center the text within the banner. By default, Figlet aligns the text to the left, but you can change this behavior by using the -c or --center flag.

$ figlet -c "Centered Text"
                _   _      _ _        __        __         _     _
                | | | | ___| | | ___   \ \      / /__  _ __| | __| |
                | |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |
                |  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |
                |_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

In this example, the text "Centered Text" is now displayed in the center of the ASCII art banner.

Figlet also allows you to adjust the vertical spacing between lines of text. You can use the -k or --kerning flag to control the amount of spacing between the lines.

$ figlet -k 2 "Spaced Text"
                _   _      _ _        __        __         _     _

                | | | | ___| | | ___   \ \      / /__  _ __| | __| |

                | |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |

                |  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |

                |_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

In this example, we've increased the vertical spacing between the lines of text by setting the --kerning flag to 2.

By combining these customization options, you can create a wide variety of Figlet banners that suit your specific needs and aesthetic preferences.

Advanced Figlet Techniques

While the basic Figlet usage and customization options covered earlier are already quite powerful, Figlet also offers more advanced techniques that can further enhance your terminal-based ASCII art creations.

Scripting with Figlet

One of the advanced capabilities of Figlet is its ability to be integrated into scripts and automated workflows. By leveraging Figlet within shell scripts, you can dynamically generate ASCII art banners based on variables, user input, or other dynamic data.

For example, you can use Figlet in combination with the sed command to transform text on the fly:

$ echo "Hello, World!" | sed 's/./\U&/g' | figlet -f standard
 _   _      _ _        __        __         _     _
| | | | ___| | | ___   \ \      / /__  _ __| | __| |
| |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |
|  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |
|_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

In this example, we use the sed command to convert the input text to uppercase before passing it to Figlet. This allows us to dynamically transform the text and generate the corresponding ASCII art banner.

Handling Terminal Width

Another advanced Figlet technique is the ability to handle varying terminal widths. This is particularly useful when you want to ensure that your ASCII art banners fit within the available terminal space, regardless of the user's screen size or window dimensions.

Figlet provides the -w or --width flag to specify the maximum width for the output. By using this flag, you can ensure that your ASCII art banners are properly formatted and centered within the terminal window.

$ figlet -w 80 "Fitting Text in Terminal"
                                _   _      _ _        __        __         _     _
                                | | | | ___| | | ___   \ \      / /__  _ __| | __| |
                                | |_| |/ _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` |
                                |  _  |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |
                                |_| |_|\___|_|_|\___/     \_/\_/ \___/|_|  |_|\__,_|

In the example above, we use the -w 80 flag to ensure that the ASCII art banner for the text "Fitting Text in Terminal" fits within an 80-character wide terminal window.

By combining these advanced Figlet techniques with scripting and terminal width handling, you can create highly customized and dynamic ASCII art banners that adapt to different environments and use cases.

Summary

In this tutorial, you've learned how to use the Figlet tool to create ASCII art text banners in the terminal. You've explored the basics of Figlet, customized the appearance of your banners, and discovered advanced techniques to take your ASCII art to new heights. With the skills you've gained, you can now easily incorporate eye-catching visual elements into your terminal-based applications, scripts, and personal projects, adding a unique and creative touch to your command-line experience.

Other Linux Tutorials you may like