161 lines
5.0 KiB
C++
161 lines
5.0 KiB
C++
#include <iostream>
|
|
#include <ctime>
|
|
#include <cstdlib>
|
|
#include <libscterm.hpp>
|
|
#include <libscscreensaver.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 {&std::cerr};
|
|
for (int i = 0; i < 1000; ++i) {
|
|
t.progress(12, "progress bar", i, 1000);
|
|
nanosleep(&tm, nullptr);
|
|
}
|
|
std::cerr << sc::io::clear_line(t);
|
|
std::cerr << "progress bar done.";
|
|
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 < top) {
|
|
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::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::reset << std::endl;
|
|
std::cout << sc::io::bold;
|
|
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 << sc::io::bold;
|
|
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 << "slow-blink" << sc::io::reset << ' ';
|
|
std::cout << sc::io::blinkfast << "fast-blink" << sc::io::reset;
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
void show_truecolor(const sc::term& t) {
|
|
// check for true color support
|
|
char* support = getenv("COLORTERM");
|
|
if (!support || support[0] == '\0') {
|
|
std::cerr << "no true color support\n";
|
|
return;
|
|
}
|
|
const char* lhb = u8"\u2584"; // lower half block
|
|
const double sat = 1.0;
|
|
for (double bri = 0; bri < 1; bri += 0.2) {
|
|
for (double hue = 0; hue < 360; hue += 360.0 / t.cols()) {
|
|
HSB hsbb = {hue, sat, bri};
|
|
Color bg {hsbb};
|
|
RGB rgbb = RGB(bg);
|
|
HSB hsbf = {hue, sat, bri + 0.1};
|
|
Color fg {hsbf};
|
|
RGB rgbf = RGB(fg);
|
|
std::cerr << sc::io::truecolorb(rgbb.r * 255, rgbb.g * 255, rgbb.b * 255);
|
|
std::cerr << sc::io::truecolorf(rgbf.r * 255, rgbf.g * 255, rgbf.b * 255);
|
|
std::cerr << lhb;
|
|
}
|
|
std::cerr << std::endl;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
try {
|
|
sc::term term {STDERR_FILENO};
|
|
show_rows_cols(term);
|
|
show_grayscale_bar();
|
|
show_hue_bars();
|
|
show_words();
|
|
show_truecolor(term);
|
|
show_progress(term);
|
|
} catch (const std::exception& ex) {
|
|
std::cerr << sc::io::reset << ex.what() << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|