Connect++ 0.4.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 187 of file vic_strings.hpp.

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

◆ get_use_colours()

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

Definition at line 146 of file vic_strings.hpp.

146{ return use_colours; }

◆ green()

string colour_string::ColourString::green ( )
inline

Definition at line 181 of file vic_strings.hpp.

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

◆ grey()

string colour_string::ColourString::grey ( )
inline

Definition at line 217 of file vic_strings.hpp.

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

◆ lblue()

string colour_string::ColourString::lblue ( )
inline

Definition at line 193 of file vic_strings.hpp.

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

◆ lgrey()

string colour_string::ColourString::lgrey ( )
inline

Definition at line 223 of file vic_strings.hpp.

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

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

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

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

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

◆ orange()

string colour_string::ColourString::orange ( )
inline

Definition at line 199 of file vic_strings.hpp.

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

◆ purple()

string colour_string::ColourString::purple ( )
inline

Definition at line 211 of file vic_strings.hpp.

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

◆ red()

string colour_string::ColourString::red ( )
inline

Definition at line 175 of file vic_strings.hpp.

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

◆ set_map()

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

Definition at line 148 of file vic_strings.hpp.

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

◆ set_use_colours()

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

Definition at line 147 of file vic_strings.hpp.

147{ use_colours = b; }

◆ yellow()

string colour_string::ColourString::yellow ( )
inline

Definition at line 205 of file vic_strings.hpp.

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

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: