Skip to content

CliColors dataclass

A model for the colors used by the Botstrap-provided CLI.

The fields of this class are Callable[[str], str] functions that can add color to particular types of text shown in the console, such as success and error messages. Simple color presets are provided by the default() and off() class methods.

To personalize these colors, you can create a new instance of this class and specify any values you'd like to change. All constructor arguments correspond to field names, and all of them are keyword-only except for primary.

Tip - Set your bot's primary color!

The primary field is not assigned a color by default. This is deliberate, as it will be used to color your bot's name and is essentially a personal brand. 🌈

To customize this field, simply instantiate this class with your desired color - such as CliColors(Color.blue) - and pass it in as the colors parameter to the Botstrap constructor. See the example below for more details.

Info - Field names and descriptions

The following table lists the names of all the fields in this class, demonstrates the colors that they use by default, and describes the types of text to which they are applied.

Field Description
primary Your bot's name. See the tip for more info.
error Message shown when the script terminates due to an error.
highlight Important text that isn't a success/warning/error message.
lowlight Less important text that may safely be de-emphasized.
success Text shown when processes or tasks complete successfully.
warning Text shown when something goes wrong, but is recoverable.
Example - Customizing specific colors

Let's say you want to use cyan as your bot's primary color... but cyan is the default highlight color, so that might be confusing. Fortunately, it's easy to change the highlight color too! This example demonstrates how to change the primary color to cyan and the highlight color to pink.

bot.py
from botstrap import Botstrap, CliColors, Color

bot_colors = CliColors(Color.cyan, highlight=Color.pink)
Botstrap(name="cyan-bot", colors=bot_colors).run_bot()
Console Session
$ python bot.py

cyan-bot: You currently don't have a saved default bot token.
Would you like to add one now? If so, type "yes" or "y":

default() -> CliColors classmethod

Returns an instance of this class with default values for all colors.

Functions from Color are used as the defaults for all fields except for primary, which defaults to str() and is essentially a no-op unless overridden.

Note - All default color values
botstrap/colors.py
primary: Callable[[str], str] = str
_: KW_ONLY = None  # type: ignore[assignment]  # (1)!
error: Callable[[str], str] = Color.red
highlight: Callable[[str], str] = Color.cyan
lowlight: Callable[[str], str] = Color.grey
success: Callable[[str], str] = Color.green
warning: Callable[[str], str] = Color.yellow
  1. This "field" is just a sentinel value for dataclasses.
    • Any fields after a pseudo-field with the type of KW_ONLY are marked as keyword-only fields.
    • These fields signify __init__() parameters that must be specified as keywords when the class is instantiated.

off() -> CliColors classmethod

Returns an instance of this class with all colors disabled.

In other words, the values of all fields will effectively be no-ops - functions that simply call str() on their inputs without adding any formatting characters. This means that any text printed to the console will be displayed in its original (un-styled) color.