diff --git a/progress.cpp b/progress.cpp index ef6cf47..1887088 100644 --- a/progress.cpp +++ b/progress.cpp @@ -1,18 +1,93 @@ #include -#include #include +#include +#include -int main() { - sc::term term {STDERR_FILENO}; - std::cout << term.rows() << " rows, " << term.cols() << " cols\n"; - sleep(1); +void show_rows_cols(const sc::term& t) { + std::cout << t.rows() << " rows, " << t.cols() << " cols\n"; +} + +void show_progress(const sc::term& t) { struct timespec tm; tm.tv_nsec = 20000000; tm.tv_sec = 0; sc::cursor_hider ch {STDERR_FILENO}; for (int i = 0; i < 1000; ++i) { - term.progress(i, 1000); + t.progress(i, 1000); nanosleep(&tm, nullptr); } std::cerr << std::endl; } + +void show_hue_bar(const sc::term& t, int top) { + int r = top; + int g = 0; + int b = 0; + // red -> yellow + while (g <= top) { + t.rgbb(r, g++, b); + std::cerr << ' '; + } + g = top; + // yellow -> green + while (r >= 0) { + t.rgbb(r--, g, b); + std::cerr << ' '; + } + r = 0; + // green -> cyan + while (b < 6) { + t.rgbb(r, g, b++); + std::cerr << ' '; + } + b = top; + // cyan -> blue + while (g >= 0) { + t.rgbb(r, g--, b); + std::cerr << ' '; + } + g = 0; + // blue -> magenta + while (r <= top) { + t.rgbb(r++, g, b); + std::cerr << ' '; + } + r = top; + // magenta -> red + while (b >= 0) { + t.rgbb(r, g, b--); + std::cerr << ' '; + } + t.reset(); + std::cerr << std::endl; +} + +void show_hue_bars(const sc::term& t) { + for (int top = 1; top < 6; ++top) { + show_hue_bar(t, top); + } +} + +void show_grayscale_bar(const sc::term& t) { + for (int i = 0; i < 23; ++i) { + t.grayb(i); + std::cerr << ' '; + } + t.reset(); + std::cerr << std::endl; +} + +int main() { + sc::term term {STDERR_FILENO}; + try { + show_rows_cols(term); + show_grayscale_bar(term); + show_hue_bars(term); + show_progress(term); + } catch (const std::exception& ex) { + term.reset(); + std::cerr << ex.what() << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +}