Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements #3

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1232413
update
karasikov Mar 29, 2019
f1b6d82
show actual progress
karasikov Mar 29, 2019
f6bce3c
Need to include cassert to compile on some systems
hmusta Mar 29, 2019
e015bcd
added operator
karasikov Apr 26, 2019
eedf886
show progress bar right after initialization
karasikov Apr 26, 2019
0b44569
fixed progress bar for zero total progress
karasikov May 3, 2019
77eca46
prevent from copying
karasikov May 14, 2019
f5c2a4e
silent mode
karasikov May 14, 2019
9ca8c46
thread safe progress bar
karasikov May 14, 2019
9315d0d
fixed blinking of the bar
karasikov May 14, 2019
e07b6f0
updated readme
karasikov May 15, 2019
d2becaa
correct update of the progress bar after resizing the window
karasikov May 15, 2019
54f1152
removed redundant newline
karasikov May 18, 2019
b69e624
properly update progress bar for operator+=(uint64_t)
karasikov Jun 6, 2019
2679318
set max value for bar width
karasikov Aug 26, 2019
5ab3bbd
special logging mode for output other than to console
karasikov Aug 26, 2019
f23e6fc
fixed frequency update
karasikov Aug 26, 2019
0373926
print time in status logs
karasikov May 11, 2020
4f07db0
use constant width in terminal
karasikov May 11, 2020
7b2259a
relaxed memory order
karasikov Jun 12, 2020
f3b1b02
flush new line right after the total process is achieved
karasikov Oct 29, 2020
1598014
fix progress increments
karasikov Nov 3, 2020
c19fc52
Cast (const char *) to (char *) for snprintf arg.
badshah400 Dec 26, 2020
2abb8c2
Fix atomic initialisation.
badshah400 Dec 26, 2020
677bf88
main: Replace Progressed() by increment operators.
badshah400 Dec 26, 2020
f8dfa61
Pass char instead of (char *) to SetStyle().
badshah400 Dec 26, 2020
007b6b2
Update main code to current API and some -fpermissive fixes
karasikov Dec 26, 2020
a4f217f
cleanup, fixes of examples in main.cpp
karasikov Dec 26, 2020
7208674
minor changes
karasikov Dec 26, 2020
609adda
fixed prints of 0/0 progress
karasikov Apr 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 78 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,49 @@ To create a progress bar, the total number of jobs need to be known.
int n = 10;
ProgressBar progress_bar(n);
```
Optionally, small descriptions can also be added to the progress bar

Optionally, small descriptions can also be added to the progress bar.

```C++
int n = 10;
ProgressBar progress_bar(n,"Example 1");
ProgressBar progress_bar(n, "Example 1");
```





Updating a progress bar
-------------------------
Updates to the progress bar are made using the `Progressed(int)` method by passing the index of the job

Updates to the progress bar are made using the increment operators.


**Example 1:**

```C++
int n = 10;
ProgressBar progress_bar(n,"Example 1");
ProgressBar progress_bar(n, "Example 1");

int job_index = 0;

do_some_work();

job_index++;
progress_bar.Progressed(job_index);
progress_bar += 1;

do_some_more_work();

