p-ranav / indicators

Activity Indicators for Modern C++
MIT License
3.04k stars 237 forks source link

Carriage return does not work #90

Open tgalaj opened 3 years ago

tgalaj commented 3 years ago

Hi,

Recently I was using the indicators library to print some progress bars inside my pet projects. Everything was working fine until I replaced the machines. On the new machine progress bars are not printed correctly:

bad

Progress bar is configured in the code as follows:

    indicators::show_console_cursor(false);
    indicators::ProgressBar bar
    {
        indicators::option::BarWidth{30},
        indicators::option::Start{"["},
        indicators::option::Fill{"="},
        indicators::option::Lead{">"},
        indicators::option::Remainder{" "},
        indicators::option::End{"]"},
        indicators::option::PostfixText{"Rendering..."},
        indicators::option::ForegroundColor{indicators::Color::green},
        indicators::option::ShowElapsedTime{true},
        indicators::option::ShowPercentage{true},
        indicators::option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}},
        indicators::option::MaxProgress{max_pixels}
    };

        (...)
        bar.set_progress(count);
        (...)
    indicators::show_console_cursor(true);

I thought that it has something to do with the carriage return. After that, I changed indicators::option::Start{"["} to indicators::option::Start{"\r["} and it worked like a charm:

good

However, I don't like such a workaround. Is it something bad with the indicators library or am I doing something wrong? (I'm using the newest version of the single header indicators lib).

p-ranav commented 3 years ago

I suppose I could add the carriage return to the progress bar start string always. That way, you don't need to.

I can do this and push an update.

p-ranav commented 3 years ago

Please this if this commit fixes it https://github.com/p-ranav/indicators/commit/4790bfddcad6ff3bd814584083e7490c096a3a2b

tgalaj commented 3 years ago

I'll reopen this issue as the problem still emerges. I found out that you also need to increase the size by 1 (size of "\r" string that you output to the os stream) of the _startlength variable to be working properly (best to handle it in the constructor imho).

lowern1ght commented 1 year ago

there is still this problem + I tried to use carriage return, but it did not give results option::Start{"\r["}, - not working

image

fix please <3