Skip to content

Accessibility

This page goes over information relevant to both developers and users relating to accessibility considerations.

Accessibility is very important to consider when developing applications. Colorblindness impacts roughly 4% of the general population, meaning that if your application gets even a small user base, there is a high probability that it is being used by someone with colorblindness.

Fortunately, there are ways as both developers and users to address these accessibility concerns, as detailed on this page.

If you are a user of a rich-click CLI, there are a few options you have to improve accessibility for yourself.

You can set a rich-click theme using the RICH_CLICK_THEME= environment variable. This will affect all CLI tools that use rich-click, even thought their authors may have coded up something differently!

The theme you choose is able to change not only the colors, but also change the structure of the help text, which can assist with screen readers.

In order to set this environment variable automatically every time you use the terminal, you can add it to your ~/.bashrc (if using bash) or ~/.zshrc (if using zsh):

Terminal window
echo "export RICH_CLICK_THEME=nord-modern" >> ~/.bashrc

Rich uses the NO_COLOR standard (more information here), giving rich-click built-in capability to allow the user to suppress color.

So, to run any rich-click CLI program without colour, you can do:

Terminal window
export NO_COLOR=1 # Set environment variable in shell
python cli.py # Run CLI tool
# ... Or run as a single line:
NO_COLOR=1 python cli.py

In order to set this environment variable automatically every time you use the terminal, you can add it to your ~/.bashrc (if using bash) or ~/.zshrc (if using zsh):

Terminal window
echo "export NO_COLOR=1" >> ~/.bashrc

3. Configure your terminal’s ANSI color escape sequences

Section titled “3. Configure your terminal’s ANSI color escape sequences”

The 4-bit ANSI color system is a set of 16 different colors implemented in every terminal. This is the most common way to set colors. These colors are not deterministic; different terminals use slightly different hex values for the ANSI colors. Wikipedia has a full breakdown of all the variations in these colors

Nearly all modern terminals have the ability to customize these colors in the terminals’ settings. If you are having difficulty distinguishing colors, it is recommended that you adjust these settings.

If you would like to make your CLI more accessible for others, there are a few rules of thumb you can follow:

There are some Click features that rich-click doesn’t override such as print statements and interactive prompts (see Comparison of Click and rich-click).

In these cases, we recommend using native Rich functionality so that your end users can benefit from NO_COLOR, which Click does not support.

So, for example:

  • Confirm.ask("[red]Are you sure?[/]") is more accessible because it works with NO_COLOR.
  • click.confirm(click.echo("Are you sure?", fg="red")) is less accessible because it cannot be overridden by NO_COLOR.

The 4-bit ANSI color system is a set of 16 different colors implemented in effectively every terminal, and they are the most common way to set colors. These colors are not deterministic; different terminals use slightly different hex values for the ANSI colors. Wikipedia has a full breakdown of all the variations in these colors

There are 16 total ANSI colors: 8 base ANSI colors, with each one having a “bright” variant:

  • black, bright_black
  • red, bright_red
  • green, bright_green
  • yellow, bright_yellow
  • blue, bright_blue
  • magenta, bright_magenta
  • cyan, bright_cyan
  • white, bright_white

Additionally, each one of these can be modified with dim, which in modern terminals just applies a change to the opacity of the color, giving developers a total of 32 different colors that can be shown.

Below is a script that renders all of these colors:

Code
# /// script
# dependencies = ["rich"]
# ///
from rich.console import Console
from rich.box import SIMPLE
from rich.table import Table
console = Console(color_system="truecolor")
table = Table(title="ANSI Colors", box=SIMPLE)
colors = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
table.add_column("Color", style="bold")
for variant in ["Normal", "Dim", "Bright", "Dim +\nBright"]:
table.add_column(variant, style="bold")
for color in colors:
table.add_row(
color,
*[
f"[{style}{color}]▓▓▓▓▓▓[/{style}{color}]"
for style in ["", "dim ", "bright_", "dim bright_"]
]
)
console.print(table)
Terminal window
$ python colors.py
Output
                  ANSI Colors                  

                                       Dim +  
  Color     Normal   Dim      Bright   Bright 
 ─────────────────────────────────────────────
  black     ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  red       ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  green     ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  yellow    ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  blue      ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  magenta   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  cyan      ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 
  white     ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓   ▓▓▓▓▓▓ 

(The colors you see when running this locally will differ from the colors here.)

The fact that the colors are not deterministic is a benefit for accessibility; it means, for example, a user can customize their terminal so that the ANSI “red” is more suitable for them. Nearly every modern terminal allows for this sort of customization.

This means that developers looking to create a more accessible experience should prefer ANSI colors.

So, for example:

  • RichHelpConfiguration(style_option="red") is more accessible because users can configure the hex value of this red.
  • RichHelpConfiguration(style_option="#FF0000") is less accessible because it is not configurable by the end user.