1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
namespace vt100 {
using std::ios_base;
struct vt100_base {
// constructors for plain sequences
vt100_base(std::string s) : sequence(s, ios_base::ate) {}
vt100_base(const char * s) : sequence(s, ios_base::ate) {}
// constructor for single param (n) e.g: \033[nA
vt100_base(std::string s, int n, std::string ch)
: sequence(s, ios_base::ate)
{
sequence << n << ch ;
}
// constructor for two params (x,y) e.g: \033[x;yH
vt100_base(std::string s, int x, int y, std::string ch)
: sequence(s, ios_base::ate)
{
sequence << x << ";" << y << ch ;
}
// copy constructor needed for ostringstream
vt100_base(const vt100_base& v) : sequence(v.sequence.str()) {}
std::ostringstream sequence;
};
std::ostream& operator<<(std::ostream & out, const vt100_base v) {
out << v.sequence.str();
return out;
}
struct down : public vt100_base {
down(int n=1) : vt100_base("\033[", n, "B") {}
};
struct up : public vt100_base {
up(int n=1) : vt100_base("\033[", n, "A") {}
};
struct right : public vt100_base {
right(int n=1) : vt100_base("\033[", n, "C") {}
};
struct left : public vt100_base {
left(int n=1) : vt100_base("\033[", n, "D") {}
};
struct moveto : public vt100_base {
moveto(int x, int y) : vt100_base("\033[", x, y, "H") {}
};
/ screen
static vt100_base reset("\033[0m"); // reset attributes
static vt100_base clear("\033[2J"); // clear screen
static vt100_base cls("\033c"); // clear screen cursor top left
// attributes
static vt100_base bright("\033[1m");
static vt100_base dim("\033[2m");
static vt100_base underscore("\033[4m");
static vt100_base blink("\033[5m");
static vt100_base reverse("\033[7m");
static vt100_base hidden("\033[8m");
// text colours
static vt100_base fg_black("\033[30m");
static vt100_base fg_red("\033[31m");
static vt100_base fg_green("\033[32m");
static vt100_base fg_yellow("\033[33m");
static vt100_base fg_blue("\033[34m");
static vt100_base fg_magenta("\033[35m");
static vt100_base fg_cyan("\033[36m");
static vt100_base fg_white("\033[37m");
// background colours
static vt100_base bg_black("\033[40m");
static vt100_base bg_red("\033[41m");
static vt100_base bg_green("\033[42m");
static vt100_base bg_yellow("\033[43m");
static vt100_base bg_blue("\033[44m");
static vt100_base bg_magenta("\033[45m");
static vt100_base bg_cyan("\033[46m");
static vt100_base bg_white("\033[47m");
// erasers
static vt100_base erase_eol("\033[K");
static vt100_base erase_sol("\033[1K");
static vt100_base erase_line("\033[2K");
static vt100_base erase_down("\033[J");
static vt100_base erase_up("\033[1J");
static vt100_base cursor_off("\033[?25l");
static vt100_base cursor_on ("\033[?25h");
static vt100_base cursor_home("\033[H");
} // namespace end
|