Home > Backend Development > Python Tutorial > Introducing acolor: A small utility to print ANSI color codes

Introducing acolor: A small utility to print ANSI color codes

Susan Sarandon
Release: 2025-01-02 14:08:39
Original
776 people have browsed it

Introducing acolor: A small utility to print ANSI color codes

In my previous post, I wrote about a tool I wanted to create to print ANSI color codes to the console. I currently need a this as I am "prettifying" my shell prompt at the moment and figured it would just be faster to leverage this tool over Googling the necessary shell codes.

So I created acolor, an open-source Python utility built on top of colorist to provide a convient way to output ANSI color codes to the terminal. Currently, only named color codes are supported (e.g., red, green, blue). Hex, HSL, VGA, and RGB color codes are currently not supported but acolor can easily be extended to include them.

You can view the source code here. You can install it with pipx via:

pipx install git https://github.com/NicholasSynovic/acolor

Here are the current command line options of the applicaton:

acolor --help

Usage: acolor [OPTIONS]

Options:
  -c, --color TEXT  Color name to generate ANSI code
  -r, --reset       Print ANSI reset code
  --help            Show this message and exit.
Copy after login

Here's an example usage:

$ acolor --color red
'\x1b[31m'

$ acolor --reset
'\x1b[0m'

$ acolor --color test
test is not a valid color: dict_keys(['BLACK', 'RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'WHITE'])
Copy after login

The above is the detailed content of Introducing acolor: A small utility to print ANSI color codes. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template