| 1 |
#include "Terminal.h" |
|---|
| 2 |
namespace term { |
|---|
| 3 |
|
|---|
| 4 |
// this is SUCH a dodgy hack |
|---|
| 5 |
static bool forcecolour = false; |
|---|
| 6 |
|
|---|
| 7 |
void forceColour(bool state) { |
|---|
| 8 |
forcecolour = state; |
|---|
| 9 |
} |
|---|
| 10 |
|
|---|
| 11 |
string title(string const &str) { |
|---|
| 12 |
return string("]0;") + str + ""; |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
string background(Colour colour) { |
|---|
| 16 |
return string("[4") + str::stringify(colour) + "m"; |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
string foreground(Colour colour) { |
|---|
| 20 |
return string("[3") + str::stringify(colour) + "m"; |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
string colour(Colour colour) { |
|---|
| 24 |
return string("[3") + str::stringify(colour) + "m"; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
string attribute(Attribute attribute) { |
|---|
| 28 |
return string("[") + str::stringify(attribute) + "m"; |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
ostream &black(ostream &os) { |
|---|
| 32 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[30m"; |
|---|
| 33 |
return os; |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
ostream &red(ostream &os) { |
|---|
| 37 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[31m"; |
|---|
| 38 |
return os; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
ostream &green(ostream &os) { |
|---|
| 42 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[32m"; |
|---|
| 43 |
return os; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
ostream &yellow(ostream &os) { |
|---|
| 47 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[33m"; |
|---|
| 48 |
return os; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
ostream &blue(ostream &os) { |
|---|
| 52 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[34m"; |
|---|
| 53 |
return os; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
ostream &magenta(ostream &os) { |
|---|
| 57 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[35m"; |
|---|
| 58 |
return os; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
ostream &cyan(ostream &os) { |
|---|
| 62 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[36m"; |
|---|
| 63 |
return os; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
ostream &white(ostream &os) { |
|---|
| 67 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[37m"; |
|---|
| 68 |
return os; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
ostream &normal(ostream &os) { |
|---|
| 72 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[0m"; |
|---|
| 73 |
return os; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
ostream &bold(ostream &os) { |
|---|
| 77 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[1m"; |
|---|
| 78 |
return os; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
ostream &halfbright(ostream &os) { |
|---|
| 82 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[2m"; |
|---|
| 83 |
return os; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
ostream &underline(ostream &os) { |
|---|
| 87 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[4m"; |
|---|
| 88 |
return os; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
ostream &blink(ostream &os) { |
|---|
| 92 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[5m"; |
|---|
| 93 |
return os; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
ostream &reverse(ostream &os) { |
|---|
| 97 |
if (&cout == &os && (forcecolour || isatty(1))) os << "[7m"; |
|---|
| 98 |
return os; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
} |
|---|