Connect++ 0.5.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
colour_string::ColourString Class Reference

Simple addition of colour to strings and ostreams. More...

#include <vic_strings.hpp>

Collaboration diagram for colour_string::ColourString:

Public Member Functions

 ColourString (bool uc)
 
bool get_use_colours () const
 
void set_use_colours (bool b)
 
void set_map (uint8_t i, ColourName colour)
 
ColourString operator() (const string &_s)
 
string operator() (const string &_s, size_t num)
 
string red ()
 
string green ()
 
string blue ()
 
string lblue ()
 
string orange ()
 
string yellow ()
 
string purple ()
 
string grey ()
 
string lgrey ()
 

Private Attributes

uint8_t num_colours
 
bool use_colours
 
std::vector< ColourName > map
 
string s
 

Detailed Description

Simple addition of colour to strings and ostreams.

The format is:

cout << col("Hello").red() ...;

Also incorporates a map allowing the format:

col.set_map(2, ColourName::PURPLE); cout << col("Hello", 2) << ...

so that assignment of colours can easily be changed

Definition at line 118 of file vic_strings.hpp.

Constructor & Destructor Documentation

◆ ColourString()

colour_string::ColourString::ColourString ( bool uc)
inline

Definition at line 125 of file vic_strings.hpp.

126 : num_colours(Colour::num_colours)
127 , use_colours(uc)
128 , map()
129 , s()
130 {
131 map = { ColourName::NOCOL,
132 ColourName::RED,
133 ColourName::GREEN,
134 ColourName::BLUE,
135 ColourName::LBLUE,
136 ColourName::ORANGE,
137 ColourName::YELLOW,
138 ColourName::PURPLE,
139 ColourName::GREY,
140 ColourName::LGREY };
141 }

Member Function Documentation

◆ blue()

string colour_string::ColourString::blue ( )
inline

Definition at line 186 of file vic_strings.hpp.

186 {
187 if (use_colours)
188 return Colour::blue + s + Colour::nocol;
189 else
190 return s;
191 }

◆ get_use_colours()

bool colour_string::ColourString::get_use_colours ( ) const
inline

Definition at line 145 of file vic_strings.hpp.

145{ return use_colours; }

◆ green()

string colour_string::ColourString::green ( )
inline

Definition at line 180 of file vic_strings.hpp.

180 {
181 if (use_colours)
182 return Colour::green + s + Colour::nocol;
183 else
184 return s;
185 }

◆ grey()

string colour_string::ColourString::grey ( )
inline

Definition at line 216 of file vic_strings.hpp.

216 {
217 if (use_colours)
218 return Colour::grey + s + Colour::nocol;
219 else
220 return s;
221 }

◆ lblue()

string colour_string::ColourString::lblue ( )
inline

Definition at line 192 of file vic_strings.hpp.

192 {
193 if (use_colours)
194 return Colour::lblue + s + Colour::nocol;
195 else
196 return s;
197 }

◆ lgrey()

string colour_string::ColourString::lgrey ( )
inline

Definition at line 222 of file vic_strings.hpp.

222 {
223 if (use_colours)
224 return Colour::lgrey + s + Colour::nocol;
225 else
226 return s;
227 }

◆ operator()() [1/2]

ColourString colour_string::ColourString::operator() ( const string & _s)
inline

This sets the member string. The idea is to allow other methods to add the colour to it.

Definition at line 155 of file vic_strings.hpp.

155 {
156 s = _s;
157 return *this;
158 }

◆ operator()() [2/2]

string colour_string::ColourString::operator() ( const string & _s,
size_t num )
inline

Make a coloured string using the map.

Does not affect the stored string.

Definition at line 164 of file vic_strings.hpp.

164 {
165 if (use_colours && num >=0 && num < map.size())
166 return Colour::name_to_string(map[num]) + _s + Colour::nocol;
167 else
168 return _s;
169 }

◆ orange()

string colour_string::ColourString::orange ( )
inline

Definition at line 198 of file vic_strings.hpp.

198 {
199 if (use_colours)
200 return Colour::orange + s + Colour::nocol;
201 else
202 return s;
203 }

◆ purple()

string colour_string::ColourString::purple ( )
inline

Definition at line 210 of file vic_strings.hpp.

210 {
211 if (use_colours)
212 return Colour::purple + s + Colour::nocol;
213 else
214 return s;
215 }

◆ red()

string colour_string::ColourString::red ( )
inline

Definition at line 174 of file vic_strings.hpp.

174 {
175 if (use_colours)
176 return Colour::red + s + Colour::nocol;
177 else
178 return s;
179 }

◆ set_map()

void colour_string::ColourString::set_map ( uint8_t i,
ColourName colour )
inline

Definition at line 147 of file vic_strings.hpp.

147 {
148 if (i >= 0 && i < Colour::num_colours)
149 map[i] = colour;
150 }

◆ set_use_colours()

void colour_string::ColourString::set_use_colours ( bool b)
inline

Definition at line 146 of file vic_strings.hpp.

146{ use_colours = b; }

◆ yellow()

string colour_string::ColourString::yellow ( )
inline

Definition at line 204 of file vic_strings.hpp.

204 {
205 if (use_colours)
206 return Colour::yellow + s + Colour::nocol;
207 else
208 return s;
209 }

Member Data Documentation

◆ map

std::vector<ColourName> colour_string::ColourString::map
private

Definition at line 122 of file vic_strings.hpp.

◆ num_colours

uint8_t colour_string::ColourString::num_colours
private

Definition at line 120 of file vic_strings.hpp.

◆ s

string colour_string::ColourString::s
private

Definition at line 123 of file vic_strings.hpp.

◆ use_colours

bool colour_string::ColourString::use_colours
private

Definition at line 121 of file vic_strings.hpp.


The documentation for this class was generated from the following file: