34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 35 #error "Only <final/final.h> can be included directly." 43 #include "final/ftypes.h" 44 #include "final/output/tty/sgr_optimizer.h" 45 #include "final/util/fstring.h" 65 const char* a_foreground;
66 const char* a_background;
67 const char* foreground;
68 const char* background;
69 const char* color_pair;
70 const char* orig_pair;
71 const char* orig_colors;
73 int attr_without_color;
74 bool ansi_default_color;
100 auto getClassName()
const ->
FString;
104 void setTermEnvironment (
const TermEnv&);
105 void setMaxColor (
const int&) noexcept;
106 void setNoColorVideo (
int) noexcept;
107 void setDefaultColorSupport() noexcept;
108 void unsetDefaultColorSupport() noexcept;
109 void set_enter_bold_mode (
const char[]);
110 void set_exit_bold_mode (
const char[]);
111 void set_enter_dim_mode (
const char[]);
112 void set_exit_dim_mode (
const char[]);
113 void set_enter_italics_mode (
const char[]);
114 void set_exit_italics_mode (
const char[]);
115 void set_enter_underline_mode (
const char[]);
116 void set_exit_underline_mode (
const char[]);
117 void set_enter_blink_mode (
const char[]);
118 void set_exit_blink_mode (
const char[]);
119 void set_enter_reverse_mode (
const char[]);
120 void set_exit_reverse_mode (
const char[]);
121 void set_enter_secure_mode (
const char[]);
122 void set_exit_secure_mode (
const char[]);
123 void set_enter_protected_mode (
const char[]);
124 void set_exit_protected_mode (
const char[]);
125 void set_enter_crossed_out_mode (
const char[]);
126 void set_exit_crossed_out_mode (
const char[]);
127 void set_enter_dbl_underline_mode (
const char[]);
128 void set_exit_dbl_underline_mode (
const char[]);
129 void set_enter_standout_mode (
const char[]);
130 void set_exit_standout_mode (
const char[]);
131 void set_set_attributes (
const char[]);
132 void set_exit_attribute_mode (
const char[]);
133 void set_enter_alt_charset_mode (
const char[]);
134 void set_exit_alt_charset_mode (
const char[]);
135 void set_enter_pc_charset_mode (
const char[]);
136 void set_exit_pc_charset_mode (
const char[]);
137 void set_a_foreground_color (
const char[]);
138 void set_a_background_color (
const char[]);
139 void set_foreground_color (
const char[]);
140 void set_background_color (
const char[]);
141 void set_term_color_pair (
const char[]);
142 void set_orig_pair (
const char[]);
143 void set_orig_colors (
const char[]);
146 static auto isNormal (
const FChar&) -> bool;
150 static auto vga2ansi (FColor) -> FColor;
151 auto changeAttribute (
FChar&,
FChar&) -> std::string;
168 Capability a_foreground{};
169 Capability a_background{};
170 Capability foreground{};
171 Capability background{};
172 Capability color_pair{};
173 Capability orig_pair{};
174 Capability orig_colors{};
175 int attr_without_color{0};
177 bool monochron{
true};
178 bool ansi_default_color{
false};
181 struct AttributeChanges
188 using SetFunctionCall = std::function<bool(FOptiAttr*, FChar&)>;
190 struct AttributeHandlerEntry
193 SetFunctionCall
function;
196 using AttributeHandlers = std::array<AttributeHandlerEntry, 13>;
197 using NoColorVideoHandler = std::function<void(FOptiAttr*, FChar&)>;
198 using NoColorVideoHandlerTable = std::array<NoColorVideoHandler, 18>;
201 enum init_reset_tests
204 test_ansi_reset = 0x01,
205 test_adm3_reset = 0x02,
213 auto setTermBold (
FChar&) -> bool;
214 auto unsetTermBold (
FChar&) -> bool;
215 auto setTermDim (
FChar&) -> bool;
216 auto unsetTermDim (
FChar&) -> bool;
217 auto setTermItalic (
FChar&) -> bool;
218 auto unsetTermItalic (
FChar&) -> bool;
219 auto setTermUnderline (
FChar&) -> bool;
220 auto unsetTermUnderline (
FChar&) -> bool;
221 auto setTermBlink (
FChar&) -> bool;
222 auto unsetTermBlink (
FChar&) -> bool;
223 auto setTermReverse (
FChar&) -> bool;
224 auto unsetTermReverse (
FChar&) -> bool;
225 auto setTermStandout (
FChar&) -> bool;
226 auto unsetTermStandout (
FChar&) -> bool;
227 auto setTermInvisible (
FChar&) -> bool;
228 auto unsetTermInvisible (
FChar&) -> bool;
229 auto setTermProtected (
FChar&) -> bool;
230 auto unsetTermProtected (
FChar&) -> bool;
231 auto setTermCrossedOut (
FChar&) -> bool;
232 auto unsetTermCrossedOut (
FChar&) -> bool;
233 auto setTermDoubleUnderline (
FChar&) -> bool;
234 auto unsetTermDoubleUnderline (
FChar&) -> bool;
236 auto unsetTermAttributes (
FChar&) -> bool;
237 auto setTermAltCharset (
FChar&) -> bool;
238 auto unsetTermAltCharset (
FChar&) -> bool;
239 auto setTermPCcharset (
FChar&) -> bool;
240 auto unsetTermPCcharset (
FChar&) -> bool;
241 auto setTermDefaultColor (
FChar&) -> bool;
242 void setAttributesOn (
FChar&);
243 void setAttributesOff (
FChar&);
245 ,
const AttributeHandlers&,
FChar& );
248 static auto hasColor (
const FChar&) -> bool;
249 static auto hasAttribute (
const FChar&) -> bool;
250 static auto hasNoAttribute (
const FChar&) -> bool;
251 auto isItalicsUsed (
const FChar&,
const FChar&)
const -> bool;
252 auto isCrossedOutUsed (
const FChar&,
const FChar&)
const -> bool;
253 auto isDoubleUnderlineUsed (
const FChar&,
const FChar&)
const -> bool;
254 auto isPCcharsetUsed (
const FChar&,
const FChar&)
const -> bool;
255 auto isPCcharsetUsable (
FChar&,
const FChar&) -> bool;
256 auto hasColorChanged (
const FChar&,
const FChar&)
const -> bool;
259 void resetColor (
FChar&)
const;
260 void prevent_no_color_video_attributes (
FChar&,
bool =
false);
263 void changeAttributeSeparately (
FChar&,
FChar&);
265 void normalizeColor (FColor&)
const noexcept;
266 void handleDefaultColors (
FChar&,
FChar&, FColor&, FColor&);
267 void change_to_default_color (
FChar&,
FChar&, FColor&, FColor&);
268 void setDefaultForeground (
FChar&);
269 void setDefaultBackground (
FChar&);
270 void change_current_color (
const FChar&,
const FColor,
const FColor);
271 void resetAttribute (
FChar&)
const;
272 void reset (
FChar&)
const;
273 auto caused_reset_attributes (
const char[], uChar = all_tests)
const -> bool;
274 void init_reset_attribute (Capability&, uChar = all_tests)
const;
275 auto fake_reverse_color_change (
const FChar& term)
const -> bool;
276 auto hasCharsetEquivalence()
const -> bool;
277 static auto getNoColorVideoHandlerTable() ->
const NoColorVideoHandlerTable&;
278 static auto getAttributeOnHandlers() ->
const AttributeHandlers&;
279 static auto getAttributeOffHandlers() ->
const AttributeHandlers&;
280 static auto getByte0ReverseMask() -> uInt8;
281 static auto getByte1Mask() -> uInt8;
282 static auto getByte1ResetMask() -> uInt8;
283 static auto getByte2ResetMask() -> uInt8;
284 void detectSwitchOn (
const FChar&,
const FChar&);
285 void detectSwitchOff (
const FChar&,
const FChar&);
286 auto switchOn()
const -> bool;
287 auto switchOff()
const -> bool;
288 template <
typename CharT
289 , enable_if_char_ptr_t<CharT> =
nullptr>
290 auto append_sequence (CharT) -> bool;
291 template <
typename CharT
292 , enable_if_char_array_t<CharT> =
nullptr>
293 auto append_sequence (CharT) -> bool;
294 auto append_sequence (
const std::string&) -> bool;
299 TextStyle F_italics{};
300 TextStyle F_underline{};
302 TextStyle F_reverse{};
303 TextStyle F_standout{};
304 TextStyle F_secure{};
305 TextStyle F_protected{};
306 TextStyle F_crossed_out{};
307 TextStyle F_dbl_underline{};
308 TextStyle F_attributes{};
309 TextStyle F_alt_charset{};
310 TextStyle F_pc_charset{};
311 ColorStyle F_color{};
313 AttributeChanges changes{};
314 std::string attr_buf{};
316 bool alt_equal_pc_charset{
false};
317 bool fake_reverse{
false};
323 inline auto FOptiAttr::getClassName()
const ->
FString 324 {
return "FOptiAttr"; }
327 inline void FOptiAttr::setMaxColor (
const int& c) noexcept
328 { F_color.max_color = c; }
331 inline void FOptiAttr::setNoColorVideo (
int attr) noexcept
332 { F_color.attr_without_color = attr; }
335 inline void FOptiAttr::setDefaultColorSupport() noexcept
336 { F_color.ansi_default_color =
true; }
339 inline void FOptiAttr::unsetDefaultColorSupport() noexcept
340 { F_color.ansi_default_color =
false; }
343 template <
typename CharT
344 , enable_if_char_ptr_t<CharT>>
345 inline auto FOptiAttr::append_sequence (CharT seq) ->
bool 349 ? append_sequence(std::string(seq))
354 template <
typename CharT
355 , enable_if_char_array_t<CharT>>
356 inline auto FOptiAttr::append_sequence (CharT seq) ->
bool 359 return append_sequence(std::string(seq));
364 #endif // FOPTIATTR_H Definition: class_template.cpp:25
Definition: foptiattr.h:57
Definition: foptiattr.h:54
Definition: foptiattr.h:77
Definition: sgr_optimizer.h:49
Definition: foptiattr.h:63