-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColour.cpp
More file actions
125 lines (106 loc) · 3.1 KB
/
Colour.cpp
File metadata and controls
125 lines (106 loc) · 3.1 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "Colour.h"
#include <string>
#include <list>
#include <sstream>
#include <iomanip>
/// <summary>
/// statice method which produces a colour grid.
/// Useful for selecting colour/background pairs which
/// are effective.
/// </summary>
/// <returns>A string containing the colour grid.</returns>
std::string gamzia::Colour::showColourGrid()
{
std::stringstream ss;
ss.clear();
// Build our grid
ss << sre << cwh << "Colour Grid:" << sref << std::endl;
ss << " ";
for (auto &x : bnames)
ss << std::setw(5) << x;
ss << std::endl;
int j=0;
for (auto& c : listcall)
{
if (!(c == coff))
{
ss << cwh << std::setw(5) << cnames[j];
j++;
}
for (auto& b : listball)
{
if (!(c == coff) && !(b == boff))
ss << c << b << " * " << coff;
}
ss << std::endl;
}
ss << std::endl;
return (ss.str());
}
/// <summary>
/// Static method which shows a list of macros (name and effect).
/// </summary>
/// <returns>A string containing the macro list.</returns>
std::string gamzia::Colour::showMacros()
{
std::stringstream ss;
ss.clear();
ss << sre << "Macro Formats" << sref << std::endl;
for (auto &m : listmall)
if (!(m == off))
ss << m << "Sultaneous Sends Salutations" << off << std::endl;
return (ss.str());
}
/// <summary>
/// A static method which shows a list of available styles.
/// </summary>
/// <returns>A string containing the styles list.</returns>
std::string gamzia::Colour::showStyles()
{
std::stringstream ss;
ss.clear();
ss << cwh << sre << "Style Formats" << sref << std::endl;
ss << "(Note: not all styles work on all terminals)" << std::endl;
ss << cwh << sbo << "This is BOLD" << sbof << std::endl;
ss << cwh << sdi << "This is DIM" << sdif << std::endl;
ss << cwh << sun << "This is UNDERLINE" << sunf << std::endl;
ss << cwh << sbl << "This is BLINK" << sblf << std::endl;
ss << cwh << sre << "This is REVERSE" << sref << std::endl;
ss << cwh << shi << "This is HIDDEN" << shif << std::endl;
return (ss.str());
}
/// <summary>
/// Strips out all colour (foreground, background, style) format codes
/// from a string.
/// </summary>
/// <param name="label">The string to scan for colour codes.</param>
/// <returns>A modified string without codes. Affects original string.</returns>
std::string gamzia::Colour::colourStrip(std::string label)
{
int x;
// Strip foreground colours
for (auto& c : listcall)
{
while ((x = (int)label.find(c, 0)) != std::string::npos)
{
label.erase(x, c.length());
}
}
// Strip background colours
for (auto& b : listball)
{
while ((x = (int)label.find(b, 0)) != std::string::npos)
{
label.erase(x, b.length());
}
}
// Strip styles
for (auto& st : listsall)
{
while ((x = (int)label.find(st, 0)) != std::string::npos)
{
label.erase(x, st.length());
}
}
return (label);
}