libzypp: zypp-tui/utils/ansi.h Source File

libzypp 17.38.15

ansi.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* Strictly for internal use!
12*/
13
14#ifndef ZYPP_TUI_UTILS_ANSI_H
15#define ZYPP_TUI_UTILS_ANSI_H
16
17#include <cstdint>
18#include <iostream>
19#include <sstream>
20#include <type_traits>
21#include <memory>
22#include <map>
23#include <string>
24
25#include <zypp-core/base/String.h>
26
27
28namespace ztui {
29
33bool do_ttyout(); // implemented in colors.cc
34
36bool do_colors(); // implemented in colors.cc
37
39bool mayUseANSIEscapes();
40
42bool hasANSIColor();
43
45 namespace ansi
46{
48 namespace tty
49 {
54 class EscapeSequence
55 {
56 public:
57 EscapeSequence( const char * ansi_r, const char * fallback_r = "" )
58 : _seq( ansi_r )
59 , _fbck( fallback_r )
60 {}
61
62 const char * str() const
63 {
64 if ( _fbck ) // determine _seq<>_fbck on 1st use (dtor is too early as do_ttyout() is not yet ready)
65 {
66 if ( ! do_ttyout() )
67 _seq = _fbck;
68 _fbck = nullptr;
69 }
70 return _seq;
71 }
72
73 private:
74 mutable const char * _seq;
75 mutable const char * _fbck;
76 };
77
79 inline std::ostream & operator<<( std::ostream & str, const EscapeSequence & obj )
80 { return str << obj.str(); }
81
82
83 // EscapeSequence definitions in colors.cc
84
85 extern const EscapeSequence clearLN;
86
87 extern const EscapeSequence cursorUP;
88 extern const EscapeSequence cursorDOWN;
89 extern const EscapeSequence cursorRIGHT;
90 extern const EscapeSequence cursorLEFT;
91
92 } // namespace tty
93
94
95#define ZYPPER_TRACE_SGR 0
96#undef ESC
97#if ( ZYPPER_TRACE_SGR < 2 )
98#define ESC "\033"
99#else
100#define ESC "@"
101#endif
145 template<class Tp_>
146 struct ColorTraits
147 { enum { customColorCtor = false }; };
148
149 // enabled via ctor Color::Constant -> Color
151 template <typename CCC_>
152 using EnableIfCustomColorCtor = std::enable_if_t< ansi::ColorTraits<std::decay_t<CCC_>>::customColorCtor >;
153
155 template <typename CCC_>
156 using DisableIfCustomColorCtor = std::enable_if_t< !ansi::ColorTraits<std::decay_t<CCC_>>::customColorCtor >;
157
172 class Color
173 {
174 public:
176 enum class Attr : std::uint8_t
177 { Unchanged, Normal, Bright, Reverse };
178
180 enum class Fg : std::uint8_t
181 { Unchanged, Default, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White };
182
184 enum class Bg : std::uint8_t
185 { Unchanged, Default, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White };
186
188 using UidType = std::uint32_t;
189
194 enum Constant : std::uint8_t
195 {
196 Black, BrightBlack, // BrightBlack = Darkgray
197 Red, BrightRed,
198 Green, BrightGreen,
199 Yellow, BrightYellow, // Yellow = Brown on Standard VGA
200 Blue, BrightBlue,
201 Magenta, BrightMagenta,
202 Cyan, BrightCyan,
203 White, BrightWhite, // White = Gray
204 Default, BrightDefault
205 };
206
207 public:
209 Color()
210 : _comp( Attr::Normal, Fg::Default, Bg::Default )
211 {}
212
213 Color( Attr attr_r, Fg fg_r = Fg::Unchanged, Bg bg_r = Bg::Unchanged )
214 : _comp( attr_r, fg_r, bg_r )
215 {}
216
217 Color( Attr attr_r, Bg bg_r )
218 : _comp( attr_r, Fg::Unchanged, bg_r )
219 {}
220
221 Color( Fg fg_r, Bg bg_r = Bg::Unchanged )
222 : _comp( Attr::Unchanged, fg_r, bg_r )
223 {}
224
225 Color( Bg bg_r )
226 : _comp( Attr::Unchanged, Fg::Unchanged, bg_r )
227 {}
228
230 Color( Constant color_r, Bg bg_r = Bg::Default )
231 : _comp( ( color_r % 2 ? Attr::Bright : Attr::Normal ), Fg::Default, bg_r )
232 {
233 switch ( color_r )
234 {
235 case Black:
236 case BrightBlack: _comp.fg = Fg::Black; break;
237 case Red:
238 case BrightRed: _comp.fg = Fg::Red; break;
239 case Green:
240 case BrightGreen: _comp.fg = Fg::Green; break;
241 case Yellow:
242 case BrightYellow: _comp.fg = Fg::Yellow; break;
243 case Blue:
244 case BrightBlue: _comp.fg = Fg::Blue; break;
245 case Magenta:
246 case BrightMagenta: _comp.fg = Fg::Magenta; break;
247 case Cyan:
248 case BrightCyan: _comp.fg = Fg::Cyan; break;
249 case White:
250 case BrightWhite: _comp.fg = Fg::White; break;
251 default:
252 case Default:
253 case BrightDefault: break;
254 }
255 }
256
258 template<class CCC_, typename = EnableIfCustomColorCtor<CCC_>>
259 Color( CCC_ && color_r )
260 : Color( customColorCtor( std::forward<CCC_>(color_r) ) )
261 {}
262
263 public:
265 static Color nocolor()
266 { return Color( UidType(0) ); }
267
278 static Color fromString( const std::string &colorName );
279
281 explicit operator bool() const
282 { return uid(); }
283
291 static const std::string & SGRReset()
292 {
293#if ( ZYPPER_TRACE_SGR )
294 static const std::string & _reset( *(new std::string( ESC"[0m[!]" )) ); // live until program ends
295#else
296 static const std::string & _reset( *(new std::string( ESC"[0m" )) ); // live until program ends
297#endif
298 static const std::string & _noreset( *(new std::string( "" )) ); // live until program ends
299 if(!do_colors()) return _noreset;
300 return _reset;
301 }
302
303 public:
305 Color & operator<=( Color rhs )
306 {
307 if ( rhs._comp.attr != Attr::Unchanged ) _comp.attr = rhs._comp.attr;
308 if ( rhs._comp.fg != Fg::Unchanged ) _comp.fg = rhs._comp.fg;
309 if ( rhs._comp.bg != Bg::Unchanged ) _comp.bg = rhs._comp.bg;
310 return *this;
311 }
312
313 Color & operator<=( Color::Attr rhs )
314 { if ( rhs != Attr::Unchanged ) _comp.attr = rhs; return *this; }
315
316 Color & operator<=( Color::Fg rhs )
317 { if ( rhs != Fg::Unchanged ) _comp.fg = rhs; return *this; }
318
319 Color & operator<=( Color::Bg rhs )
320 { if ( rhs != Bg::Unchanged ) _comp.bg = rhs; return *this; }
321
322 inline Color & operator<=( Color::Constant rhs );
323
325 Color operator<( Color rhs ) const
326 { return Color(*this) <= rhs; }
327
328 Color operator<( Color::Attr rhs ) const
329 { return Color(*this) <= rhs; }
330
331 Color operator<( Color::Fg rhs ) const
332 { return Color(*this) <= rhs; }
333
334 Color operator<( Color::Bg rhs ) const
335 { return Color(*this) <= rhs; }
336
337 inline Color operator<( Color::Constant rhs ) const;
338
339 public:
340 Attr attr() const
341 { return _comp.attr; }
342
343 Color & attr( Attr attr_r )
344 { _comp.attr = attr_r; return *this; }
345
346 Fg fg() const
347 { return _comp.fg; }
348
349 Color & fg( Fg fg_r )
350 { _comp.fg = fg_r; return *this; }
351
352 Bg bg() const
353 { return _comp.bg; }
354
355 Color & bg( Bg bg_r )
356 { _comp.bg = bg_r; return *this; }
357
359 UidType uid() const
360 { return _comp.uid; }
361
363 const std::string & str() const
364 { return genSGR( *this ); }
365
367 std::string debugstr() const
368 { return genSGR( *this ).c_str()+1; }
369
370 public:
372 friend inline bool operator==( Color lhs, Color rhs )
373 { return( lhs.uid() == rhs.uid() ); }
374
376 friend inline bool operator!=( Color lhs, Color rhs )
377 { return ! ( lhs == rhs ); }
378
379 private:
381 static std::string & genSGR( Color color_r )
382 {
383 static std::map<UidType,std::string> & _def( *(new std::map<UidType,std::string>) ); // live until program ends
384
385 if ( ! ( color_r && do_colors() ) ) // nocolor, all ::Unchanged, uid 0: return empty string
386 {
387#if ( ZYPPER_TRACE_SGR )
388 std::string & ret( _def[0] );
389 if ( ret.empty() )
390 ret = "[]";
391 return ret;
392#else
393 return _def[0];
394#endif
395 }
396
397 std::string & ret( _def[color_r._comp.uid] );
398 if ( ret.empty() )
399 {
400 ret += ESC"[";
401 switch ( color_r._comp.attr )
402 {
403 case Attr::Normal: ret += "22;27;"; break;
404 case Attr::Bright: ret += "1;"; break;
405 case Attr::Reverse: ret += "7;"; break;
406 default:
407 case Attr::Unchanged: break;
408 }
409 switch ( color_r._comp.fg )
410 {
411 case Fg::Black: ret += "30;"; break;
412 case Fg::Red: ret += "31;"; break;
413 case Fg::Green: ret += "32;"; break;
414 case Fg::Yellow: ret += "33;"; break;
415 case Fg::Blue: ret += "34;"; break;
416 case Fg::Magenta: ret += "35;"; break;
417 case Fg::Cyan: ret += "36;"; break;
418 case Fg::White: ret += "37;"; break;
419 case Fg::Default: ret += "39;"; break;
420 default:
421 case Fg::Unchanged: break;
422 }
423 switch ( color_r._comp.bg )
424 {
425 case Bg::Black: ret += "40;"; break;
426 case Bg::Red: ret += "41;"; break;
427 case Bg::Green: ret += "42;"; break;
428 case Bg::Yellow: ret += "43;"; break;
429 case Bg::Blue: ret += "44;"; break;
430 case Bg::Magenta: ret += "45;"; break;
431 case Bg::Cyan: ret += "46;"; break;
432 case Bg::White: ret += "47;"; break;
433 case Bg::Default: ret += "49;"; break;
434 default:
435 case Bg::Unchanged: break;
436 }
437 *ret.rbegin() = 'm'; // turn trailing ';' into 'm'
438#if ( ZYPPER_TRACE_SGR )
439 ret += ( color_r == Color() ? "[*]" : "[@]" );
440#endif
441 }
442 return ret;
443 }
444
445 private:
447 Color ( UidType ) {}
448
449 union Comp {
450 Comp() // nocolor, all ::Unchanged, uid 0
451 : uid( 0 )
452 {}
453
454 Comp( Attr attr_r, Fg fg_r, Bg bg_r )
455 : attr( attr_r ), fg( fg_r ), bg( bg_r ), _f( 0 )
456 {}
457
458 struct {
459 Color::Attr attr; // std::uint8_t
460 Color::Fg fg; // std::uint8_t
461 Color::Bg bg; // std::uint8_t
462 std::uint8_t _f; // std::uint8_t
463 };
464 UidType uid; // std::uint32_t
465 } _comp;
466 };
467
468 template<>
469 struct ColorTraits<Color::Constant>
470 { enum { customColorCtor = true }; }; // enabled via ctor Color::Constant -> Color
471
472 // Implememtation after ColorTraits<Color::Constant> instantiation !
473 Color & Color::operator<=( Color::Constant rhs ) { return this->operator<=( Color( rhs, Bg::Unchanged ) ); }
474 Color Color::operator<( Color::Constant rhs ) const { return Color(*this) <= rhs; }
475
477 inline std::ostream & operator<<( std::ostream & str, Color obj )
478 { return str << obj.str(); }
479
496 class ColorString
497 {
498 public:
499 ColorString()
500 : _color( Color::nocolor() )
501 {}
502
504 explicit ColorString( Color color_r )
505 : _color( color_r )
506 {}
507
509 explicit ColorString( const std::string & str_r )
510 : _str( str_r )
511 , _color( Color::nocolor() )
512 {}
513
514 explicit ColorString( std::string && str_r )
515 : _str( std::move(str_r) )
516 , _color( Color::nocolor() )
517 {}
518
520 ColorString( const std::string & str_r, Color color_r )
521 : _str( str_r )
522 , _color( color_r )
523 {}
524
525 ColorString( std::string && str_r, Color color_r )
526 : _str( std::move(str_r) )
527 , _color( color_r )
528 {}
529
531 ColorString( Color color_r, const std::string & str_r )
532 : _str( str_r )
533 , _color( color_r )
534 {}
535
536 ColorString( Color color_r, std::string && str_r )
537 : _str( std::move(str_r) )
538 , _color( color_r )
539 {}
540
541 public:
543 ColorString & operator=( const std::string & str_r )
544 { _str = str_r; return *this; }
545
546 ColorString & operator=( std::string && str_r )
547 { _str = std::move(str_r); return *this; }
548
550 // Append via '<<' (not '+=' '+') because it's
551 // strictly evaluated left-to-right:
552 //
553 // ColorString sep( "-", Color::Cyan );
554 // ColorString ver( "version" );
555 //
556 // ver << sep << "release"; // + prints "-" in cyan :)
557 //
558 // ver += sep + "release"; // - prints "-release" in cyan :(
559 // ver += sep += "release"; // - prints "-release" in cyan :(
560 // (ver += sep) += "release"; // + but ugly syntax
561 //
563 ColorString & operator<<( const ColorString & rhs )
564 { _str += rhs.str(); return *this; }
565
567 ColorString & operator<<( const std::string & str_r )
568 { _str += str_r; return *this; }
569
570 public:
572 ColorString & operator=( Color color_r )
573 { _color = color_r; return *this; }
574
576 ColorString & operator<=( Color color_r )
577 { _color <= color_r; return *this; }
578
580 ColorString operator()( Color color_r ) const
581 { return ColorString( _str, color_r ); }
582
583 public:
585 Color color() const
586 { return _color; }
587
588 public:
590 bool empty() const
591 { return plainstr().empty(); }
592
594 std::string::size_type size() const
595 { return plainstr().size(); }
596
598 std::string str() const
599 { return str( _color ); }
600
601 std::string asString() const
602 { return str(); }
603
605 std::string str( Color color_r ) const
606 {
607 std::string ret( plainstr() );
608 if ( do_colors() && color_r )
609 {
610 using zypp::str::replaceAll;
611 replaceAll( ret, Color::SGRReset(), color_r.str() );
612 ret = color_r.str() + ret + Color::SGRReset();
613 }
614#if ( ZYPPER_TRACE_SGR )
615 return "[\"<]" + ret + "[>\"]";
616#endif
617 return ret;
618 }
619
620 public:
622 const std::string & plainstr() const
623 { return _str; }
624
626 std::string & plainstr()
627 { return _str; }
628
630 const std::string & operator*() const
631 { return plainstr(); }
632
634 std::string & operator*()
635 { return plainstr(); }
636
637 private:
638 std::string _str;
639 Color _color;
640 };
641
643 inline std::ostream & operator<<( std::ostream & str, const ColorString & obj )
644 { return str << obj.str(); }
645
673 class ColorStream
674 {
675 struct nullDeleter { void operator() (void const *) const {}; };
676
677 public:
679 ColorStream()
680 {}
681
683 explicit ColorStream( Color color_r )
684 : _color( color_r )
685 {}
686
688 explicit ColorStream( std::ostream & direct_r )
689 : ColorStream( direct_r, Color::Default )
690 {}
691
693 ColorStream( std::ostream & direct_r, Color color_r )
694 : _directP( &direct_r )
695 , _color( color_r )
696 { (*_directP) << _color; }
697
699 ColorStream( const ColorStream & ) = delete;
700 ColorStream & operator=( const ColorStream & ) = delete;
701
703 ColorStream( ColorStream && ) = default;
704 ColorStream & operator=( ColorStream && ) = default;
705
706 ~ColorStream()
707 { if ( _directP ) (*_directP) << Color::SGRReset(); }
708
710 explicit operator std::ostream &()
711 { return stream(); }
712
713 public:
715 ColorStream & operator=( Color color_r )
716 {
717 _color = color_r;
718 if ( hasStream() )
719 stream() << _color;
720 return *this;
721 }
722
724 ColorStream & operator<=( Color color_r )
725 {
726 _color <= color_r;
727 if ( hasStream() )
728 stream() << _color;
729 return *this;
730 }
731
732 public:
734 Color color() const
735 { return _color; }
736
737 public:
739 std::string str() const
740 {
741 std::string ret;
742 if ( hasContent() )
743 {
744 ret = _bufferP->str();
745 ret += Color::SGRReset();
746 }
747 return ret;
748 }
749
750 public:
752 ColorStream & operator<<( Color color_r )
753 { return operator<=( color_r ); }
754
758 ColorStream & operator<<( const ColorString & val_r )
759 { stream() << ( val_r.color() ? val_r.str() : val_r.str(_color) ) << _color; return *this; }
760
762 ColorStream & operator<<( const ColorStream & val_r )
763#if ( ZYPPER_TRACE_SGR )
764 { if ( val_r.hasContent() ) stream() << "[<<]" << val_r.content() << _color << "[>>]"; return *this; }
765#else
766 { if ( val_r.hasContent() ) stream() << val_r.content() << _color; return *this; }
767#endif
768
770 template<class Tp_, typename = DisableIfCustomColorCtor<Tp_>>
771 ColorStream & operator<<( const Tp_ & val_r ) // ! Universal reference here would be too greedy
772 { stream() << val_r; return *this; }
773
775 ColorStream & operator<<( std::ostream & (*omanip)( std:: ostream & ) )
776 { stream() << omanip; return *this; }
777
778 public:
780 friend inline std::ostream & operator<<( std::ostream & str, const ColorStream & obj )
781#if ( ZYPPER_TRACE_SGR )
782 { if ( obj.hasContent() ) str << "[<<]" << obj.content() << Color::SGRReset() << "[>>]"; return str; }
783#else
784 { if ( obj.hasContent() ) str << obj.content() << Color::SGRReset(); return str; }
785#endif
786
787 private:
789 bool hasStream() const
790 { return _directP || _bufferP; }
791
793 std::ostream & stream() const
794 {
795 if ( _directP )
796 return *_directP;
797
798 if ( !_bufferP )
799 {
800 _bufferP.reset( new std::ostringstream );
801 *_bufferP << _color;
802 }
803 return *_bufferP;
804 }
805
807 bool hasContent() const
808 { return !!_bufferP; }
809
811 std::string content() const
812 {
813 std::string ret;
814 if ( hasContent() )
815 ret = _bufferP->str();
816 return ret;
817 }
818
819 private:
820 std::unique_ptr<std::ostream,nullDeleter> _directP;
821 mutable std::unique_ptr<std::ostringstream> _bufferP;
822 Color _color;
823 };
824
825
826#undef ZYPPER_TRACE_SGR
827} // namespace ansi
828
829
830// Drag them into this namespace:
831using ansi::ColorString;
832using ansi::ColorStream;
833
835template<class Tp_>
836 inline ansi::ColorStream operator<<( ansi::Color color_r, Tp_ && val_r )
837{ return std::move( ansi::ColorStream( color_r ) << std::forward<Tp_>(val_r) ); }
838
839 inline ansi::ColorStream operator<<( ansi::Color color_r, std::ostream & (*omanip)( std::ostream & ) )
840{ return std::move( ansi::ColorStream( color_r ) << omanip ); }
841
843template<class CCC_, class Tp_, typename = ansi::EnableIfCustomColorCtor<CCC_> >
844 inline ansi::ColorStream operator<<( CCC_ && color_r, Tp_ && val_r )
845{ return std::move( ansi::ColorStream( std::forward<CCC_>(color_r) ) << std::forward<Tp_>(val_r) ); }
846
847template<class CCC_, typename = ansi::EnableIfCustomColorCtor<CCC_> >
848 inline ansi::ColorStream operator<<( CCC_ && color_r, std::ostream & (*omanip)( std:: ostream & ) )
849{ return std::move( ansi::ColorStream( std::forward<CCC_>(color_r) ) << omanip ); }
850
851}
852
853
854 namespace std
855{
859template<class CCC_, typename = ztui::ansi::EnableIfCustomColorCtor<CCC_>>
860 inline ostream & operator<<( ostream & str, CCC_ && color_r )
861{ return str << ztui::ansi::Color( std::forward<CCC_>(color_r) ); }
862} // namespace std
863
864#endif // ZYPP_TUI_UTILS_ANSI_H
String.h
ESC
#define ESC
Definition ansi.h:98
bool
ztui::ColorString::ColorString
ColorString()
Definition ansi.h:499
ztui::ansi::ColorStream
Colored stream output if do_colors.
Definition ansi.h:674
ztui::ansi::ColorStream::operator<<
ColorStream & operator<<(const ColorStream &val_r)
Printing another ColorStream using his Color.
Definition ansi.h:762
ztui::ansi::ColorStream::stream
std::ostream & stream() const
Reference to the underlying ostream (direct or auto-created buffer).
Definition ansi.h:793
ztui::ansi::ColorStream::ColorStream
ColorStream(std::ostream &direct_r)
Ctor directly printing to a std::ostream (Color::Default).
Definition ansi.h:688
ztui::ansi::ColorStream::str
std::string str() const
Return a buffered streams content as (colored) string.
Definition ansi.h:739
ztui::ansi::ColorStream::ColorStream
ColorStream(Color color_r)
Ctor taking a Color.
Definition ansi.h:683
ztui::ansi::ColorStream::content
std::string content() const
Content of a non-empty buffered stream or empty.
Definition ansi.h:811
ztui::ansi::ColorStream::hasStream
bool hasStream() const
Direct or non-empty buffer.
Definition ansi.h:789
ztui::ansi::ColorStream::operator<<
ColorStream & operator<<(Color color_r)
Printing a Color (also via enum) updates the streams Color.
Definition ansi.h:752
ztui::ansi::ColorStream::color
Color color() const
Return streams Color.
Definition ansi.h:734
ztui::ansi::ColorStream::~ColorStream
~ColorStream()
Definition ansi.h:706
ztui::ansi::ColorStream::_color
Color _color
Definition ansi.h:822
ztui::ansi::ColorStream::operator<<
ColorStream & operator<<(const ColorString &val_r)
Printing a ColorString using his Color.
Definition ansi.h:758
ztui::ansi::ColorStream::_bufferP
std::unique_ptr< std::ostringstream > _bufferP
Definition ansi.h:821
ztui::ansi::ColorStream::operator=
ColorStream & operator=(Color color_r)
Change the streams Color.
Definition ansi.h:715
ztui::ansi::ColorStream::ColorStream
ColorStream(std::ostream &direct_r, Color color_r)
Ctor directly printing to a std::ostream in Color.
Definition ansi.h:693
ztui::ansi::ColorStream::operator<<
ColorStream & operator<<(std::ostream &(*omanip)(std::ostream &))
Definition ansi.h:775
ztui::ansi::ColorStream::operator<<
ColorStream & operator<<(const Tp_ &val_r)
All other types are printed via std::ostream.
Definition ansi.h:771
ztui::ansi::ColorStream::operator<<
friend std::ostream & operator<<(std::ostream &str, const ColorStream &obj)
relates: ColorStream Print colored on ostream
Definition ansi.h:780
ztui::ansi::ColorStream::operator=
ColorStream & operator=(const ColorStream &)=delete
ztui::ansi::ColorStream::hasContent
bool hasContent() const
Non-empty buffer (implies direct).
Definition ansi.h:807
ztui::ansi::ColorStream::operator=
ColorStream & operator=(ColorStream &&)=default
ztui::ansi::ColorStream::ColorStream
ColorStream()
Default Ctor (Color::Default).
Definition ansi.h:679
ztui::ansi::ColorStream::_directP
std::unique_ptr< std::ostream, nullDeleter > _directP
Definition ansi.h:820
ztui::ansi::ColorStream::ColorStream
ColorStream(const ColorStream &)=delete
non copyable
ztui::ansi::ColorStream::operator<=
ColorStream & operator<=(Color color_r)
Update the streams Color.
Definition ansi.h:724
ztui::ansi::ColorStream::ColorStream
ColorStream(ColorStream &&)=default
movable
ztui::ansi::ColorString
Colored string if do_colors.
Definition ansi.h:497
ztui::ansi::ColorString::operator()
ColorString operator()(Color color_r) const
Return a copy with different color.
Definition ansi.h:580
ztui::ansi::ColorString::color
Color color() const
Return strings Color.
Definition ansi.h:585
ztui::ansi::ColorString::operator=
ColorString & operator=(const std::string &str_r)
Assign new string.
Definition ansi.h:543
ztui::ansi::ColorString::ColorString
ColorString(Color color_r)
Ctor from color.
Definition ansi.h:504
ztui::ansi::ColorString::empty
bool empty() const
Whether the underlying string is empty.
Definition ansi.h:590
ztui::ansi::ColorString::operator=
ColorString & operator=(Color color_r)
Assign Color.
Definition ansi.h:572
ztui::ansi::ColorString::ColorString
ColorString(std::string &&str_r)
Definition ansi.h:514
ztui::ansi::ColorString::_color
Color _color
Definition ansi.h:639
ztui::ansi::ColorString::str
std::string str(Color color_r) const
Return the string rendered in a differernt color if do_colors.
Definition ansi.h:605
ztui::ansi::ColorString::plainstr
const std::string & plainstr() const
Return the underlying plain string.
Definition ansi.h:622
ztui::ansi::ColorString::operator=
ColorString & operator=(std::string &&str_r)
Definition ansi.h:546
ztui::ansi::ColorString::ColorString
ColorString()
Definition ansi.h:499
ztui::ansi::ColorString::operator*
const std::string & operator*() const
Access the underlying plain string via operator*.
Definition ansi.h:630
ztui::ansi::ColorString::plainstr
std::string & plainstr()
Return the underlying plain string.
Definition ansi.h:626
ztui::ansi::ColorString::operator<<
ColorString & operator<<(const ColorString &rhs)
Append a \Ref ColorString.
Definition ansi.h:563
ztui::ansi::ColorString::size
std::string::size_type size() const
Size of the underlying string.
Definition ansi.h:594
ztui::ansi::ColorString::str
std::string str() const
Return the colored string if do_colors.
Definition ansi.h:598
ztui::ansi::ColorString::operator*
std::string & operator*()
Access the underlying plain string via operator*.
Definition ansi.h:634
ztui::ansi::ColorString::_str
std::string _str
Definition ansi.h:638
ztui::ansi::ColorString::ColorString
ColorString(const std::string &str_r, Color color_r)
Ctor from string and color.
Definition ansi.h:520
ztui::ansi::ColorString::operator<=
ColorString & operator<=(Color color_r)
Update Color.
Definition ansi.h:576
ztui::ansi::ColorString::ColorString
ColorString(Color color_r, const std::string &str_r)
Ctor from color and string.
Definition ansi.h:531
ztui::ansi::ColorString::operator<<
ColorString & operator<<(const std::string &str_r)
Append a string.
Definition ansi.h:567
ztui::ansi::ColorString::ColorString
ColorString(std::string &&str_r, Color color_r)
Definition ansi.h:525
ztui::ansi::ColorString::asString
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:601
ztui::ansi::ColorString::ColorString
ColorString(Color color_r, std::string &&str_r)
Definition ansi.h:536
ztui::ansi::ColorString::ColorString
ColorString(const std::string &str_r)
Ctor from string.
Definition ansi.h:509
ztui::ansi::Color
Various ways to define ansi SGR sequences.
Definition ansi.h:173
ztui::ansi::Color::Color
Color(CCC_ &&color_r)
Custom ctor from ColorTraits enabled type.
Definition ansi.h:259
ztui::ansi::Color::Color
Color(Constant color_r, Bg bg_r=Bg::Default)
Color constant combined with background (Bg::Default).
Definition ansi.h:230
ztui::ansi::Color::Color
Color()
Default ctor: terminal default color.
Definition ansi.h:209
ztui::ansi::Color::Bg
Bg
Backgroud colors.
Definition ansi.h:185
ztui::ansi::Color::Bg::Cyan
@ Cyan
Definition ansi.h:185
ztui::ansi::Color::Bg::White
@ White
Definition ansi.h:185
ztui::ansi::Color::Bg::Yellow
@ Yellow
Definition ansi.h:185
ztui::ansi::Color::Bg::Unchanged
@ Unchanged
Definition ansi.h:185
ztui::ansi::Color::Bg::Default
@ Default
Definition ansi.h:185
ztui::ansi::Color::Bg::Blue
@ Blue
Definition ansi.h:185
ztui::ansi::Color::Bg::Magenta
@ Magenta
Definition ansi.h:185
ztui::ansi::Color::Bg::Green
@ Green
Definition ansi.h:185
ztui::ansi::Color::Bg::Black
@ Black
Definition ansi.h:185
ztui::ansi::Color::Bg::Red
@ Red
Definition ansi.h:185
ztui::ansi::Color::fg
Color & fg(Fg fg_r)
Definition ansi.h:349
ztui::ansi::Color::operator!=
friend bool operator!=(Color lhs, Color rhs)
relates: Color
Definition ansi.h:376
ztui::ansi::Color::debugstr
std::string debugstr() const
The colors SGRsequence human readable.
Definition ansi.h:367
ztui::ansi::Color::bg
Color & bg(Bg bg_r)
Definition ansi.h:355
ztui::ansi::Color::operator<
Color operator<(Color::Fg rhs) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:331
ztui::ansi::Color::_comp
union ztui::ansi::Color::Comp _comp
ztui::ansi::Color::Color
Color(UidType)
ctor nocolor, all Unchanged, uid 0
Definition ansi.h:447
ztui::ansi::Color::Color
Color(Fg fg_r, Bg bg_r=Bg::Unchanged)
Definition ansi.h:221
ztui::ansi::Color::operator==
friend bool operator==(Color lhs, Color rhs)
relates: Color
Definition ansi.h:372
ztui::ansi::Color::nocolor
static Color nocolor()
Leave everything unchanged.
Definition ansi.h:265
ztui::ansi::Color::bg
Bg bg() const
Definition ansi.h:352
ztui::ansi::Color::Color
Color(Attr attr_r, Bg bg_r)
Definition ansi.h:217
ztui::ansi::Color::fg
Fg fg() const
Definition ansi.h:346
ztui::ansi::Color::operator<
Color operator<(Color::Bg rhs) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:334
ztui::ansi::Color::SGRReset
static const std::string & SGRReset()
ANSI SGR sesquence to reset all attributes.
Definition ansi.h:291
ztui::ansi::Color::Constant
Constant
Predefined (foregreound) color contants Intentionally not an enum class, so it can be used as Color::...
Definition ansi.h:195
ztui::ansi::Color::Black
@ Black
Definition ansi.h:196
ztui::ansi::Color::BrightDefault
@ BrightDefault
Definition ansi.h:204
ztui::ansi::Color::Green
@ Green
Definition ansi.h:198
ztui::ansi::Color::BrightRed
@ BrightRed
Definition ansi.h:197
ztui::ansi::Color::Magenta
@ Magenta
Definition ansi.h:201
ztui::ansi::Color::BrightYellow
@ BrightYellow
Definition ansi.h:199
ztui::ansi::Color::White
@ White
Definition ansi.h:203
ztui::ansi::Color::Red
@ Red
Definition ansi.h:197
ztui::ansi::Color::BrightBlack
@ BrightBlack
Definition ansi.h:196
ztui::ansi::Color::BrightGreen
@ BrightGreen
Definition ansi.h:198
ztui::ansi::Color::Yellow
@ Yellow
Definition ansi.h:199
ztui::ansi::Color::BrightWhite
@ BrightWhite
Definition ansi.h:203
ztui::ansi::Color::Blue
@ Blue
Definition ansi.h:200
ztui::ansi::Color::Default
@ Default
Definition ansi.h:204
ztui::ansi::Color::Cyan
@ Cyan
Definition ansi.h:202
ztui::ansi::Color::BrightMagenta
@ BrightMagenta
Definition ansi.h:201
ztui::ansi::Color::BrightCyan
@ BrightCyan
Definition ansi.h:202
ztui::ansi::Color::BrightBlue
@ BrightBlue
Definition ansi.h:200
ztui::ansi::Color::attr
Color & attr(Attr attr_r)
Definition ansi.h:343
ztui::ansi::Color::Color
Color(Bg bg_r)
Definition ansi.h:225
ztui::ansi::Color::UidType
std::uint32_t UidType
Color unique id type.
Definition ansi.h:188
ztui::ansi::Color::uid
UidType uid() const
Each color has a unique numeric id.
Definition ansi.h:359
ztui::ansi::Color::operator<=
Color & operator<=(Color rhs)
Update Color (assign components which are not Unchanged in rhs ).
Definition ansi.h:305
ztui::ansi::Color::str
const std::string & str() const
The colors SGRsequence if do_colors is true.
Definition ansi.h:363
ztui::ansi::Color::genSGR
static std::string & genSGR(Color color_r)
Return a colors SGRsequence if do_colors retruns true.
Definition ansi.h:381
ztui::ansi::Color::attr
Attr attr() const
Definition ansi.h:340
ztui::ansi::Color::Fg
Fg
Foreground colors.
Definition ansi.h:181
ztui::ansi::Color::Fg::Cyan
@ Cyan
Definition ansi.h:181
ztui::ansi::Color::Fg::White
@ White
Definition ansi.h:181
ztui::ansi::Color::Fg::Yellow
@ Yellow
Definition ansi.h:181
ztui::ansi::Color::Fg::Unchanged
@ Unchanged
Definition ansi.h:181
ztui::ansi::Color::Fg::Default
@ Default
Definition ansi.h:181
ztui::ansi::Color::Fg::Blue
@ Blue
Definition ansi.h:181
ztui::ansi::Color::Fg::Magenta
@ Magenta
Definition ansi.h:181
ztui::ansi::Color::Fg::Green
@ Green
Definition ansi.h:181
ztui::ansi::Color::Fg::Black
@ Black
Definition ansi.h:181
ztui::ansi::Color::Fg::Red
@ Red
Definition ansi.h:181
ztui::ansi::Color::operator<=
Color & operator<=(Color::Bg rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:319
ztui::ansi::Color::operator<=
Color & operator<=(Color::Fg rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:316
ztui::ansi::Color::operator<=
Color & operator<=(Color::Attr rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:313
ztui::ansi::Color::Color
Color(Attr attr_r, Fg fg_r=Fg::Unchanged, Bg bg_r=Bg::Unchanged)
Definition ansi.h:213
ztui::ansi::Color::Attr
Attr
Color attributes.
Definition ansi.h:177
ztui::ansi::Color::Attr::Bright
@ Bright
Definition ansi.h:177
ztui::ansi::Color::Attr::Unchanged
@ Unchanged
Definition ansi.h:177
ztui::ansi::Color::Attr::Reverse
@ Reverse
Definition ansi.h:177
ztui::ansi::Color::Attr::Normal
@ Normal
Definition ansi.h:177
ztui::ansi::Color::operator<
Color operator<(Color rhs) const
Return updated color.
Definition ansi.h:325
ztui::ansi::Color::operator<
Color operator<(Color::Attr rhs) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:328
ztui::ansi::tty::EscapeSequence
ANSI Escape sequences and their fallback if no tty.
Definition ansi.h:55
ztui::ansi::tty::EscapeSequence::_seq
const char * _seq
Definition ansi.h:74
ztui::ansi::tty::EscapeSequence::_fbck
const char * _fbck
Definition ansi.h:75
ztui::ansi::tty::EscapeSequence::EscapeSequence
EscapeSequence(const char *ansi_r, const char *fallback_r="")
Definition ansi.h:57
ztui::ansi::tty::EscapeSequence::str
const char * str() const
Definition ansi.h:62
std
Definition ansi.h:855
std::operator<<
ostream & operator<<(ostream &str, CCC_ &&color_r)
relates: ansi::Color Stream oputput for ColorTraits enabled types Defined in namespace 'std' because ...
Definition ansi.h:860
std::enable_if_t
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
str
String related utilities and Regular expression matching.
ztui::ansi::tty
Definition ansi.h:49
ztui::ansi::tty::cursorUP
const EscapeSequence cursorUP
Cursor up 1 line.
ztui::ansi::tty::clearLN
const EscapeSequence clearLN
Clear entire line.
ztui::ansi::tty::cursorDOWN
const EscapeSequence cursorDOWN
Cursor down 1 line.
ztui::ansi::tty::cursorRIGHT
const EscapeSequence cursorRIGHT
Cursor right 1 char.
ztui::ansi::tty::operator<<
std::ostream & operator<<(std::ostream &str, const EscapeSequence &obj)
relates: EscapeSequence stream output
Definition ansi.h:79
ztui::ansi::tty::cursorLEFT
const EscapeSequence cursorLEFT
Cursor left 1 char.
ztui::ansi
Definition ansi.h:46
ztui::ansi::EnableIfCustomColorCtor
std::enable_if_t< ansi::ColorTraits< std::decay_t< CCC_ > >::customColorCtor > EnableIfCustomColorCtor
relates: ColorTraits<Tp_> SFINAE: hide template signatures unless enum is enabled in ColorTraits
Definition ansi.h:152
ztui::ansi::operator<<
std::ostream & operator<<(std::ostream &str, Color obj)
relates: Color Print the colors SGRsequence if do_colors is true
Definition ansi.h:477
ztui::ansi::DisableIfCustomColorCtor
std::enable_if_t< !ansi::ColorTraits< std::decay_t< CCC_ > >::customColorCtor > DisableIfCustomColorCtor
relates: ColorTraits<Tp_> SFINAE: hide template signatures unless enum is enabled in ColorTraits
Definition ansi.h:156
ztui
Definition application.cc:13
ztui::mayUseANSIEscapes
bool mayUseANSIEscapes()
Simple check whether stdout is a (not dumb) tty.
Definition colors.cc:37
ztui::customColorCtor
ansi::Color customColorCtor(ColorContext ctxt_r)
relates: ColorContext map to ansi::Color
Definition colors.cc:125
ztui::do_ttyout
bool do_ttyout()
True unless output is a dumb tty or file.
Definition colors.cc:27
ztui::hasANSIColor
bool hasANSIColor()
Simple check whether stdout can handle colors.
Definition colors.cc:53
ztui::do_colors
bool do_colors()
If output is done in colors (depends on config).
Definition colors.cc:32
zypp::str::replaceAll
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition String.cc:333
zypp::ResolverFocus::Default
@ Default
Request the standard behavior (as defined in zypp.conf or 'Job').
Definition ResolverFocus.h:25
zypp::operator<
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition Capability.h:317
zypp::fromString
bool fromString(const std::string &val_r, ResolverFocus &ret_r)
relates: ResolverFocus Conversion from string (enumerator name, case insensitive, empty string is Def...
Definition ResolverFocus.cc:39
zypp::operator<=
bool operator<=(const IdString &lhs, const IdString &rhs)
relates: IdString LessEqual
Definition IdString.h:207
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
ztui::ColorStream::nullDeleter::operator()
void operator()(void const *) const
Definition ansi.h:675
ztui::ansi::ColorStream::nullDeleter
Definition ansi.h:675
ztui::ansi::ColorTraits< Color::Constant >::customColorCtor
@ customColorCtor
Definition ansi.h:470
ztui::ansi::ColorTraits
Definition ansi.h:147
ztui::ansi::ColorTraits::customColorCtor
@ customColorCtor
Definition ansi.h:147
ztui::ansi::Color::Comp::[struct].__unnamed0__::attr
Color::Attr attr
ztui::ansi::Color::Comp::[struct].__unnamed0__::_f
std::uint8_t _f
ztui::ansi::Color::Comp::[struct].__unnamed0__::bg
Color::Bg bg
ztui::ansi::Color::Comp::[struct].__unnamed0__::fg
Color::Fg fg
ztui::ansi::Color::Comp::uid
UidType uid
Definition ansi.h:464
ztui::ansi::Color::Comp::Comp
Comp(Attr attr_r, Fg fg_r, Bg bg_r)
Definition ansi.h:454
ztui::ansi::Color::Comp::Comp
Comp()
Definition ansi.h:450