Skip to content

Add colorization method to cwms-cli#118

Open
krowvin wants to merge 3 commits intomainfrom
10-add-colors-library-to-cli
Open

Add colorization method to cwms-cli#118
krowvin wants to merge 3 commits intomainfrom
10-add-colors-library-to-cli

Conversation

@krowvin
Copy link
Collaborator

@krowvin krowvin commented Feb 12, 2026

With this PR you will be able to easily colorize the CLI

Resolves #10

Docs?

@Enovotny
Should decide if we want both developer and enduser docs.

If developer docs do I put those in CONTRIBUTING with the below howto?

If enduser, would you like to see a page in addition to what would present automatically from the site builder made by the args?

i.e. something explaining the colors and when/why you might disable them (file based logs)

PR Details

I started with blob which will dynamically figure out if an object is JSON and format it (screenshot below)

I did have to hook into the logger to try and catch the logs at a low level.

This also made it so you do not have to pass the no-color optione everywhere.

This introduces log-file and log-level arguments.

Where you would call it like this:

cwms-cli --log-level=DEBUG blob list

Right after cwms-cli. Keeping the blob/list arg list from looking like a book.

I have it coloring the log level by default in 4 different colors.

But to explicitly color a log item with JSON you can do this:

import logging
from cwmscli.utils.logging.formatters import format_df_for_log


logging.info(
            format_df_for_log(
                df, c=c, col_colors={0: "BLUE", 1: "GREEN"}, json_color=True
            )
        )

You can also arbitrarily color various parts of text with
c("some text", "BLUE")

or

logging.info(c("hello", "GREEN") + " " + c("world", "BLUE"))
which would give
image

image

Libraries

I went with Colorama, seemed very popular!

@krowvin krowvin requested a review from Enovotny February 12, 2026 22:53
@krowvin krowvin linked an issue Feb 12, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Colors Library to CLI

1 participant