Skip to content

DynamicProgress with ProgressSpinner #140

@Jomy10

Description

@Jomy10

DynamicProgress doesn't seem to work with ProgressSpinner. Take the following example:

#include <indicators/progress_bar.hpp>
#include <indicators/dynamic_progress.hpp>
#include <indicators/progress_spinner.hpp>
#include <indicators/termcolor.hpp>
#include <thread>
#include <chrono>
#include <iostream>

int main() {
    using namespace indicators;
    auto spinner1 = std::make_unique<ProgressSpinner>(
        option::PostfixText{"Building module X"},
        option::ForegroundColor{Color::white},
        option::SpinnerStates{std::vector<std::string>{"", "", "", "", "", "", "", ""}},
        option::FontStyles{std::vector<FontStyle>{FontStyle::bold}},
        option::ShowSpinner(false)
    );

    auto spinner2 = std::make_unique<ProgressSpinner>(
        option::PostfixText{"Building module X"},
        option::ForegroundColor{Color::white},
        option::SpinnerStates{std::vector<std::string>{"", "", "", "", "", "", "", ""}},
        option::FontStyles{std::vector<FontStyle>{FontStyle::bold}},
        option::ShowSpinner(false)
    );

    auto spinner3 = std::make_unique<ProgressSpinner>(
        option::PostfixText{"Building module X"},
        option::ForegroundColor{Color::white},
        option::SpinnerStates{std::vector<std::string>{"", "", "", "", "", "", "", ""}},
        option::FontStyles{std::vector<FontStyle>{FontStyle::bold}},
        option::ShowSpinner(false)
    );

    //auto spinners = std::vector<std::unique_ptr<ProgressSpinner>>{spinner1, spinner2, spinner3};

    DynamicProgress<ProgressSpinner> spinners(spinner1, spinner2, spinner3);
    spinners.set_option(option::HideBarWhenComplete{false});

    auto job1 = [&spinners](size_t i) {
        while (true) {
            spinners[i].tick();
            if (spinners[i].is_completed()) {
                spinners[i].set_option(option::ForegroundColor{Color::green});
                spinners[i].set_option(option::PrefixText{""});
                spinners[i].set_option(option::ShowSpinner{false});         
                spinners[i].set_option(option::PostfixText{"Building module X DONE"});
                spinners[i].mark_as_completed();
                break;
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
        }
    };

    std::vector<std::thread> jobs = std::vector<std::thread>{};
    for (int i = 0; i < 3; i++) {
        jobs.push_back(std::thread(job1, i));
    }

    for (std::thread& job : jobs) {
        job.join();
    }
    
  
    return 0;
}

This produces the following errors:

/private/tmp/indicators (master*) » clang++ test.cpp -Iinclude -std=c++17                                                                              1 ↵ jonaseveraert@MacBook-Pro-van-Jonas
In file included from test.cpp:2:
include/indicators/dynamic_progress.hpp:26:12: error: no member named 'multi_progress_mode_' in 'indicators::ProgressSpinner'
   26 |       bar->multi_progress_mode_ = true;
      |       ~~~~~^
test.cpp:37:38: note: in instantiation of function template specialization 'indicators::DynamicProgress<indicators::ProgressSpinner>::DynamicProgress<std::unique_ptr<indicators::ProgressSpinn
   37 |     DynamicProgress<ProgressSpinner> spinners(spinner1, spinner2, spinner3);
      |                                      ^
In file included from test.cpp:2:
include/indicators/dynamic_progress.hpp:98:31: error: too many arguments to function call, expected 0, have 1
   98 |           bar->print_progress(true);
      |           ~~~~~~~~~~~~~~~~~~~ ^~~~
include/indicators/dynamic_progress.hpp:33:5: note: in instantiation of member function 'indicators::DynamicProgress<indicators::ProgressSpinner>::print_progress' requested here
   33 |     print_progress();
      |     ^
test.cpp:42:21: note: in instantiation of member function 'indicators::DynamicProgress<indicators::ProgressSpinner>::operator[]' requested here
   42 |             spinners[i].tick();
      |                     ^
include/indicators/progress_spinner.hpp:165:8: note: 'print_progress' declared here
  165 |   void print_progress() {
      |        ^
In file included from test.cpp:2:
include/indicators/dynamic_progress.hpp:110:29: error: too many arguments to function call, expected 0, have 1
  110 |         bar->print_progress(true);
      |         ~~~~~~~~~~~~~~~~~~~ ^~~~
include/indicators/progress_spinner.hpp:165:8: note: 'print_progress' declared here
  165 |   void print_progress() {
      |        ^
3 errors generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions