Skip to content

refactor: simplify color formatting#44

Merged
water-sucks merged 4 commits intomainfrom
simplify-color-formatting
Aug 29, 2024
Merged

refactor: simplify color formatting#44
water-sucks merged 4 commits intomainfrom
simplify-color-formatting

Conversation

@water-sucks
Copy link
Copy Markdown
Collaborator

This doesn't bring any new features, but rather simplifies color handling.

In order to respect the user's preference for printing colors (i.e. for printing to a file), this adds a configuration setting and
a global flag that forces color even when printing to a file, much like less does.

Additionally, this does a huge refactor of how colors are handled. Before, this used to just check the conditional directly and change the format string to have ANSI codes or not have ANSI codes. This is awkward as hell, since you have to do this everywhere and duplicate formatting logic in so many places that this becomes quite unwieldy. This creates an ANSIFilter writer that wraps over another writer, and either prints or doesn't print any ANSI codes that it encounters. That way, we only have to check in one place whether or not we should render these colors, provided that the developer is using the provided log and utils.print utilities.

@water-sucks water-sucks merged commit 0f1ba04 into main Aug 29, 2024
@water-sucks water-sucks deleted the simplify-color-formatting branch August 29, 2024 23:25
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.

1 participant