Added iomanipulators for all effects

This commit is contained in:
Bob Polis
2021-12-13 12:52:03 +01:00
parent 3e9c27de28
commit bacc189d99
4 changed files with 303 additions and 52 deletions

View File

@ -5,6 +5,7 @@
#include <iomanip>
#include <string>
#include <stdexcept>
#include "iomanip.hpp"
using namespace sc;
@ -52,155 +53,140 @@ void term::progress(int prefixlen,
*_out << bar[steps % 8 - 1];
fill_len--;
}
reset();
*_out << std::string(fill_len, ' ');
*_out << io::reset << std::string(fill_len, ' ');
*_out << ' ' << std::setw(3) << perc << '%';
}
void term::hide_cursor() const {
*_out << "\x1b[?25l";
*_out << io::hide_cursor;
}
void term::show_cursor() const {
*_out << "\x1b[?25h";
*_out << io::show_cursor;
}
void term::reset() const {
*_out << "\x1b[m";
*_out << io::reset;
}
void term::bold() const {
*_out << "\x1b[1m";
*_out << io::bold;
}
void term::italic() const {
*_out << "\x1b[3m";
*_out << io::italic;
}
void term::underline() const {
*_out << "\x1b[4m";
*_out << io::underline;
}
void term::overline() const {
*_out << "\x1b[53m";
*_out << io::overline;
}
void term::strikethru() const {
*_out << "\x1b[9m";
*_out << io::strikethru;
}
void term::blinkslow() const {
*_out << "\x1b[5m";
*_out << io::blinkslow;
}
void term::blinkfast() const {
*_out << "\x1b[6m";
*_out << io::blinkfast;
}
void term::reverse() const {
*_out << "\x1b[7m";
*_out << io::reverse;
}
void term::blackf() const {
*_out << "\x1b[30m";
*_out << io::blackf;
}
void term::redf() const {
*_out << "\x1b[31m";
*_out << io::redf;
}
void term::greenf() const {
*_out << "\x1b[32m";
*_out << io::greenf;
}
void term::yellowf() const {
*_out << "\x1b[33m";
*_out << io::yellowf;
}
void term::bluef() const {
*_out << "\x1b[34m";
*_out << io::bluef;
}
void term::magentaf() const {
*_out << "\x1b[35m";
*_out << io::magentaf;
}
void term::cyanf() const {
*_out << "\x1b[36m";
*_out << io::cyanf;
}
void term::whitef() const {
*_out << "\x1b[37m";
*_out << io::whitef;
}
void term::defaultf() const {
*_out << "\x1b[39m";
*_out << io::defaultf;
}
void term::grayf(int val) const {
gray(val, 38);
*_out << io::grayf(val);
}
void term::rgbf(int r, int g, int b) const {
rgb(r, g, b, 38);
*_out << io::rgbf(r, g, b);
}
void term::blackb() const {
*_out << "\x1b[40m";
*_out << io::blackb;
}
void term::redb() const {
*_out << "\x1b[41m";
*_out << io::redb;
}
void term::greenb() const {
*_out << "\x1b[42m";
*_out << io::greenb;
}
void term::yellowb() const {
*_out << "\x1b[43m";
*_out << io::yellowb;
}
void term::blueb() const {
*_out << "\x1b[44m";
*_out << io::blueb;
}
void term::magentab() const {
*_out << "\x1b[45m";
*_out << io::magentab;
}
void term::cyanb() const {
*_out << "\x1b[46m";
*_out << io::cyanb;
}
void term::whiteb() const {
*_out << "\x1b[47m";
*_out << io::whiteb;
}
void term::defaultb() const {
*_out << "\x1b[49m";
*_out << io::defaultb;
}
void term::grayb(int val) const {
gray(val, 48);
*_out << io::grayb(val);
}
void term::rgbb(int r, int g, int b) const {
rgb(r, g, b, 48);
}
void term::gray(int val, int code) const {
if (val < 0 || val > 24) {
throw std::invalid_argument("gray value out of range");
}
*_out << "\x1b[" << code << ";5;" << 232 + val << "m";
}
void term::rgb(int r, int g, int b, int code) const {
if (r < 0 || r > 5 || g < 0 || g > 5 || b < 0 || b > 5) {
throw std::invalid_argument("rgb color component out of range");
}
*_out << "\x1b[" << code << ";5;" << (16 + 36 * r + 6 * g + b) << "m";
*_out << io::rgbb(r, g, b);
}
// ------------------------------------------------------------------------