Use color for terminal output

Colorful

Article from Issue 284/2024
Author(s):

You don't necessarily need color on the terminal, but still, it does look good – and does not involve too much effort.

If you look at the output of the common Linux commands, there is always one impressive feature: simplicity. Nothing flashes, wobbles, or makes a noise – plain-vanilla information without any distracting trappings. In today's world, where every device or open tab in the web browser begs for attention with a beep, this approach, which may seem anachronistic to newcomers, supports a focused work approach and lets you fully concentrate on solving the problem at hand. Simply fantastic.

Why Color?

If everything is so perfect, why bother with color? Color helps to highlight things and draw your attention to a particular point or fact. Let's take a look at how we can spice up the output on the command line with some color. Note that how the output is actually displayed depends on the terminal, its size, the fonts used, and other settings. After all, you still want output to remain legible.

Without color, neither the developer nor the program have to worry about the properties of the terminal currently in use. Nobody needs to know how the user's terminal is set up and what output the program uses (e.g., whether it is a simple display on the terminal, a redirect to a file, or further processing via a pipe). Remember: Color increases complexity.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News