1 #pragma once
2 
3 #include <cstdint>
4 
5 namespace host_tool
6 {
7 
8 class ProgressInterface
9 {
10   public:
11     virtual ~ProgressInterface() = default;
12 
13     /** Update the progress by X bytes.  This will inform any listening
14      * interfaces (just write to stdout mostly), and tick off as time passed.
15      */
16     virtual void updateProgress(std::int64_t bytes) = 0;
17     virtual void start(std::int64_t bytes) = 0;
18     virtual void finish() = 0;
19     virtual void abort() = 0;
20 };
21 
22 /**
23  * @brief A progress indicator that writes to stdout.  It deliberately
24  * overwrites the same line when it's used, so it's advised to not interject
25  * other non-error messages.
26  */
27 class ProgressStdoutIndicator : public ProgressInterface
28 {
29   public:
30     ProgressStdoutIndicator() = default;
31 
32     void updateProgress(std::int64_t bytes) override;
33     void start(std::int64_t bytes) override;
34     void finish() override;
35     void abort() override;
36 
37   private:
38     std::int64_t totalBytes = 0;
39     std::int64_t currentBytes = 0;
40 };
41 
42 } // namespace host_tool
43