Connect++ 0.4.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
vic_strings.hpp
1/*
2
3Copyright © 2023-24 Sean Holden. All rights reserved.
4
5*/
6/*
7
8This file is part of Connect++.
9
10Connect++ is free software: you can redistribute it and/or modify it
11under the terms of the GNU General Public License as published by the
12Free Software Foundation, either version 3 of the License, or (at your
13option) any later version.
14
15Connect++ is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18more details.
19
20You should have received a copy of the GNU General Public License along
21with Connect++. If not, see <https://www.gnu.org/licenses/>.
22
23*/
24
25#ifndef VICSTRING_HPP
26#define VICSTRING_HPP
27
28#include<iostream>
29#include<vector>
30#include<string>
31
39//--------------------------------------------------------------
40namespace unicode_symbols {
44 struct LogSym {
45 static std::string neg;
46 static std::string unicode_space;
47 static std::string or_sym;
48 static std::string and_sym;
49 static std::string true_sym;
50 static std::string false_sym;
51 static std::string forall;
52 static std::string exists;
53 static std::string ifthen;
54 static std::string iff;
55 };
56}
57//--------------------------------------------------------------
58namespace ansi_escape_colours {
62 enum class ColourName {NOCOL,
63 RED,
64 GREEN,
65 BLUE,
66 LBLUE,
67 ORANGE,
68 YELLOW,
69 PURPLE,
70 GREY,
71 LGREY
72 };
82 struct Colour {
83 static uint8_t num_colours;
84 static std::string nocol;
85 static std::string red;
86 static std::string green;
87 static std::string blue;
88 static std::string lblue;
89 static std::string orange;
90 static std::string yellow;
91 static std::string purple;
92 static std::string grey;
93 static std::string lgrey;
94
95 static std::string name_to_string(const ColourName&);
96 };
97}
98//--------------------------------------------------------------
99using std::ostream;
100using std::string;
101
102namespace colour_string {
103 using namespace ansi_escape_colours;
119 private:
120 uint8_t num_colours;
121 bool use_colours;
122 std::vector<ColourName> map;
123 string s;
124 public:
125 ColourString(bool uc)
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 }
142
143 /*
144 * Straighforward gets and sets.
145 */
146 bool get_use_colours() const { return use_colours; }
147 void set_use_colours(bool b) { use_colours = b; }
148 void set_map(uint8_t i, ColourName colour) {
149 if (i >= 0 && i < Colour::num_colours)
150 map[i] = colour;
151 }
156 ColourString operator()(const string& _s) {
157 s = _s;
158 return *this;
159 }
165 string operator()(const string& _s, size_t num) {
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 }
171
172 /*
173 *Individual colour setters.
174 */
175 string red() {
176 if (use_colours)
177 return Colour::red + s + Colour::nocol;
178 else
179 return s;
180 }
181 string green() {
182 if (use_colours)
183 return Colour::green + s + Colour::nocol;
184 else
185 return s;
186 }
187 string blue() {
188 if (use_colours)
189 return Colour::blue + s + Colour::nocol;
190 else
191 return s;
192 }
193 string lblue() {
194 if (use_colours)
195 return Colour::lblue + s + Colour::nocol;
196 else
197 return s;
198 }
199 string orange() {
200 if (use_colours)
201 return Colour::orange + s + Colour::nocol;
202 else
203 return s;
204 }
205 string yellow() {
206 if (use_colours)
207 return Colour::yellow + s + Colour::nocol;
208 else
209 return s;
210 }
211 string purple() {
212 if (use_colours)
213 return Colour::purple + s + Colour::nocol;
214 else
215 return s;
216 }
217 string grey() {
218 if (use_colours)
219 return Colour::grey + s + Colour::nocol;
220 else
221 return s;
222 }
223 string lgrey() {
224 if (use_colours)
225 return Colour::lgrey + s + Colour::nocol;
226 else
227 return s;
228 }
229 };
230}
231
232//--------------------------------------------------------------
233namespace verbose_print {
238 class VPrint {
239 private:
240 static uint8_t verbosity;
241 public:
242 VPrint() = delete;
243 VPrint(uint8_t v) { verbosity = v; }
244 void operator()(uint8_t, const string&, bool = false, uint8_t = 1);
245 void operator()(uint8_t, char*, bool = false, uint8_t = 1);
246 void nl(uint8_t, uint8_t = 1);
247 };
248}
249
250//--------------------------------------------------------------
251namespace commas {
264 class comma {
265 private:
266 size_t target;
267 size_t i;
268 public:
272 comma() = delete;
276 comma(size_t _target)
277 : i(1), target(_target) {}
281 string operator()() {
282 if (i < target) {
283 i++;
284 return string(", ");
285 }
286 return string("");
287 }
288 };
289}
290
291#endif
Simple addition of colour to strings and ostreams.
string operator()(const string &_s, size_t num)
ColourString operator()(const string &_s)
Simple function object for putting commas in lists.
comma()=delete
Wouldn't make any sense.
comma(size_t _target)
Initialise with the length of the list you're printing.
string operator()()
The magic happens here!
void nl(uint8_t, uint8_t=1)
void operator()(uint8_t, const string &, bool=false, uint8_t=1)
vic_string - "verbose/indented/coloured"