clitic / kdam

A console progress bar library for Rust. (inspired by tqdm & rich.progress)
https://docs.rs/kdam
Apache License 2.0
196 stars 6 forks source link

Feature request: adapt to changing terminal width #5

Closed oersted closed 2 years ago

oersted commented 2 years ago

kdam / tqdm is commonly used for long-running processes, which are often run in a tmux session in a server, which can be opened via from multiple machines with often different terminal window widths.

Just to give proper motivation for the request, I suspect it affects a majority of use-cases of kdam. Currently opening it in a smaller terminal substantially mangles the output.

The original python tqdm does adapt to changing terminal width on every refresh.

clitic commented 2 years ago

If you want progress bar to adapt terminal width on every refresh then you should use tqdm!(dynamic_ncols = true, ..). If the terminal size can't be determined then it uses progress bar of width 10. This also can be overwritten by using KDAM_NCOLS environment variable.

oersted commented 2 years ago

Nice thanks, I didn't expect it to be an option since it's automatic in the python library.

Is there a reason why it's not the default? Is it because the performance overhead might be an issue in cases where there are many short iterations?

clitic commented 2 years ago

Is there a reason why it's not the default? Is it because the performance overhead might be an issue in cases where there are many short iterations?

@oersted It is not default because the function used to get terminal width uses system calls which unnecessarily creates a overhead each time when bar is refreshed. By making it optional it makes less system calls which reduces overheads. tqdm also disables it by default see here.