tracing-indicatif: automatically show CLI progress bars for active tracing spans
Wanted to share tracing-indicatif, a small crate I've recently published!
I'm a huge fan of having progress bars in CLIs as I find it makes them significantly more interactive. I haven't been a big fan of adding PB logic to my CLIs though. It's fairly invasive (adding PB logic to a library pretty much means your library can only be used in CLI contexts) and they're fairly difficult to manage.
I realized the other day that progress bars are effectively just tracking the lifetime of some "span", so I could just tie my PBs to the existing tracing spans in my library; and I wrote a tracing layer to do just that. I'm pretty happy with how clean and easy this solution turned out to be.
Key benefits/features:
- With a simple 3 line change to your existing tracing subscriber init code, you can enable progress bars for your CLI.
- Handles all PB management for you, including preventing PBs from clobbering your stderr output and limiting the number of visible PBs.
- Able to show parent-child span relationships in the PBs.
- Ease to "toggle" PBs: if you aren't in a CLI context, just don't add the layer.
- Requires zero PB management code in your libraries. Means you can have PBs show up for spans in your dependencies, and you don't need to add any invasive PB management code to your libraries.
- Easy to customize, it preserves indicatif's ProgressStyle API so you can customize the PB appearance to your heart's content.
I recommend looking at the example code in the repo for demos. Hope you find this useful in your CLIs. :)