Textualize / rich-cli

Rich-cli is a command line toolbox for fancy output in the terminal

Home Page:https://www.textualize.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: pv equivalent progress bar (using --size) feature

jkrauska opened this issue · comments

pv command is great for making progress bars on the command line, but it could be implemented in rich and be so much prettier.

please consider adding the equivalent of pv --size BYTES in rich-cli?

commented

This is a pretty major feature request. pv copies text or binary data unmodified; rich-cli is all about colorizing and reformatting text output to be more pretty, and it does not handle binary data at all. Looking at the current code for rich-cli, I think it would be easier to start over and write a separate program if you want to do what pv does.

I'm aware of another Python-based utility (tqdm) that does exactly what you're asking for. It does not use Rich, so it doesn't look quite as pretty, but it does look better than qv.

The "output" from PV is sent to stderr. That's where we'd want the pretty color progress bars. (existing feature)

All that rich would need to do with the STDIN is pass it directly to STDOUT and count bytes.

commented

I realise that I was perhaps not as clear as I could be. Please note that I have nothing to do with the Rich projects apart from being an interested user, so nothing I say is official. 😊

I understood what you asked for originally. I have used tqdm for exactly this purpose previously. I've read the source for rich-cli and understood the code structure. I also spent five or ten minutes reading the pv documentation, looked at the examples on the home page, installed it and tried it out for a few toy examples, since it seemed like a promising tool, but ultimately I decided that tqdm is good enough for me. I took all of this into account when I wrote my previous reply.

All that rich would need to do with the STDIN is pass it directly to STDOUT and count bytes.

No part of rich-cli currently passes data directly. The current code structure reads the entire input into memory as text, tries to parse, reformat and colorize it, before producing output. Since all input is read, decoded and parsed in text mode, there is no counting bytes either.

It is my understanding that a new function for copying and counting bytes directly to STDOUT, ideally without reading the entire input into memory, would be a corner case that has no overlap with any existing code. If you believe otherwise, I would be happy to give feedback on a PR.

Also, please note the large number of command line options that both pv and tqdm have, in order to implement the functionality of a good CLI tool. I do not believe this is a simple feature request.

Edited to add: I don't think your idea is bad, in fact I also think this would be a nice thing to have. Since it doesn't fit into the current code structure, maybe rather than creating a separate utility it might be possible to implement it inside rich-cli as a separate subcommand, e.g. rich cat file_a file_b > new_file or gzip -c file.tar | rich cat > file.tar.gz.