job_index++;
progress_bar.Progressed(job_index);
progress_bar += 1;
```

**Example 2:**

```C++
int n = 100;
ProgressBar *bar = new ProgressBar(n, "Example 1");
for(int i=0;i<=n;++i){
bar1->Progressed(i);
std::this_thread::sleep_for (std::chrono::milliseconds(10));
ProgressBar bar1(n, "Example 1");

for (int i = 0; i <= n; ++i) {
++bar1;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
```

Expand All @@ -83,11 +82,11 @@ If progressing through a large job list, iterating through every update will slo
**Example 3:**
```C++
int n = 100000;
ProgressBar *bar2 = new ProgressBar(n, "Example 3");
bar2->SetFrequencyUpdate(10);
for(int i=0;i<=n;++i){
bar2->Progressed(i);
ProgressBar bar2(n, "Example 3");
bar2.SetFrequencyUpdate(10);

for (int i = 0; i <= n; ++i){
++bar2;
}
```

Expand All @@ -99,79 +98,74 @@ The progress bar can be customised using the `SetStyle(const char*, const char*)
**Example 4**
```C++
n = 1000;
ProgressBar *bar3 = new ProgressBar(n, "Example 4");
bar3->SetFrequencyUpdate(10);
bar3->SetStyle("\u2588", "-");
for(int i=0;i<=n;++i){
bar3->Progressed(i);
ProgressBar bar3(n, "Example 4");
bar3.SetFrequencyUpdate(10);
bar3.SetStyle("\u2588", "-");

for (int i = 0; i <= n; ++i) {
++bar3;
}
```


Main Example
=========


```C++
#include "progress_bar.hpp"
#include <iostream>
#include <thread>
#include <chrono>

int main(){

int n;

/// Example 1 ///

n = 100;
ProgressBar *bar1 = new ProgressBar(n, "Example 1");

for(int i=0;i<=n;++i){
bar1->Progressed(i);
std::this_thread::sleep_for (std::chrono::milliseconds(10));
}
#include "progress_bar.hpp"

/// Example 2 ///

n = 1000;
ProgressBar *bar2 = new ProgressBar(n, "Example 2");
bar2->SetFrequencyUpdate(10);
bar2->SetStyle("|","-");
//bar2->SetStyle("\u2588", "-"); for linux

std::cout << std::endl;
for(int i=0;i<=n;++i){
bar2->Progressed(i);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

n = 5;
ProgressBar bar3(n);
bar3.Progressed(0);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(1);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(2);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(3);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(4);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(5);
// following tests exception error
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(6);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(7);

return 0;
}
```
int main() {

int n;

/// Example 1 ///

n = 100;
ProgressBar bar1(n, "Example 1");

for (int i = 0; i <= n; ++i) {
++bar1;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

/// Example 2 ///

n = 1000;
ProgressBar bar2(n, "Example 2");
bar2.SetFrequencyUpdate(10);
bar2.SetStyle("|", "-");
//bar2.SetStyle("\u2588", "-"); for linux

std::cout << std::endl;
for (int i = 0; i <= n; ++i) {
++bar2;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

n = 5;
ProgressBar bar3(n);
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
// following tests exception error
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;

return 0;
}
```
77 changes: 36 additions & 41 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,47 @@
#include <thread>
#include <chrono>

int main(){

int n;

int main() {
/// Example 1 ///
{
int n = 100;
ProgressBar bar1(n, "Example 1");

n = 100;
ProgressBar *bar1 = new ProgressBar(n, "Example 1");

for(int i=0;i<=n;++i){
bar1->Progressed(i);
std::this_thread::sleep_for (std::chrono::milliseconds(10));
}
for (int i = 1; i <= n; ++i) {
bar1 += 1;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}

/// Example 2 ///
{
int n = 1000;
ProgressBar bar2(n, "Example 2");
bar2.SetFrequencyUpdate(10);
bar2.SetStyle('|','-');
//bar2.SetStyle("\u2588", "-"); for linux
for (int i = 1; i <= n; ++i) {
bar2 += 1;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}

n = 1000;
ProgressBar *bar2 = new ProgressBar(n, "Example 2");
bar2->SetFrequencyUpdate(10);
bar2->SetStyle("|","-");
//bar2->SetStyle("\u2588", "-"); for linux

std::cout << std::endl;
for(int i=0;i<=n;++i){
bar2->Progressed(i);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

n = 5;
ProgressBar bar3(n);
bar3.Progressed(0);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(1);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(2);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(3);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(4);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(5);
// following tests exception error
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(6);
std::this_thread::sleep_for (std::chrono::milliseconds(200));
bar3.Progressed(7);
ProgressBar bar3(5);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
// following tests exception error
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
++bar3;

return 0;
}
Loading