libzypp 17.37.17
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/base/String.h>
26
27
28namespace ztui {
29
33bool do_ttyout(); // implemented in colors.cc
34
36bool do_colors(); // implemented in colors.cc
37
40
42bool hasANSIColor();
43
45namespace ansi
46{
48 namespace tty
49 {
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_>
147 { enum { customColorCtor = false }; };
148
149 // enabled via ctor Color::Constant -> Color
151 template <typename CCC_>
153
155 template <typename CCC_>
157
172 class Color
173 {
174 public:
176 enum class Attr : std::uint8_t
178
180 enum class Fg : std::uint8_t
182
184 enum class Bg : std::uint8_t
186
188 using UidType = std::uint32_t;
189
194 enum Constant : std::uint8_t
195 {
196 Black, BrightBlack, // BrightBlack = Darkgray
199 Yellow, BrightYellow, // Yellow = Brown on Standard VGA
203 White, BrightWhite, // White = Gray
205 };
206
207 public:
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:
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
314 { if ( rhs != Attr::Unchanged ) _comp.attr = rhs; return *this; }
315
317 { if ( rhs != Fg::Unchanged ) _comp.fg = rhs; return *this; }
318
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
329 { return Color(*this) <= rhs; }
330
332 { return Color(*this) <= rhs; }
333
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:
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
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 !
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
497 {
498 public:
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 //
564 { _str += rhs.str(); return *this; }
565
567 ColorString & operator<<( const std::string & str_r )
568 { _str += str_r; return *this; }
569
570 public:
573 { _color = color_r; return *this; }
574
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 {
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;
640 };
641
643 inline std::ostream & operator<<( std::ostream & str, const ColorString & obj )
644 { return str << obj.str(); }
645
674 {
675 struct nullDeleter { void operator() (void const *) const {}; };
676
677 public:
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;
705
707 { if ( _directP ) (*_directP) << Color::SGRReset(); }
708
710 explicit operator std::ostream &()
711 { return stream(); }
712
713 public:
716 {
717 _color = color_r;
718 if ( hasStream() )
719 stream() << _color;
720 return *this;
721 }
722
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:
753 { return operator<=( color_r ); }
754
759 { stream() << ( val_r.color() ? val_r.str() : val_r.str(_color) ) << _color; return *this; }
760
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;
823 };
824
825
826#undef ZYPPER_TRACE_SGR
827} // namespace ansi
828
829
830// Drag them into this namespace:
833
835template<class Tp_>
836inline ansi::ColorStream operator<<( ansi::Color color_r, Tp_ && val_r )
837{ return std::move( ansi::ColorStream( color_r ) << std::forward<Tp_>(val_r) ); }
839inline 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_> >
844inline 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) ); }
847template<class CCC_, typename = ansi::EnableIfCustomColorCtor<CCC_> >
848inline 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
854namespace std
855{
859template<class CCC_, typename = ztui::ansi::EnableIfCustomColorCtor<CCC_>>
860inline ostream & operator<<( ostream & str, CCC_ && color_r )
861{ return str << ztui::ansi::Color( forward<CCC_>(color_r) ); }
862} // namespace std
863
864#endif // ZYPP_TUI_UTILS_ANSI_H
#define ESC
Definition ansi.h:98
Colored stream output if do_colors.
Definition ansi.h:674
ColorStream & operator<<(const ColorStream &val_r)
Printing another ColorStream using his Color.
Definition ansi.h:762
std::ostream & stream() const
Reference to the underlying ostream (direct or auto-created buffer)
Definition ansi.h:793
ColorStream(std::ostream &direct_r)
Ctor directly printing to a std::ostream (Color::Default)
Definition ansi.h:688
std::string str() const
Return a buffered streams content as (colored) string.
Definition ansi.h:739
ColorStream(Color color_r)
Ctor taking a Color.
Definition ansi.h:683
std::string content() const
Content of a non-empty buffered stream or empty.
Definition ansi.h:811
bool hasStream() const
Direct or non-empty buffer.
Definition ansi.h:789
ColorStream & operator<<(Color color_r)
Printing a Color (also via enum) updates the streams Color.
Definition ansi.h:752
Color color() const
Return streams Color.
Definition ansi.h:734
ColorStream & operator<<(const ColorString &val_r)
Printing a ColorString using his Color.
Definition ansi.h:758
std::unique_ptr< std::ostringstream > _bufferP
Definition ansi.h:821
ColorStream & operator=(Color color_r)
Change the streams Color.
Definition ansi.h:715
ColorStream(std::ostream &direct_r, Color color_r)
Ctor directly printing to a std::ostream in Color.
Definition ansi.h:693
ColorStream & operator<<(std::ostream &(*omanip)(std::ostream &))
Definition ansi.h:775
ColorStream & operator<<(const Tp_ &val_r)
All other types are printed via std::ostream.
Definition ansi.h:771
friend std::ostream & operator<<(std::ostream &str, const ColorStream &obj)
Print colored on ostream.
Definition ansi.h:780
ColorStream & operator=(const ColorStream &)=delete
bool hasContent() const
Non-empty buffer (implies direct)
Definition ansi.h:807
ColorStream & operator=(ColorStream &&)=default
ColorStream()
Default Ctor (Color::Default)
Definition ansi.h:679
std::unique_ptr< std::ostream, nullDeleter > _directP
Definition ansi.h:820
ColorStream(const ColorStream &)=delete
non copyable
ColorStream & operator<=(Color color_r)
Update the streams Color.
Definition ansi.h:724
ColorStream(ColorStream &&)=default
movable
Colored string if do_colors.
Definition ansi.h:497
ColorString operator()(Color color_r) const
Return a copy with different color.
Definition ansi.h:580
Color color() const
Return strings Color.
Definition ansi.h:585
ColorString & operator=(const std::string &str_r)
Assign new string.
Definition ansi.h:543
ColorString(Color color_r)
Ctor from color.
Definition ansi.h:504
bool empty() const
Whether the underlying string is empty.
Definition ansi.h:590
ColorString & operator=(Color color_r)
Assign Color.
Definition ansi.h:572
ColorString(std::string &&str_r)
Definition ansi.h:514
std::string str(Color color_r) const
Return the string rendered in a differernt color if do_colors.
Definition ansi.h:605
const std::string & plainstr() const
Return the underlying plain string.
Definition ansi.h:622
ColorString & operator=(std::string &&str_r)
Definition ansi.h:546
std::ostream & operator<<(std::ostream &str, const ColorString &obj)
Print colored on ostream.
Definition ansi.h:643
const std::string & operator*() const
Access the underlying plain string via operator*.
Definition ansi.h:630
std::string & plainstr()
Return the underlying plain string.
Definition ansi.h:626
ColorString & operator<<(const ColorString &rhs)
Append a \Ref ColorString.
Definition ansi.h:563
std::string::size_type size() const
Size of the underlying string.
Definition ansi.h:594
std::string str() const
Return the colored string if do_colors.
Definition ansi.h:598
std::string & operator*()
Access the underlying plain string via operator*.
Definition ansi.h:634
std::string _str
Definition ansi.h:638
ColorString(const std::string &str_r, Color color_r)
Ctor from string and color.
Definition ansi.h:520
ColorString & operator<=(Color color_r)
Update Color.
Definition ansi.h:576
ColorString(Color color_r, const std::string &str_r)
Ctor from color and string.
Definition ansi.h:531
ColorString & operator<<(const std::string &str_r)
Append a string.
Definition ansi.h:567
ColorString(std::string &&str_r, Color color_r)
Definition ansi.h:525
std::string asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ansi.h:601
ColorString(Color color_r, std::string &&str_r)
Definition ansi.h:536
ColorString(const std::string &str_r)
Ctor from string.
Definition ansi.h:509
Various ways to define ansi SGR sequences.
Definition ansi.h:173
Color(CCC_ &&color_r)
Custom ctor from ColorTraits enabled type.
Definition ansi.h:259
Color(Constant color_r, Bg bg_r=Bg::Default)
Color constant combined with background (Bg::Default)
Definition ansi.h:230
Color()
Default ctor: terminal default color.
Definition ansi.h:209
Bg
Backgroud colors.
Definition ansi.h:185
Color & fg(Fg fg_r)
Definition ansi.h:349
friend bool operator!=(Color lhs, Color rhs)
Definition ansi.h:376
std::string debugstr() const
The colors SGRsequence human readable.
Definition ansi.h:367
Color & bg(Bg bg_r)
Definition ansi.h:355
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
union ztui::ansi::Color::Comp _comp
static Color fromString(const std::string &colorName)
Definition colors.cc:68
Color(UidType)
ctor nocolor, all Unchanged, uid 0
Definition ansi.h:447
Color(Fg fg_r, Bg bg_r=Bg::Unchanged)
Definition ansi.h:221
friend bool operator==(Color lhs, Color rhs)
Definition ansi.h:372
static Color nocolor()
Leave everything unchanged.
Definition ansi.h:265
Bg bg() const
Definition ansi.h:352
Color(Attr attr_r, Bg bg_r)
Definition ansi.h:217
Fg fg() const
Definition ansi.h:346
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
static const std::string & SGRReset()
ANSI SGR sesquence to reset all attributes.
Definition ansi.h:291
Constant
Predefined (foregreound) color contants Intentionally not an enum class, so it can be used as Color::...
Definition ansi.h:195
Color & attr(Attr attr_r)
Definition ansi.h:343
Color(Bg bg_r)
Definition ansi.h:225
std::uint32_t UidType
Color unique id type.
Definition ansi.h:188
UidType uid() const
Each color has a unique numeric id.
Definition ansi.h:359
Color & operator<=(Color rhs)
Update Color (assign components which are not Unchanged in rhs )
Definition ansi.h:305
const std::string & str() const
The colors SGRsequence if do_colors is true.
Definition ansi.h:363
static std::string & genSGR(Color color_r)
Return a colors SGRsequence if do_colors retruns true.
Definition ansi.h:381
Attr attr() const
Definition ansi.h:340
Fg
Foreground colors.
Definition ansi.h:181
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
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
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
Color(Attr attr_r, Fg fg_r=Fg::Unchanged, Bg bg_r=Bg::Unchanged)
Definition ansi.h:213
Attr
Color attributes.
Definition ansi.h:177
Color operator<(Color rhs) const
Return updated color.
Definition ansi.h:325
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
std::ostream & operator<<(std::ostream &str, Color obj)
Print the colors SGRsequence if do_colors is true.
Definition ansi.h:477
ANSI Escape sequences and their fallback if no tty.
Definition ansi.h:55
std::ostream & operator<<(std::ostream &str, const EscapeSequence &obj)
stream output
Definition ansi.h:79
EscapeSequence(const char *ansi_r, const char *fallback_r="")
Definition ansi.h:57
const char * str() const
Definition ansi.h:62
Definition Arch.h:364
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
std::ostream & operator<<(std::ostream &str, const zypp::shared_ptr< void > &obj)
Definition PtrTypes.h:141
String related utilities and Regular expression matching.
const EscapeSequence cursorUP
Cursor up 1 line.
const EscapeSequence clearLN
Clear entire line.
const EscapeSequence cursorDOWN
Cursor down 1 line.
const EscapeSequence cursorRIGHT
Cursor right 1 char.
const EscapeSequence cursorLEFT
Cursor left 1 char.
bool mayUseANSIEscapes()
Simple check whether stdout is a (not dumb) tty.
Definition colors.cc:37
ansi::Color customColorCtor(ColorContext ctxt_r)
Definition colors.cc:125
bool do_ttyout()
True unless output is a dumb tty or file.
Definition colors.cc:27
bool hasANSIColor()
Simple check whether stdout can handle colors.
Definition colors.cc:53
bool do_colors()
If output is done in colors (depends on config)
Definition colors.cc:32
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
@ Default
Request the standard behavior (as defined in zypp.conf or 'Job')
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
void operator()(void const *) const
Definition ansi.h:675
std::enable_if_t< !ansi::ColorTraits< std::decay_t< CCC_ > >::customColorCtor > DisableIfCustomColorCtor
<Tp_> SFINAE: hide template signatures unless enum is enabled in ColorTraits
Definition ansi.h:156
std::enable_if_t< ansi::ColorTraits< std::decay_t< CCC_ > >::customColorCtor > EnableIfCustomColorCtor
<Tp_> SFINAE: hide template signatures unless enum is enabled in ColorTraits
Definition ansi.h:152
Comp(Attr attr_r, Fg fg_r, Bg bg_r)
Definition ansi.h:454
std::uint8_t _f
Definition ansi.h:462
Color::Attr attr
Definition ansi.h:459