alive-progress icon indicating copy to clipboard operation
alive-progress copied to clipboard

Are new line characters "\n" allowed in the Dual Line feature?

Open jakemayfield opened this issue 1 year ago • 4 comments

Hi @rsalmei , thank you for this awesome library!

Referring to https://github.com/rsalmei/alive-progress/issues/135, are new line characters \n allowed in bar.text? Mine do not seem to be taking and keeps everything showing only on a single line. I've also tried using \r\n, with no success.

My use case is that I output performance stats, with each metric being on its own line, that update in real-time as I'm going through the loop. Since I'm looking at 10+ lines, I do not want to print these lines over and over again as they continuously update throughout the loop. It would be much better to have them display below the progress bars.

Thanks!

jakemayfield avatar Sep 07 '22 13:09 jakemayfield

Hello @jakemayfield, thanks man!

To guarantee the dual line (or even the default single line) mode works, I have to filter new line characters. So, at the end of a refresh, I know how to return the cursor to the bar, either on the same or on the line above...

Perhaps it would be possible to support something like this, but it seems a very niche feature, because bar.text would have to either always have the exact same number of lines, or I would have to count them every time one changes it, so I can make the cursor return to the initial line. The first is cumbersome and prone to errors, and the second is very tricky to implement because of the race condition that will surely occur with recently changed texts, that haven't been printed on the screen yet. This means I would have to count the lines directly on the hot refresh loop, which would adversely affect performance. Multithreading is complicated.

Can't you use the best of both worlds? You could put on the dual line some real-time data that the user doesn't need a history for, and print the ones that the user could benefit from having the history on screen.

rsalmei avatar Sep 07 '22 15:09 rsalmei