Added everything
This commit is contained in:
4
example/Makefile
Normal file
4
example/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
all:
|
||||
g++ main.cpp ../Progress.cpp ../StatusBarManager.cpp -o example
|
||||
|
||||
.PHONY: all
|
||||
69
example/main.cpp
Normal file
69
example/main.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../Progress.h"
|
||||
#include "../StatusBarManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
StatusBarManager* g_manager = nullptr;
|
||||
|
||||
// This ensures your terminal is left in normal state even after Ctrl+C
|
||||
void INT_handler(int sig)
|
||||
{
|
||||
if (nullptr != g_manager)
|
||||
{
|
||||
g_manager->stop();
|
||||
}
|
||||
signal(sig, SIG_DFL);
|
||||
raise(sig);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, INT_handler);
|
||||
Progress p("Normal", 10);
|
||||
Progress p2("Test", 10);
|
||||
StatusBarManager manager;
|
||||
g_manager = &manager;
|
||||
manager.add_progress_message(&p);
|
||||
manager.add_progress_message(&p2);
|
||||
if (isatty(STDOUT_FILENO))
|
||||
{
|
||||
manager.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "NOT A TTY" << endl;
|
||||
}
|
||||
|
||||
string test[2] = {"Message 1", "Message 2"};
|
||||
|
||||
srand(time(nullptr));
|
||||
|
||||
manager.draw_status_line();
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
int random = rand() % 2;
|
||||
if (random != 2)
|
||||
{
|
||||
cout << test[random] << endl;
|
||||
}
|
||||
p.increment_progress();
|
||||
p2.increment_progress();
|
||||
|
||||
manager.draw_status_line();
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
}
|
||||
|
||||
manager.stop();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user