FINAL CUT
fvtermattribute.h
1 /***********************************************************************
2 * fvtermattribute.h - Manipulation of FChar colors and attributes *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2021-2026 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Standalone class
24  * ════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTermAttribute ▏
28  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
29  */
30 
31 #ifndef FVTERMATTRIBUTE_H
32 #define FVTERMATTRIBUTE_H
33 
34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
35  #error "Only <final/final.h> can be included directly."
36 #endif
37 
38 #include "final/ftypes.h"
39 #include "final/util/fstring.h"
40 #include "final/vterm/fcolorpair.h"
41 
42 namespace finalcut
43 {
44 
45 namespace internal
46 {
47 
48 constexpr auto getAttrResetMask() noexcept -> uInt32
49 {
50  FCharAttribute mask{};
51  mask.bold = true;
52  mask.dim = true;
53  mask.italic = true;
54  mask.underline = true;
55  mask.blink = true;
56  mask.reverse = true;
57  mask.standout = true;
58  mask.invisible = true;
59  mask.protect = true;
60  mask.crossed_out = true;
61  mask.dbl_underline = true;
62  mask.alt_charset = true;
63  mask.pc_charset = true;
64  mask.transparent = true;
65  mask.color_overlay = true;
66  mask.inherit_background = true;
67  mask.no_changes = true;
68  return 0xffffffff & ~(FCharAttribute_to_uInt32(mask));
69 }
70 
71 struct attr_var
72 {
73  static constexpr auto reset_mask = getAttrResetMask();
74 };
75 
76 } // namespace internal
77 
78 // class forward declaration
79 class FColorPair;
80 class FStyle;
81 
82 //----------------------------------------------------------------------
83 // class FVTermAttribute
84 //----------------------------------------------------------------------
85 
87 {
88  public:
89  // Constructors
91 
92  // Disable copy constructor
93  FVTermAttribute (const FVTermAttribute&) = delete;
94 
95  // Disable move constructor
96  FVTermAttribute (FVTermAttribute&&) noexcept = delete;
97 
98  // Destructor
99  virtual ~FVTermAttribute() noexcept;
100 
101  // Disable copy assignment operator (=)
102  auto operator = (const FVTermAttribute&) -> FVTermAttribute& = delete;
103 
104  // Disable move assignment operator (=)
105  auto operator = (FVTermAttribute&&) noexcept -> FVTermAttribute& = delete;
106 
107  // Accessors
108  virtual auto getClassName() const -> FString;
109  static auto getTermForegroundColor() noexcept -> FColor;
110  static auto getTermBackgroundColor() noexcept -> FColor;
111  static auto getAttribute() noexcept -> FChar&;
112 
113  // Mutators
114  static void setColor (FColor, FColor) noexcept;
115  static void setColor (const FColorPair&) noexcept;
116  static void setNormal() noexcept;
117  static void setBold (bool) noexcept;
118  static void setBold() noexcept;
119  static void unsetBold() noexcept;
120  static void setDim (bool) noexcept;
121  static void setDim() noexcept;
122  static void unsetDim() noexcept;
123  static void setItalic (bool) noexcept;
124  static void setItalic() noexcept;
125  static void unsetItalic() noexcept;
126  static void setUnderline (bool) noexcept;
127  static void setUnderline() noexcept;
128  static void unsetUnderline() noexcept;
129  static void setBlink (bool) noexcept;
130  static void setBlink() noexcept;
131  static void unsetBlink() noexcept;
132  static void setReverse (bool) noexcept;
133  static void setReverse() noexcept;
134  static void unsetReverse() noexcept;
135  static void setStandout (bool) noexcept;
136  static void setStandout() noexcept;
137  static void unsetStandout() noexcept;
138  static void setInvisible (bool) noexcept;
139  static void setInvisible() noexcept;
140  static void unsetInvisible() noexcept;
141  static void setProtected (bool) noexcept;
142  static void setProtected() noexcept;
143  static void unsetProtected() noexcept;
144  static void setCrossedOut (bool) noexcept;
145  static void setCrossedOut() noexcept;
146  static void unsetCrossedOut() noexcept;
147  static void setDoubleUnderline (bool) noexcept;
148  static void setDoubleUnderline() noexcept;
149  static void unsetDoubleUnderline() noexcept;
150  static void setAltCharset (bool) noexcept;
151  static void setAltCharset() noexcept;
152  static void unsetAltCharset() noexcept;
153  static void setPCcharset (bool) noexcept;
154  static void setPCcharset() noexcept;
155  static void unsetPCcharset() noexcept;
156  static void setTransparent (bool) noexcept;
157  static void setTransparent() noexcept;
158  static void unsetTransparent() noexcept;
159  static void setColorOverlay (bool) noexcept;
160  static void setColorOverlay() noexcept;
161  static void unsetColorOverlay() noexcept;
162  static void setInheritBackground (bool) noexcept;
163  static void setInheritBackground() noexcept;
164  static void unsetInheritBackground() noexcept;
165 
166  // Predicates
167  static auto isBold() noexcept -> bool;
168  static auto isDim() noexcept -> bool;
169  static auto isItalic() noexcept -> bool;
170  static auto isUnderline() noexcept -> bool;
171  static auto isBlink() noexcept -> bool;
172  static auto isReverse() noexcept -> bool;
173  static auto isStandout() noexcept -> bool;
174  static auto isInvisible() noexcept -> bool;
175  static auto isProtected() noexcept -> bool;
176  static auto isCrossedOut() noexcept -> bool;
177  static auto isDoubleUnderline() noexcept -> bool;
178  static auto isAltCharset() noexcept -> bool;
179  static auto isPCcharset() noexcept -> bool;
180  static auto isTransparent() noexcept -> bool;
181  static auto isColorOverlay() noexcept -> bool;
182  static auto isInheritBackground() noexcept -> bool;
183 
184  // Methods
185  static void initAttribute() noexcept;
186  static void print (const FStyle&);
187  static void print (const FColorPair&) noexcept;
188 
189  private:
190  // Data members
191  static FChar next_attribute;
192 };
193 
194 
195 // FVTermAttribute inline functions
196 //----------------------------------------------------------------------
197 inline auto FVTermAttribute::getClassName() const -> FString
198 { return "FVTermAttribute"; }
199 
200 //----------------------------------------------------------------------
201 inline auto FVTermAttribute::getTermForegroundColor() noexcept -> FColor
202 { return next_attribute.color.getPair().fg; }
203 
204 //----------------------------------------------------------------------
205 inline auto FVTermAttribute::getTermBackgroundColor() noexcept -> FColor
206 { return next_attribute.color.getPair().bg; }
207 
208 //----------------------------------------------------------------------
209 inline auto FVTermAttribute::getAttribute() noexcept -> FChar&
210 { return next_attribute; }
211 
212 //----------------------------------------------------------------------
213 inline void FVTermAttribute::setColor (FColor fg, FColor bg) noexcept
214 {
215  // Changes colors
216  next_attribute.color.setPair({fg, bg});
217 }
218 
219 //----------------------------------------------------------------------
220 inline void FVTermAttribute::setColor (const FColorPair& pair) noexcept
221 {
222  setColor (pair.getForegroundColor(), pair.getBackgroundColor());
223 }
224 
225 //----------------------------------------------------------------------
226 inline void FVTermAttribute::setNormal() noexcept
227 {
228  // Reset all character attributes
229  next_attribute.color = default_color_pair;
230  next_attribute.unsetBit(internal::attr_var::reset_mask);
231 }
232 
233 //----------------------------------------------------------------------
234 inline void FVTermAttribute::setBold (bool enable) noexcept
235 {
236  next_attribute.setBit(FAttribute::set::bold, enable);
237 }
238 
239 //----------------------------------------------------------------------
240 inline void FVTermAttribute::setBold() noexcept
241 {
242  next_attribute.setBit(FAttribute::set::bold);
243 }
244 
245 //----------------------------------------------------------------------
246 inline void FVTermAttribute::unsetBold() noexcept
247 {
248  next_attribute.unsetBit(FAttribute::unset::bold);
249 }
250 
251 //----------------------------------------------------------------------
252 inline void FVTermAttribute::setDim (bool enable) noexcept
253 {
254  next_attribute.setBit(FAttribute::set::dim, enable);
255 }
256 
257 //----------------------------------------------------------------------
258 inline void FVTermAttribute::setDim() noexcept
259 {
260  next_attribute.setBit(FAttribute::set::dim);
261 }
262 
263 //----------------------------------------------------------------------
264 inline void FVTermAttribute::unsetDim() noexcept
265 {
266  next_attribute.unsetBit(FAttribute::unset::dim);
267 }
268 
269 //----------------------------------------------------------------------
270 inline void FVTermAttribute::setItalic (bool enable) noexcept
271 {
272  next_attribute.setBit(FAttribute::set::italic, enable);
273 }
274 
275 //----------------------------------------------------------------------
276 inline void FVTermAttribute::setItalic() noexcept
277 {
278  next_attribute.setBit(FAttribute::set::italic);
279 }
280 
281 //----------------------------------------------------------------------
282 inline void FVTermAttribute::unsetItalic() noexcept
283 {
284  next_attribute.unsetBit(FAttribute::unset::italic);
285 }
286 
287 //----------------------------------------------------------------------
288 inline void FVTermAttribute::setUnderline (bool enable) noexcept
289 {
290  next_attribute.setBit(FAttribute::set::underline, enable);
291 }
292 
293 //----------------------------------------------------------------------
294 inline void FVTermAttribute::setUnderline() noexcept
295 {
296  next_attribute.setBit(FAttribute::set::underline);
297 }
298 
299 //----------------------------------------------------------------------
300 inline void FVTermAttribute::unsetUnderline() noexcept
301 {
302  next_attribute.unsetBit(FAttribute::unset::underline);
303 }
304 
305 //----------------------------------------------------------------------
306 inline void FVTermAttribute::setBlink (bool enable) noexcept
307 {
308  next_attribute.setBit(FAttribute::set::blink, enable);
309 }
310 
311 //----------------------------------------------------------------------
312 inline void FVTermAttribute::setBlink() noexcept
313 {
314  next_attribute.setBit(FAttribute::set::blink);
315 }
316 
317 //----------------------------------------------------------------------
318 inline void FVTermAttribute::unsetBlink() noexcept
319 {
320  next_attribute.unsetBit(FAttribute::unset::blink);
321 }
322 
323 //----------------------------------------------------------------------
324 inline void FVTermAttribute::setReverse (bool enable) noexcept
325 {
326  next_attribute.setBit(FAttribute::set::reverse, enable);
327 }
328 
329 //----------------------------------------------------------------------
330 inline void FVTermAttribute::setReverse() noexcept
331 {
332  next_attribute.setBit(FAttribute::set::reverse);
333 }
334 
335 //----------------------------------------------------------------------
336 inline void FVTermAttribute::unsetReverse() noexcept
337 {
338  next_attribute.unsetBit(FAttribute::unset::reverse);
339 }
340 
341 //----------------------------------------------------------------------
342 inline void FVTermAttribute::setStandout (bool enable) noexcept
343 {
344  next_attribute.setBit(FAttribute::set::standout, enable);
345 }
346 
347 //----------------------------------------------------------------------
348 inline void FVTermAttribute::setStandout() noexcept
349 {
350  next_attribute.setBit(FAttribute::set::standout);
351 }
352 
353 //----------------------------------------------------------------------
354 inline void FVTermAttribute::unsetStandout() noexcept
355 {
356  next_attribute.unsetBit(FAttribute::unset::standout);
357 }
358 
359 //----------------------------------------------------------------------
360 inline void FVTermAttribute::setInvisible (bool enable) noexcept
361 {
362  next_attribute.setBit(FAttribute::set::invisible, enable);
363 }
364 
365 //----------------------------------------------------------------------
366 inline void FVTermAttribute::setInvisible() noexcept
367 {
368  next_attribute.setBit(FAttribute::set::invisible);
369 }
370 
371 //----------------------------------------------------------------------
372 inline void FVTermAttribute::unsetInvisible() noexcept
373 {
374  next_attribute.unsetBit(FAttribute::unset::invisible);
375 }
376 
377 //----------------------------------------------------------------------
378 inline void FVTermAttribute::setProtected (bool enable) noexcept
379 {
380  next_attribute.setBit(FAttribute::set::protect, enable);
381 }
382 
383 //----------------------------------------------------------------------
384 inline void FVTermAttribute::setProtected() noexcept
385 {
386  next_attribute.setBit(FAttribute::set::protect);
387 }
388 
389 //----------------------------------------------------------------------
390 inline void FVTermAttribute::unsetProtected() noexcept
391 {
392  next_attribute.unsetBit(FAttribute::unset::protect);
393 }
394 
395 //----------------------------------------------------------------------
396 inline void FVTermAttribute::setCrossedOut (bool enable) noexcept
397 {
398  next_attribute.setBit(FAttribute::set::crossed_out, enable);
399 }
400 
401 //----------------------------------------------------------------------
402 inline void FVTermAttribute::setCrossedOut() noexcept
403 {
404  next_attribute.setBit(FAttribute::set::crossed_out);
405 }
406 
407 //----------------------------------------------------------------------
408 inline void FVTermAttribute::unsetCrossedOut() noexcept
409 {
410  next_attribute.unsetBit(FAttribute::unset::crossed_out);
411 }
412 
413 //----------------------------------------------------------------------
414 inline void FVTermAttribute::setDoubleUnderline (bool enable) noexcept
415 {
416  next_attribute.setBit(FAttribute::set::dbl_underline, enable);
417 }
418 
419 //----------------------------------------------------------------------
420 inline void FVTermAttribute::setDoubleUnderline() noexcept
421 {
422  next_attribute.setBit(FAttribute::set::dbl_underline);
423 }
424 
425 //----------------------------------------------------------------------
426 inline void FVTermAttribute::unsetDoubleUnderline() noexcept
427 {
428  next_attribute.unsetBit(FAttribute::unset::dbl_underline);
429 }
430 
431 //----------------------------------------------------------------------
432 inline void FVTermAttribute::setAltCharset (bool enable) noexcept
433 {
434  next_attribute.setBit(FAttribute::set::alt_charset, enable);
435 }
436 
437 //----------------------------------------------------------------------
438 inline void FVTermAttribute::setAltCharset() noexcept
439 {
440  next_attribute.setBit(FAttribute::set::alt_charset);
441 }
442 
443 //----------------------------------------------------------------------
444 inline void FVTermAttribute::unsetAltCharset() noexcept
445 {
446  next_attribute.unsetBit(FAttribute::unset::alt_charset);
447 }
448 
449 //----------------------------------------------------------------------
450 inline void FVTermAttribute::setPCcharset (bool enable) noexcept
451 {
452  next_attribute.setBit(FAttribute::set::pc_charset, enable);
453 }
454 
455 //----------------------------------------------------------------------
456 inline void FVTermAttribute::setPCcharset() noexcept
457 {
458  next_attribute.setBit(FAttribute::set::pc_charset);
459 }
460 
461 //----------------------------------------------------------------------
462 inline void FVTermAttribute::unsetPCcharset() noexcept
463 {
464  next_attribute.unsetBit(FAttribute::unset::pc_charset);
465 }
466 
467 //----------------------------------------------------------------------
468 inline void FVTermAttribute::setTransparent (bool enable) noexcept
469 {
470  next_attribute.setBit(FAttribute::set::transparent, enable);
471 }
472 
473 //----------------------------------------------------------------------
474 inline void FVTermAttribute::setTransparent() noexcept
475 {
476  next_attribute.setBit(FAttribute::set::transparent);
477 }
478 
479 //----------------------------------------------------------------------
480 inline void FVTermAttribute::unsetTransparent() noexcept
481 {
482  next_attribute.unsetBit(FAttribute::unset::transparent);
483 }
484 
485 //----------------------------------------------------------------------
486 inline void FVTermAttribute::setColorOverlay (bool enable) noexcept
487 {
488  next_attribute.setBit(FAttribute::set::color_overlay, enable);
489 }
490 
491 //----------------------------------------------------------------------
492 inline void FVTermAttribute::setColorOverlay() noexcept
493 {
494  next_attribute.setBit(FAttribute::set::color_overlay);
495 }
496 
497 //----------------------------------------------------------------------
498 inline void FVTermAttribute::unsetColorOverlay() noexcept
499 {
500  next_attribute.unsetBit(FAttribute::unset::color_overlay);
501 }
502 
503 //----------------------------------------------------------------------
504 inline void FVTermAttribute::setInheritBackground (bool enable) noexcept
505 {
506  next_attribute.setBit(FAttribute::set::inherit_background, enable);
507 }
508 
509 //----------------------------------------------------------------------
510 inline void FVTermAttribute::setInheritBackground() noexcept
511 {
512  next_attribute.setBit(FAttribute::set::inherit_background);
513 }
514 
515 //----------------------------------------------------------------------
516 inline void FVTermAttribute::unsetInheritBackground() noexcept
517 {
518  next_attribute.unsetBit(FAttribute::unset::inherit_background);
519 }
520 
521 //----------------------------------------------------------------------
522 inline auto FVTermAttribute::isBold() noexcept -> bool
523 {
524  return next_attribute.isBitSet(FAttribute::set::bold);
525 }
526 
527 //----------------------------------------------------------------------
528 inline auto FVTermAttribute::isDim() noexcept -> bool
529 {
530  return next_attribute.isBitSet(FAttribute::set::dim);
531 }
532 
533 //----------------------------------------------------------------------
534 inline auto FVTermAttribute::isItalic() noexcept -> bool
535 {
536  return next_attribute.isBitSet(FAttribute::set::italic);
537 }
538 
539 //----------------------------------------------------------------------
540 inline auto FVTermAttribute::isUnderline() noexcept -> bool
541 {
542  return next_attribute.isBitSet(FAttribute::set::underline);
543 }
544 
545 //----------------------------------------------------------------------
546 inline auto FVTermAttribute::isBlink() noexcept -> bool
547 {
548  return next_attribute.isBitSet(FAttribute::set::blink);
549 }
550 
551 //----------------------------------------------------------------------
552 inline auto FVTermAttribute::isReverse() noexcept -> bool
553 {
554  return next_attribute.isBitSet(FAttribute::set::reverse);
555 }
556 
557 //----------------------------------------------------------------------
558 inline auto FVTermAttribute::isStandout() noexcept -> bool
559 {
560  return next_attribute.isBitSet(FAttribute::set::standout);
561 }
562 
563 //----------------------------------------------------------------------
564 inline auto FVTermAttribute::isInvisible() noexcept -> bool
565 {
566  return next_attribute.isBitSet(FAttribute::set::invisible);
567 }
568 
569 //----------------------------------------------------------------------
570 inline auto FVTermAttribute::isProtected() noexcept -> bool
571 {
572  return next_attribute.isBitSet(FAttribute::set::protect);
573 }
574 
575 //----------------------------------------------------------------------
576 inline auto FVTermAttribute::isCrossedOut() noexcept -> bool
577 {
578  return next_attribute.isBitSet(FAttribute::set::crossed_out);
579 }
580 
581 //----------------------------------------------------------------------
582 inline auto FVTermAttribute::isDoubleUnderline() noexcept -> bool
583 {
584  return next_attribute.isBitSet(FAttribute::set::dbl_underline);
585 }
586 
587 //----------------------------------------------------------------------
588 inline auto FVTermAttribute::isAltCharset() noexcept -> bool
589 {
590  return next_attribute.isBitSet(FAttribute::set::alt_charset);
591 }
592 
593 //----------------------------------------------------------------------
594 inline auto FVTermAttribute::isPCcharset() noexcept -> bool
595 {
596  return next_attribute.isBitSet(FAttribute::set::pc_charset);
597 }
598 
599 //----------------------------------------------------------------------
600 inline auto FVTermAttribute::isTransparent() noexcept -> bool
601 {
602  return next_attribute.isBitSet(FAttribute::set::transparent);
603 }
604 
605 //----------------------------------------------------------------------
606 inline auto FVTermAttribute::isColorOverlay() noexcept -> bool
607 {
608  return next_attribute.isBitSet(FAttribute::set::color_overlay);
609 }
610 
611 //----------------------------------------------------------------------
612 inline auto FVTermAttribute::isInheritBackground() noexcept -> bool
613 {
614  return next_attribute.isBitSet(FAttribute::set::inherit_background);
615 }
616 
617 } // namespace finalcut
618 
619 #endif // FVTERMATTRIBUTE_H
Definition: class_template.cpp:25
Definition: ftypes.h:1081
Definition: fvtermattribute.h:71
Definition: fstring.h:82
Definition: fstyle.h:49
Definition: fcolorpair.h:49
Definition: fvtermattribute.h:86