Connect++ 0.6.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 121 of file vic_strings.hpp.

Constructor & Destructor Documentation

◆ ColourString()

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

Definition at line 128 of file vic_strings.hpp.

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

Member Function Documentation

◆ blue()

string colour_string::ColourString::blue ( )
inline

Definition at line 189 of file vic_strings.hpp.

189 {
190 if (use_colours)
191 return Colour::blue + s + Colour::nocol;
192 else
193 return s;
194 }

◆ get_use_colours()

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

Definition at line 148 of file vic_strings.hpp.

148{ return use_colours; }

◆ green()

string colour_string::ColourString::green ( )
inline

Definition at line 183 of file vic_strings.hpp.

183 {
184 if (use_colours)
185 return Colour::green + s + Colour::nocol;
186 else
187 return s;
188 }

◆ grey()

string colour_string::ColourString::grey ( )
inline

Definition at line 219 of file vic_strings.hpp.

219 {
220 if (use_colours)
221 return Colour::grey + s + Colour::nocol;
222 else
223 return s;
224 }

◆ lblue()

string colour_string::ColourString::lblue ( )
inline

Definition at line 195 of file vic_strings.hpp.

195 {
196 if (use_colours)
197 return Colour::lblue + s + Colour::nocol;
198 else
199 return s;
200 }

◆ lgrey()

string colour_string::ColourString::lgrey ( )
inline

Definition at line 225 of file vic_strings.hpp.

225 {
226 if (use_colours)
227 return Colour::lgrey + s + Colour::nocol;
228 else
229 return s;
230 }

◆ 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 158 of file vic_strings.hpp.

158 {
159 s = _s;
160 return *this;
161 }

◆ 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 167 of file vic_strings.hpp.

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

◆ orange()

string colour_string::ColourString::orange ( )
inline

Definition at line 201 of file vic_strings.hpp.

201 {
202 if (use_colours)
203 return Colour::orange + s + Colour::nocol;
204 else
205 return s;
206 }

◆ purple()

string colour_string::ColourString::purple ( )
inline

Definition at line 213 of file vic_strings.hpp.

213 {
214 if (use_colours)
215 return Colour::purple + s + Colour::nocol;
216 else
217 return s;
218 }

◆ red()

string colour_string::ColourString::red ( )
inline

Definition at line 177 of file vic_strings.hpp.

177 {
178 if (use_colours)
179 return Colour::red + s + Colour::nocol;
180 else
181 return s;
182 }

◆ set_map()

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

Definition at line 150 of file vic_strings.hpp.

150 {
151 if (i >= 0 && i < Colour::num_colours)
152 map[i] = colour;
153 }

◆ set_use_colours()

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

Definition at line 149 of file vic_strings.hpp.

149{ use_colours = b; }

◆ yellow()

string colour_string::ColourString::yellow ( )
inline

Definition at line 207 of file vic_strings.hpp.

207 {
208 if (use_colours)
209 return Colour::yellow + s + Colour::nocol;
210 else
211 return s;
212 }

Member Data Documentation

◆ map

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

Definition at line 125 of file vic_strings.hpp.

◆ num_colours

uint8_t colour_string::ColourString::num_colours
private

Definition at line 123 of file vic_strings.hpp.

◆ s

string colour_string::ColourString::s
private

Definition at line 126 of file vic_strings.hpp.

◆ use_colours

bool colour_string::ColourString::use_colours
private

Definition at line 124 of file vic_strings.hpp.


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