libzypp 17.37.10

colors.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_COLORS_H_
15#define ZYPP_TUI_UTILS_COLORS_H_
16
17#include <iostream>
18#include <string>
19
20#include "ansi.h"
21
22 namespace ztui {
23
27 bool do_ttyout();
28
30 bool do_colors();
31
33
34 enum class ColorContext
35{
36 DEFAULT,
37
38 RESULT,
39 MSG_STATUS,
40 MSG_ERROR,
41 MSG_WARNING,
42 PROMPT,
43 PROMPT_OPTION,
44 POSITIVE,
45 CHANGE,
46 NEGATIVE,
47 HIGHLIGHT,
48 LOWLIGHT,
49
50 OSDEBUG
51};
52
54ansi::Color customColorCtor( ColorContext ctxt_r );
55
56 namespace ansi
57{
58 // Enable using ColorContext as ansi::SGRSequence
59 template<>
60 struct ColorTraits<ztui::ColorContext>
61 { enum { customColorCtor = true }; };
62}
63
64// ColorString types
65 template <ColorContext _ctxt>
66 struct CCString : public ColorString
67{
68 CCString() : ColorString( _ctxt ) {}
69 explicit CCString( const std::string & str_r ) : ColorString( _ctxt, str_r ) {}
70 explicit CCString( std::string && str_r ) : ColorString( _ctxt, std::move(str_r) ) {}
71};
72
73 template <ColorContext _ctxt>
74 inline ansi::ColorStream & operator<<( ansi::ColorStream & cstr_r, const CCString<_ctxt> & cstring_r )
75{ return cstr_r << static_cast<const ColorString &>(cstring_r); }
76
77 using DEFAULTString = CCString<ColorContext::DEFAULT>;
78
79 using MSG_STATUSString = CCString<ColorContext::MSG_STATUS>;
80 using MSG_ERRORString = CCString<ColorContext::MSG_ERROR>;
81 using MSG_WARNINGString = CCString<ColorContext::MSG_WARNING>;
82
83 using POSITIVEString = CCString<ColorContext::POSITIVE>;
84 using CHANGEString = CCString<ColorContext::CHANGE>;
85 using NEGATIVEString = CCString<ColorContext::NEGATIVE>;
86
87 using HIGHLIGHTString = CCString<ColorContext::HIGHLIGHT>;
88 using LOWLIGHTString = CCString<ColorContext::LOWLIGHT>;
89
90}
91
92#endif /* ZYPP_TUI_UTILS_COLORS_H_ */
ansi.h
ztui::ansi::ColorStream
Colored stream output if do_colors.
Definition ansi.h:674
ztui::ansi::ColorString::ColorString
ColorString()
Definition ansi.h:499
std
Definition Arch.h:364
ztui
Definition application.cc:13
ztui::LOWLIGHTString
CCString< ColorContext::LOWLIGHT > LOWLIGHTString
Definition colors.h:88
ztui::NEGATIVEString
CCString< ColorContext::NEGATIVE > NEGATIVEString
Definition colors.h:85
ztui::MSG_ERRORString
CCString< ColorContext::MSG_ERROR > MSG_ERRORString
Definition colors.h:80
ztui::MSG_WARNINGString
CCString< ColorContext::MSG_WARNING > MSG_WARNINGString
Definition colors.h:81
ztui::HIGHLIGHTString
CCString< ColorContext::HIGHLIGHT > HIGHLIGHTString
Definition colors.h:87
ztui::CHANGEString
CCString< ColorContext::CHANGE > CHANGEString
Definition colors.h:84
ztui::POSITIVEString
CCString< ColorContext::POSITIVE > POSITIVEString
Definition colors.h:83
ztui::customColorCtor
ansi::Color customColorCtor(ColorContext ctxt_r)
Definition colors.cc:125
ztui::ColorContext
ColorContext
Definition colors.h:35
ztui::ColorContext::MSG_WARNING
@ MSG_WARNING
Definition colors.h:41
ztui::ColorContext::PROMPT
@ PROMPT
Definition colors.h:42
ztui::ColorContext::CHANGE
@ CHANGE
Definition colors.h:45
ztui::ColorContext::NEGATIVE
@ NEGATIVE
Definition colors.h:46
ztui::ColorContext::HIGHLIGHT
@ HIGHLIGHT
Definition colors.h:47
ztui::ColorContext::DEFAULT
@ DEFAULT
Definition colors.h:36
ztui::ColorContext::MSG_ERROR
@ MSG_ERROR
Definition colors.h:40
ztui::ColorContext::OSDEBUG
@ OSDEBUG
Definition colors.h:50
ztui::ColorContext::RESULT
@ RESULT
Definition colors.h:38
ztui::ColorContext::POSITIVE
@ POSITIVE
Definition colors.h:44
ztui::ColorContext::LOWLIGHT
@ LOWLIGHT
Definition colors.h:48
ztui::ColorContext::PROMPT_OPTION
@ PROMPT_OPTION
Definition colors.h:43
ztui::ColorContext::MSG_STATUS
@ MSG_STATUS
Definition colors.h:39
ztui::do_ttyout
bool do_ttyout()
True unless output is a dumb tty or file.
Definition colors.cc:27
ztui::do_colors
bool do_colors()
If output is done in colors (depends on config)
Definition colors.cc:32
ztui::DEFAULTString
CCString< ColorContext::DEFAULT > DEFAULTString
Definition colors.h:77
ztui::MSG_STATUSString
CCString< ColorContext::MSG_STATUS > MSG_STATUSString
Definition colors.h:79
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
ztui::CCString
Definition colors.h:67
ztui::CCString::CCString
CCString(const std::string &str_r)
Definition colors.h:69
ztui::CCString::CCString
CCString(std::string &&str_r)
Definition colors.h:70
ztui::CCString::CCString
CCString()
Definition colors.h:68
ztui::ansi::ColorTraits< ztui::ColorContext >::customColorCtor
@ customColorCtor
Definition colors.h:61
ztui::ansi::ColorTraits
Definition ansi.h:147