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 <drain/TypeName.h>
35#include <iostream>
36#include <set>
37
38//#include "Sprinter.h"
39//#include "StringBuilder.h"
40
41namespace drain
42{
43
45
49class TextStyle {
50
51public:
52
53 enum Colour {DEFAULT_COLOR=0, BLACK, GRAY, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, WHITE};
54
55 enum Style {NO_STYLE=0, ITALIC=1, BOLD=2, DIM=4, REVERSE=8}; // NO_STYLE not needed?
56
57 enum Line {NO_LINE=0, UNDERLINE=1, DOUBLE_UNDERLINE=2, OVERLINE=4};
58
59 enum Control {RESET=0};
60
61
62 // Could be: EnumFlagger<SingleFlagger> ? -> see TextDecorator
63 Colour colour;
64
65 // Could be: EnumFlagger<MultiFlagger> -> see TextDecorator
66 std::set<Style> style;
67
68 // Could be: EnumFlagger<SingleFlagger> ? -> see TextDecorator
69 Line line;
70
71 template <typename ... T>
72 inline
73 void set(Control ctrl, const T &... args) {
74 if (ctrl == Control::RESET){
75 reset();
76 add(args...);
77 }
78 else {
79 // Or warn about unhandled control character?
80 add(ctrl, args...);
81 }
82 }
83
84 template <typename ... T>
85 inline
86 void set(const T &... args) {
87 reset();
88 //this->value = 0;
89 add(args...);
90 }
91
92
93 template <typename T, typename ... TT>
94 inline
95 void add(const T & arg, const TT &... args) {
96 _add(arg);
97 add(args...);
98 }
99
100protected:
101
102 inline
103 void reset(){
104 colour = Colour::DEFAULT_COLOR;
105 line = Line::NO_LINE;
106 style.clear();
107 };
108
109
110 inline
111 void set(){};
112
113 inline
114 void add(){};
115
116 inline
117 void _add(const Colour & c){
118 colour = c;
119 };
120
121 inline
122 void _add(const Line & l){
123 line = l;
124 };
125
126 inline
127 void _add(const Style & s){
128 style.insert(s);
129 };
130
131};
132
133DRAIN_TYPENAME(TextStyle);
134
135DRAIN_TYPENAME(TextStyle::Colour);
136DRAIN_TYPENAME(TextStyle::Line);
137DRAIN_TYPENAME(TextStyle::Style);
138
139inline
140std::ostream & operator<<(std::ostream & ostr, const TextStyle &t){
141 ostr << __FILE__ << ':' << __LINE__ << '?';
142 return ostr;
143}
144
145
146} // ::drain
147
148#endif
Utility for scanning text segments.
Definition TextStyle.h:49
Definition Data.h:1473