Loading...
Searching...
No Matches
TextStyle.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef DRAIN_TEXT_STYLE
32#define DRAIN_TEXT_STYLE
33
34#include <iostream>
35#include <map>
36#include <set>
37
38#include "Type.h"
39//#include "Sprinter.h"
40//#include "StringBuilder.h"
41
42namespace drain
43{
44
46
50class TextStyle {
51
52public:
53
54 enum Colour {DEFAULT_COLOR=0, BLACK, GRAY, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, WHITE};
55
56 enum Style {NO_STYLE=0, ITALIC=1, BOLD=2, DIM=4, REVERSE=8}; // NO_STYLE not needed?
57
58 enum Line {NO_LINE=0, UNDERLINE=1, DOUBLE_UNDERLINE=2, OVERLINE=4};
59
60
61 // Could be: EnumFlagger<SingleFlagger> ? -> see TextDecorator
62 Colour colour;
63
64 // Could be: EnumFlagger<MultiFlagger> -> see TextDecorator
65 std::set<Style> style;
66
67 // Could be: EnumFlagger<SingleFlagger> ? -> see TextDecorator
68 Line line;
69
70 template <typename ... T>
71 inline
72 void set(const T &... args) {
73 reset();
74 //this->value = 0;
75 add(args...);
76 }
77
78 template <typename T, typename ... TT>
79 inline
80 void add(const T & arg, const TT &... args) {
81 _add(arg);
82 add(args...);
83 }
84
85protected:
86
87 inline
88 void reset(){
89 colour = Colour::DEFAULT_COLOR;
90 line = Line::NO_LINE;
91 style.clear();
92 };
93
94
95 inline
96 void set(){};
97
98 inline
99 void add(){};
100
101 inline
102 void _add(const Colour & c){
103 colour = c;
104 };
105
106 inline
107 void _add(const Line & l){
108 line = l;
109 };
110
111 inline
112 void _add(const Style & s){
113 style.insert(s);
114 };
115
116};
117
119
120DRAIN_TYPENAME(TextStyle::Colour);
121DRAIN_TYPENAME(TextStyle::Line);
122DRAIN_TYPENAME(TextStyle::Style);
123
124inline
125std::ostream & operator<<(std::ostream & ostr, const TextStyle &t){
126 ostr << __FILE__ << ':' << __LINE__ << '?';
127 return ostr;
128}
129
130
131} // ::drain
132
133#endif
Utility for scanning text segments.
Definition TextStyle.h:50
Definition DataSelector.cpp:1277
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.