Indicator with set_progress does not display properly (cursor issue?)
prudhomm opened this issue · comments
using namespace indicators;
// Hide cursor
show_console_cursor(false);
ProgressBar bar{
option::BarWidth{50},
option::Start{"["},
option::Fill{"■"},
option::Lead{"■"},
option::Remainder{"-"},
option::End{" ]"},
option::PostfixText{"Starting simulator"},
option::ForegroundColor{Color::cyan},
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}
};
here is the code for the first 10%
if ( !VLOG_IS_ON( 1 ) && Environment::isMasterRank() )
{
bar.set_option( option::PostfixText{ "Configuring "s} );
bar.set_progress( 10 );
}
the same for the rest
This is typically caused by the size of the terminal window being smaller than the total width of the bar (including postfix text). If you set bar width smaller and/or make your window larger, it should display correctly when you rerun the program.
I will check thanks
Wouldn't it be possible to get automatically the terminal size and adjust automatically?
Also this is not intuitive because my terminal is quite larger than the indicator part
Wouldn't it be possible to get automatically the terminal size and adjust automatically?
Depends. Calculating the full width of the progress bar = (Prefix text) + (Width of bar) + (Width of time remaining displayed) (Width of postfix text displayed). Some of these are known at compile time and others are calculated as we go (e.g., parameterized postfix text) and one of these displayed elements could bring the total bar width over the available terminal size.
In your case, however, I don't understand why the carriage return is correctly working after the first Configuring
. The terminal cursor should shoot back to the first cell in that row in the terminal so that the bar can be printed again.
This suggests to me that (if the terminal has enough width), that \r
isn't correctly working for some reason.
What terminal are you using?
I use the macosx terminal (Catalina), as well as vscode embedded terminal (vscode on a mac)