An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
Lending some color to Tokei Code Analyzer
Time for another open-source adventure! Well be joined by Max Jacobson as we visit the Rust cli-tool Tokei. Tokei generates statistics around your code and language usage. For example, chael.codes looks like:
Forem, the repo behind therelicans.com and dev.to, looks like this:
Were going to pick up an issue with a lot of discussion that hasnt been touched in 10 months that I personally like. Those screenshots before werent very engaging, right? Lets add some lovely color to Tokeis terminal output!
There are some requirements listed out in the issue above.
- It must look good in light and dark mode terminals
- A crate should manage colorizing the output
- A color flag should manage color output
--color (always|auto|never)
- thick rows === should be bold and the thin rows dimmed
I think itd look nice to give all the languages a cyan color, and emphasize the subtotals.
First step is identifying how well cover color output, and the issue points us to colored which is based on a Ruby gem of the same name. Usage is very straightforward. println!("Hello, {}!", "world".green().bold())
will use the terminals colors, and bold the text.
Note that cyan or green may not always be cyan or green, theyre just roles in your terminal color scheme.
Next, its time to think about how and where to output these colors. Tokei implements a printer interface in cli_utils.rs which is where I found the headers!
With some lovely colors and style implemented in Tokei, its time to think about those command line args and turning off color. Some people (like other computers) prefer not to have color. I think we handle this in cli.rs. ShouldColorize respects environment variables like NOCOLOR and CLICOLOR, but flags seem helpful too. We should document this regardless.
Add Color to Tokei #751
closes #419Use the colored crate to add some additional color to Tokei.Colored will respect settings like CLICOLOR_FORCE and NO_COLOR.It will also use the configured terminal theme's blue.
Original Link: https://dev.to/newrelic/lending-some-color-to-tokei-code-analyzer-pib
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To