131 lines
4.0 KiB
C++
131 lines
4.0 KiB
C++
#include <iostream>
|
|
#include <ctime>
|
|
#include <cmath>
|
|
#include <libscterm.hpp>
|
|
|
|
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 = 10000000;
|
|
tm.tv_sec = 0;
|
|
sc::cursor_hider ch {STDERR_FILENO};
|
|
for (int i = 0; i < 1000; ++i) {
|
|
t.progress(12, "progress bar", i, 1000);
|
|
nanosleep(&tm, nullptr);
|
|
}
|
|
std::cerr << std::endl;
|
|
}
|
|
|
|
void show_hue_bar(int top) {
|
|
int r = top;
|
|
int g = 0;
|
|
int b = 0;
|
|
// red -> yellow
|
|
while (g <= top) {
|
|
std::cerr << sc::io::rgbb(r, g++, b) << ' ';
|
|
}
|
|
g = top;
|
|
// yellow -> green
|
|
while (r >= 0) {
|
|
std::cerr << sc::io::rgbb(r--, g, b) << ' ';
|
|
}
|
|
r = 0;
|
|
// green -> cyan
|
|
while (b < 6) {
|
|
std::cerr << sc::io::rgbb(r, g, b++) << ' ';
|
|
}
|
|
b = top;
|
|
// cyan -> blue
|
|
while (g >= 0) {
|
|
std::cerr << sc::io::rgbb(r, g--, b) << ' ';
|
|
}
|
|
g = 0;
|
|
// blue -> magenta
|
|
while (r <= top) {
|
|
std::cerr << sc::io::rgbb(r++, g, b) << ' ';
|
|
}
|
|
r = top;
|
|
// magenta -> red
|
|
while (b >= 0) {
|
|
std::cerr << sc::io::rgbb(r, g, b--) << ' ';
|
|
}
|
|
std::cerr << sc::io::reset << std::endl;
|
|
}
|
|
|
|
void show_hue_bars() {
|
|
for (int top = 1; top < 6; ++top) {
|
|
show_hue_bar(top);
|
|
}
|
|
}
|
|
|
|
void show_grayscale_bar() {
|
|
for (int i = 0; i < 23; ++i) {
|
|
std::cerr << sc::io::grayb(i) << ' ';
|
|
}
|
|
std::cerr << sc::io::reset << std::endl;
|
|
}
|
|
|
|
void show_words() {
|
|
std::cout << sc::io::redf << " red ";
|
|
std::cout << sc::io::greenf << " green ";
|
|
std::cout << sc::io::bluef << " blue ";
|
|
std::cout << sc::io::cyanf << " cyan ";
|
|
std::cout << sc::io::magentaf << " magenta ";
|
|
std::cout << sc::io::yellowf << " yellow ";
|
|
std::cout << sc::io::rgbf(5, 2, 0) << " orange ";
|
|
std::cout << sc::io::bold << std::endl;
|
|
std::cout << sc::io::redf << " red ";
|
|
std::cout << sc::io::greenf << " green ";
|
|
std::cout << sc::io::bluef << " blue ";
|
|
std::cout << sc::io::cyanf << " cyan ";
|
|
std::cout << sc::io::magentaf << " magenta ";
|
|
std::cout << sc::io::yellowf << " yellow ";
|
|
std::cout << sc::io::rgbf(5, 2, 0) << " orange ";
|
|
std::cout << sc::io::reset << std::endl;
|
|
std::cout << sc::io::blackf;
|
|
std::cout << sc::io::redb << " red ";
|
|
std::cout << sc::io::greenb << " green ";
|
|
std::cout << sc::io::blueb << " blue ";
|
|
std::cout << sc::io::cyanb << " cyan ";
|
|
std::cout << sc::io::magentab << " magenta ";
|
|
std::cout << sc::io::yellowb << " yellow ";
|
|
std::cout << sc::io::rgbb(5, 2, 0) << " orange ";
|
|
std::cout << sc::io::bold << std::endl;
|
|
std::cout << sc::io::redb << " red ";
|
|
std::cout << sc::io::greenb << " green ";
|
|
std::cout << sc::io::blueb << " blue ";
|
|
std::cout << sc::io::cyanb << " cyan ";
|
|
std::cout << sc::io::magentab << " magenta ";
|
|
std::cout << sc::io::yellowb << " yellow ";
|
|
std::cout << sc::io::rgbb(5, 2, 0) << " orange ";
|
|
std::cout << sc::io::reset << std::endl;
|
|
std::cout << sc::io::bold << "bold " << sc::io::reset;
|
|
std::cout << sc::io::italic << "italic " << sc::io::reset;
|
|
std::cout << sc::io::underline << "underline" << sc::io::reset << ' ';
|
|
std::cout << sc::io::strikethru << "strike thru" << sc::io::reset << ' ';
|
|
std::cout << sc::io::overline << "overline" << sc::io::reset << ' ';
|
|
std::cout << sc::io::reverse << "reverse" << sc::io::reset << ' ';
|
|
// std::cout << sc::io::blinkslow << "blink slowly " << sc::io::reset;
|
|
// std::cout << sc::io::blinkfast << "blink fast " << sc::io::reset;
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
int main() {
|
|
sc::term term {STDERR_FILENO};
|
|
try {
|
|
show_rows_cols(term);
|
|
show_grayscale_bar();
|
|
show_hue_bars();
|
|
show_words();
|
|
show_progress(term);
|
|
} catch (const std::exception& ex) {
|
|
term.reset();
|
|
std::cerr << ex.what() << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|