mandiant / capa

The FLARE team's open-source tool to identify capabilities in executable files.
Apache License 2.0
3.99k stars 499 forks source link

Replace halo spinner with rich #2086

Closed s-ff closed 1 month ago

s-ff commented 1 month ago

This PR is a candidate replacement for Halo spinner as discussed in #1812. It uses Rich module.

If we end up adopting rich, we could maybe use some of its other features to reduce dependencies, for example replacing tqdm with rich.progress and tabulate with rich.table. It could also serve to implement a pager functionality for long output texts.

Checklist

williballenthin commented 1 month ago

does the rich Console expect to own stderr and that all writes to it go through the console instance? Or can a console be freely mixed with raw print calls (to stderr)?

williballenthin commented 1 month ago

we can test by having an active spinner (or rich progress bar) and also writing to the output stream directly, and then observing if the spinner is correctly cleaned up/rendered near the new lines.

s-ff commented 1 month ago

does the rich Console expect to own stderr and that all writes to it go through the console instance? Or can a console be freely mixed with raw print calls (to stderr)?

we can test by having an active spinner (or rich progress bar) and also writing to the output stream directly, and then observing if the spinner is correctly cleaned up/rendered near the new lines.

I did an expriment for this, and concluded that rich.console.Console can freely be mixed with raw print to stderr.

Test if rich.console can be mixed with raw prints to stderr ```python import sys import time from rich.console import Console console = Console(stderr=True) with console.status("Spinner...", spinner="dots"): time.sleep(1) print("This text is printed to stdout") time.sleep(1) print("This text is printed to stderr", file=sys.stderr) time.sleep(1) ``` Result: ![Kapture 2024-05-24 at 16 21 53](https://github.com/mandiant/capa/assets/31004043/15eb4b11-9566-49ad-9085-1b249f887623)

Does this answer your question @williballenthin?

williballenthin commented 1 month ago

wow that's great!

thanks @s-ff!