Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ranav committed May 25, 2020
1 parent e5cc05a commit a2e11d4
Show file tree
Hide file tree
Showing 25 changed files with 774 additions and 922 deletions.
79 changes: 42 additions & 37 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <indicators/cursor_control.hpp>
#include <indicators/progress_bar.hpp>
#include <indicators/progress_spinner.hpp>
#include <indicators/cursor_control.hpp>
#include <vector>

int main() {
Expand All @@ -13,15 +13,15 @@ int main() {
//
// PROGRESS BAR 1
//
indicators::ProgressBar p{option::BarWidth{50},
option::Start{"["},
option::Fill{""},
option::Lead{""},
option::Remainder{" "},
option::End{" ]"},
option::ForegroundColor{indicators::Color::yellow},
option::FontStyles{
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
indicators::ProgressBar p{
option::BarWidth{50},
option::Start{"["},
option::Fill{""},
option::Lead{""},
option::Remainder{" "},
option::End{" ]"},
option::ForegroundColor{indicators::Color::yellow},
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};

std::atomic<size_t> index{0};
std::vector<std::string> status_text = {"Rocket.exe is not responding",
Expand Down Expand Up @@ -62,7 +62,8 @@ int main() {
p.set_option(option::End{""});
p.set_option(option::ForegroundColor{indicators::Color::white});
p.set_option(option::ShowPercentage{false});
p.set_option(option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}});
p.set_option(
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}});
auto job = [&p]() {
while (true) {
p.set_option(
Expand Down Expand Up @@ -93,7 +94,8 @@ int main() {
p.set_option(option::End{"]"});
p.set_option(option::PostfixText{"Getting started"});
p.set_option(option::ForegroundColor{indicators::Color::green});
p.set_option(option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}});
p.set_option(
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}});
auto job = [&p]() {
while (true) {
auto ticks = p.current();
Expand Down Expand Up @@ -130,7 +132,8 @@ int main() {
p4.set_option(option::ForegroundColor{indicators::Color::cyan});
p4.set_option(option::PostfixText{"Restoring system state"});
p4.set_option(option::ShowPercentage{false});
p4.set_option(option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}});
p4.set_option(
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}});
std::atomic<size_t> index4{0};
auto job4 = [&p4, &index4, &lead_spinner]() {
while (true) {
Expand Down Expand Up @@ -164,17 +167,17 @@ int main() {
//
// GOING BACKWARDS
//
indicators::ProgressBar p{option::BarWidth{50},
option::ProgressType{ProgressType::decremental},
option::Start{"["},
option::Fill{""},
option::Lead{""},
option::Remainder{"-"},
option::End{"]"},
option::ForegroundColor{indicators::Color::white},
option::PostfixText{"Reverting system restore"},
option::FontStyles{
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
indicators::ProgressBar p{
option::BarWidth{50},
option::ProgressType{ProgressType::decremental},
option::Start{"["},
option::Fill{""},
option::Lead{""},
option::Remainder{"-"},
option::End{"]"},
option::ForegroundColor{indicators::Color::white},
option::PostfixText{"Reverting system restore"},
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
auto job = [&p]() {
while (true) {
p.tick();
Expand Down Expand Up @@ -225,8 +228,10 @@ int main() {
// PROGRESS BAR 6
//
indicators::ProgressSpinner p{
option::PrefixText{" - "}, option::PostfixText{"Searching for the Moon"},
option::ForegroundColor{indicators::Color::white}, option::ShowPercentage{false},
option::PrefixText{" - "},
option::PostfixText{"Searching for the Moon"},
option::ForegroundColor{indicators::Color::white},
option::ShowPercentage{false},
option::SpinnerStates{std::vector<std::string>{"", "", "", ""}},
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
auto job = [&p]() {
Expand Down Expand Up @@ -264,17 +269,17 @@ int main() {
//
// NESTED PROGRESS BAR
//
indicators::ProgressBar p2{option::BarWidth{30},
option::PrefixText{" - "},
option::Start{"🌎"},
option::Fill{"·"},
option::Lead{"🚀"},
option::Remainder{" "},
option::End{"🌑"},
option::PostfixText{"Achieved low-Earth orbit"},
option::ForegroundColor{indicators::Color::white},
option::FontStyles{
std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
indicators::ProgressBar p2{
option::BarWidth{30},
option::PrefixText{" - "},
option::Start{"🌎"},
option::Fill{"·"},
option::Lead{"🚀"},
option::Remainder{" "},
option::End{"🌑"},
option::PostfixText{"Achieved low-Earth orbit"},
option::ForegroundColor{indicators::Color::white},
option::FontStyles{std::vector<indicators::FontStyle>{indicators::FontStyle::bold}}};
std::vector<std::string> ship_trail{"", "", "", "", "", "", "", ""};
std::atomic<int> ship_trail_index{0};
auto job2 = [&p2, &ship_trail_index, &ship_trail]() {
Expand Down
22 changes: 11 additions & 11 deletions include/indicators/block_progress_bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ class BlockProgressBar {
option::MaxPostfixTextLen{0}, std::forward<Args>(args)...),
details::get<details::ProgressBarOption::font_styles>(
option::FontStyles{std::vector<FontStyle>{}}, std::forward<Args>(args)...),
details::get<details::ProgressBarOption::max_progress>(option::MaxProgress{100},
std::forward<Args>(args)...),
details::get<details::ProgressBarOption::stream>(
option::Stream{std::cout}, std::forward<Args>(args)...)
) {}
details::get<details::ProgressBarOption::max_progress>(
option::MaxProgress{100}, std::forward<Args>(args)...),
details::get<details::ProgressBarOption::stream>(option::Stream{std::cout},
std::forward<Args>(args)...)) {}

template <typename T, details::ProgressBarOption id>
void set_option(details::Setting<T, id> &&setting) {
Expand Down Expand Up @@ -118,7 +117,8 @@ class BlockProgressBar {

size_t current() {
std::lock_guard<std::mutex> lock{mutex_};
return std::min(static_cast<size_t>(progress_), size_t(get_value<details::ProgressBarOption::max_progress>()));
return std::min(static_cast<size_t>(progress_),
size_t(get_value<details::ProgressBarOption::max_progress>()));
}

bool is_completed() const { return get_value<details::ProgressBarOption::completed>(); }
Expand Down Expand Up @@ -163,7 +163,7 @@ class BlockProgressBar {
void print_progress(bool from_multi_progress = false) {
std::lock_guard<std::mutex> lock{mutex_};

auto& os = get_value<details::ProgressBarOption::stream>();
auto &os = get_value<details::ProgressBarOption::stream>();

const auto max_progress = get_value<details::ProgressBarOption::max_progress>();
if (multi_progress_mode_ && !from_multi_progress) {
Expand All @@ -181,7 +181,7 @@ class BlockProgressBar {

for (auto &style : get_value<details::ProgressBarOption::font_styles>())
details::set_font_style(os, style);

os << get_value<details::ProgressBarOption::prefix_text>();
os << get_value<details::ProgressBarOption::start>();

Expand All @@ -191,7 +191,8 @@ class BlockProgressBar {

os << get_value<details::ProgressBarOption::end>();
if (get_value<details::ProgressBarOption::show_percentage>()) {
os << " " << std::min(static_cast<size_t>(progress_ / max_progress * 100.0), size_t(100)) << "%";
os << " " << std::min(static_cast<size_t>(progress_ / max_progress * 100.0), size_t(100))
<< "%";
}

auto &saved_start_time = get_value<details::ProgressBarOption::saved_start_time>();
Expand Down Expand Up @@ -228,8 +229,7 @@ class BlockProgressBar {
if (get_value<details::ProgressBarOption::max_postfix_text_len>() == 0)
get_value<details::ProgressBarOption::max_postfix_text_len>() = 10;
os << " " << get_value<details::ProgressBarOption::postfix_text>()
<< std::string(get_value<details::ProgressBarOption::max_postfix_text_len>(), ' ')
<< "\r";
<< std::string(get_value<details::ProgressBarOption::max_postfix_text_len>(), ' ') << "\r";
os.flush();
if (progress_ > max_progress) {
get_value<details::ProgressBarOption::completed>() = true;
Expand Down
4 changes: 2 additions & 2 deletions include/indicators/details/stream_helper.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <indicators/display_width.hpp>
#include <indicators/setting.hpp>
#include <indicators/termcolor.hpp>
#include <indicators/display_width.hpp>

#include <algorithm>
#include <chrono>
Expand Down Expand Up @@ -175,7 +175,7 @@ class ProgressScaleWriter {
class IndeterminateProgressScaleWriter {
public:
IndeterminateProgressScaleWriter(std::ostream &os, size_t bar_width, const std::string &fill,
const std::string &lead)
const std::string &lead)
: os(os), bar_width(bar_width), fill(fill), lead(lead) {}

std::ostream &write(size_t progress) {
Expand Down
Loading

0 comments on commit a2e11d4

Please sign in to comment.