Added long list of attributes

This commit is contained in:
Bob Polis 2021-12-12 13:14:57 +01:00
parent a93b5d7b0e
commit 97a5cd5873
2 changed files with 181 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include <iostream>
#include <iomanip>
#include <string>
#include <stdexcept>
using namespace sc;
@ -53,6 +54,146 @@ void term::show_cursor() const {
*_out << "\x1b[?25h";
}
void term::reset() const {
*_out << "\x1b[m";
}
void term::bold() const {
*_out << "\x1b[1m";
}
void term::italic() const {
*_out << "\x1b[3m";
}
void term::underline() const {
*_out << "\x1b[4m";
}
void term::overline() const {
*_out << "\x1b[53m";
}
void term::strikethru() const {
*_out << "\x1b[9m";
}
void term::blinkslow() const {
*_out << "\x1b[5m";
}
void term::blinkfast() const {
*_out << "\x1b[6m";
}
void term::reverse() const {
*_out << "\x1b[7m";
}
void term::blackf() const {
*_out << "\x1b[30m";
}
void term::redf() const {
*_out << "\x1b[31m";
}
void term::greenf() const {
*_out << "\x1b[32m";
}
void term::yellowf() const {
*_out << "\x1b[33m";
}
void term::bluef() const {
*_out << "\x1b[34m";
}
void term::magentaf() const {
*_out << "\x1b[35m";
}
void term::cyanf() const {
*_out << "\x1b[36m";
}
void term::whitef() const {
*_out << "\x1b[37m";
}
void term::defaultf() const {
*_out << "\x1b[39m";
}
void term::grayf(int val) const {
gray(val, 38);
}
void term::rgbf(int r, int g, int b) const {
rgb(r, g, b, 38);
}
void term::blackb() const {
*_out << "\x1b[40m";
}
void term::redb() const {
*_out << "\x1b[41m";
}
void term::greenb() const {
*_out << "\x1b[42m";
}
void term::yellowb() const {
*_out << "\x1b[43m";
}
void term::blueb() const {
*_out << "\x1b[44m";
}
void term::magentab() const {
*_out << "\x1b[45m";
}
void term::cyanb() const {
*_out << "\x1b[46m";
}
void term::whiteb() const {
*_out << "\x1b[47m";
}
void term::defaultb() const {
*_out << "\x1b[49m";
}
void term::grayb(int val) const {
gray(val, 48);
}
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 + 7 * g + b) << "m";
}
// ------------------------------------------------------------------------
cursor_hider::cursor_hider(int fd) : _t {fd} {
_t.hide_cursor();
}

View File

@ -12,6 +12,9 @@ namespace sc {
struct winsize _ws;
std::ostream* _out {nullptr};
void gray(int val, int code) const;
void rgb(int r, int g, int b, int code) const;
public:
term(int fd);
@ -22,6 +25,43 @@ namespace sc {
void hide_cursor() const;
void show_cursor() const;
void reset() const;
void bold() const;
void italic() const;
void underline() const;
void overline() const;
void strikethru() const;
void blinkslow() const;
void blinkfast() const;
void reverse() const;
void blackf() const;
void redf() const;
void greenf() const;
void yellowf() const;
void bluef() const;
void magentaf() const;
void cyanf() const;
void whitef() const;
void defaultf() const;
void grayf(int val) const; // val = 0..23
void rgbf(int r, int g, int b) const; // r,g,b = 0..5
void blackb() const;
void redb() const;
void greenb() const;
void yellowb() const;
void blueb() const;
void magentab() const;
void cyanb() const;
void whiteb() const;
void defaultb() const;
void grayb(int val) const; // val = 0..23
void rgbb(int r, int g, int b) const; // r,g,b = 0..5
};
class cursor_hider {