libzypp 17.34.0
Out.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 OUT_H_
15#define OUT_H_
16
17#include <string>
18#include <sstream>
19#include <optional>
20
21#include <zypp-core/base/Xml.h>
26#include <utility>
27#include <zypp-core/base/DefaultIntegral>
28#include <zypp-core/base/DtorReset>
30#include <zypp-core/Url.h>
31#include <zypp-core/TriBool.h>
32#include <zypp-core/ui/ProgressData>
34
35#include <zypp-tui/utils/text.h>
38#include <zypp-tui/Table.h>
39#include <zypp-tui/output/PromptOptions>
40
41namespace ztui {
42
43class Application;
44
47
48namespace text
49{
50 // translator: usually followed by a ' ' and some explanatory text
51 inline ColorString tagNote() { return HIGHLIGHTString(_("Note:") ); }
52 // translator: usually followed by a ' ' and some explanatory text
53 inline ColorString tagWarning() { return MSG_WARNINGString(_("Warning:") ); }
54 // translator: usually followed by a ' ' and some explanatory text
55 inline ColorString tagError() { return MSG_ERRORString(_("Error:") ); }
56
57 inline const char * qContinue() { return _("Continue?"); }
58
59
61 template <class Tltext, class Trtext>
62 inline std::string join( const Tltext & ltext, const Trtext & rtext, const char * sep = " " )
63 { std::string ret( zypp::str::asString(ltext) ); ret += sep; ret += zypp::str::asString(rtext); return ret; }
64
66 inline bool endsOnWS( const std::string & str_r )
67 {
68 bool ret = false;
69 if ( !str_r.empty() )
70 { int l = *str_r.rbegin(); if ( ::strchr( " \n\t", l ) ) ret = true; }
71 return ret;
72 }
73
74 inline const char * optBlankAfter( const std::string & str_r )
75 { return( endsOnWS( str_r ) ? "" : " " ); }
76}
77
78namespace out
79{
80 static constexpr unsigned termwidthUnlimited = 0u;
81 unsigned defaultTermwidth(); // Zypper::instance().out().termwidth()
82} // namespace out
83
84namespace out
85{
92 {
93 template <class TFormater> struct Writer;
94
95 ListLayout( bool singleline_r, bool wrapline_r, bool gaped_r, unsigned indent_r )
98 , _gaped( gaped_r )
99 , _indent( indent_r )
100 {}
103 bool _gaped;
104 unsigned _indent;
105 };
106
107 namespace detail
108 {
109 template <bool singleline_, bool wrapline_, bool gaped_, unsigned indent_>
111 }
112
119
125 {
126 template <class TFormater> struct Writer;
127 };
128
130
131 // Either specialize per Type or define a custom Formater:
132
134 template <class Tp>
135 std::string asXmlListElement( const Tp & val_r );
136 inline std::string asXmlListElement( const std::string & val_r ){ return val_r; }
137 inline std::string asXmlListElement( const char * val_r ) { return val_r; }
138
140 template <class Tp>
141 std::string asListElement( const Tp & val_r );
142 inline std::string asListElement( const std::string & val_r ) { return val_r; }
143 inline std::string asListElement( const char * val_r ) { return val_r; }
144
146 template <class Tp = void>
148
149 template <>
151 { return TableHeader(); }
152
154 template <class Tp>
155 TableRow asTableRow( const Tp & val_r );
156
162 {
163 template <class Tp>
164 std::string xmlListElement( const Tp & val_r ) const//< XML representation of element
165 { return asXmlListElement( val_r ); }
166 };
167
172 struct ListFormater : public XmlFormater
173 {
174 using NormalLayout = DefaultListLayout; //< ListLayout for NORMAL lists
175
176 template <class Tp>
177 std::string listElement( const Tp & val_r ) const //< NORMAL representation of list element
178 { return asListElement( val_r ); }
179 };
180
186 {
187 using NormalLayout = DefaultTableLayout; //< NORMAL layout as Table
188
189 TableHeader header() const //< TableHeader for TableRow representation
190 { return asTableHeader<>(); }
191
192 template <class Tp> //< Representation as TableRow
193 TableRow row( const Tp & val_r ) const
194 { return asTableRow( val_r ); }
195 };
196
201
202 template <class TFormater>
204 {
205 using NormalLayout = XmlListLayout; //< Layout as XML list
206
207 template <class Tp>
208 std::string listElement( const Tp & val_r ) const //< use TFormater::asXmlListElement
209 { return _formater.xmlListElement( val_r ); }
210
214 private:
216 };
217
218} // namespace out
220
222namespace out
223{
227 // TODO: wrap singlelines; support for attributed text;
229 template <class TFormater>
231 {
233
234 Writer( std::ostream & str_r, const ListLayout & layout_r, const TFormater & formater_r )
235 : _str( str_r )
236 , _layout( layout_r )
239 , _indent( _layout._indent, ' ' )
240 {}
241
243 { if ( !_layout._singleline && _cpos ) _str << std::endl; }
244
245 template <class Tp>
246 void operator<<( Tp && val_r ) const
247 {
248 const std::string & element( _formater.listElement( std::forward<Tp>(val_r) ) );
249
250 if ( _layout._singleline )
251 {
252 if ( _layout._gaped )
253 _str << std::endl;
254 _str << _indent << element << std::endl;
255 }
256 else
257 {
258 if ( _cpos != 0 && ! fitsOnLine( 1/*' '*/ + element.size() ) )
259 endLine();
260
261 if ( _cpos == 0 )
262 {
263 if ( !_indent.empty() )
265 }
266 else
267 printAndCount( " " );
268
270 }
271 }
272
273 private:
274 bool fitsOnLine( unsigned size_r ) const
276
277 void printAndCount( const std::string & element_r ) const
278 { _cpos += element_r.size(); _str << element_r; }
279
280 void endLine() const
281 { _str << std::endl; _cpos = 0U; }
282
283 private:
284 std::ostream & _str;
287 const unsigned _linewidth;
288 const std::string _indent;
289 mutable unsigned _cpos = 0U;
290 };
291
296 template <class TFormater>
298 {
300
301 Writer( std::ostream & str_r, const TableLayout & layout_r, const TFormater & formater_r )
302 : _str( str_r )
303 , _layout( layout_r )
305 {}
306
308 {
309 if ( !_t.empty() )
310 {
311 _t.setHeader( _formater.header() );
312 _str << _t;
313 }
314 }
315
316 template <class Tp>
317 void operator<<( Tp && val_r ) const
318 { _t.add( _formater.row( std::forward<Tp>(val_r) ) ); }
319
320 private:
321 std::ostream & _str;
324 mutable Table _t;
325 };
326
327
329 template <class TContainer, class TFormater, class TLayout = typename TFormater::NormalLayout>
330 void writeContainer( std::ostream & str_r, const TContainer & container_r, const TFormater & formater_r, const TLayout & layout_r = TLayout() )
331 {
332 typedef typename TLayout::template Writer<TFormater> Writer;
333 Writer writer( str_r, layout_r, formater_r );
334 for ( auto && el : container_r )
335 writer << el;
336 }
337
339 template <class TContainer, class TFormater>
342
343} // namespace out
345
346// Too simple on small terminals as esc-sequences may get truncated.
347// A table like writer for attributed strings is desirable.
349{
351 {
352 SF_CRUSH = 1<<0, //< truncate lhs, then rhs
353 SF_SPLIT = 1<<1, //< split line across two
354 SF_EXPAND = 1<<2 //< expand short lines iff stdout is a tty
355 };
357
358 TermLine( SplitFlags flags_r, char exp_r ) : flagsHint( flags_r ), expHint( exp_r ) {}
359 TermLine( SplitFlags flags_r ) : flagsHint( flags_r ) {}
360 TermLine( char exp_r ) : expHint( exp_r ) {}
362
363 SplitFlags flagsHint; //< flags to use if not passed to \ref get
364 zypp::DefaultIntegral<char,' '> expHint; //< expand char to use if not passed to \ref get
365 zypp::DefaultIntegral<int,-1> percentHint; //< draw progress indicator in expanded space if in [0,100]
366
367 zypp::str::Str lhs; //< left side
368 zypp::str::Str rhs; //< right side
369
370
372 std::string get() const
373 { return std::string(lhs) + std::string(rhs); }
374
378 std::string get( unsigned width_r, SplitFlags flags_r, char exp_r ) const;
380 std::string get( unsigned width_r, SplitFlags flags_r ) const
381 { return get( width_r, flags_r, expHint ); }
383 std::string get( unsigned width_r, char exp_r ) const
384 { return get( width_r, flagsHint, exp_r ); }
386 std::string get( unsigned width_r ) const
387 { return get( width_r, flagsHint, expHint ); }
388};
389ZYPP_DECLARE_OPERATORS_FOR_FLAGS( TermLine::SplitFlags );
390
430{
431public:
433 typedef enum
434 {
435 QUIET = 0,
436 NORMAL = 1,
438 HIGH = 2,
439 DEBUG = 3
441
444 {
445 TYPE_NORMAL = 0x01<<0,
446 TYPE_XML = 0x01<<1
447 };
449
450 static constexpr Type TYPE_NONE = Type(0x00);
451 static constexpr Type TYPE_ALL = Type(0xff);
452
453 using PromptId = unsigned;
454
455protected:
459
460public:
461 virtual ~Out();
462
463protected:
468 {
470 Out & out() { return _out; }
471 private:
473 };
474
475public:
485 struct XmlNode : protected ParentOut
486 {
488
490 XmlNode( Out & out_r, const std::string & name_r, const std::initializer_list<Attr> & attrs_r = {} )
491 : ParentOut( out_r )
492 {
493 if ( out().typeXML() && ! name_r.empty() )
494 { _node.reset( new zypp::xmlout::Node( std::cout, name_r, attrs_r ) ); }
495 }
496
498 XmlNode( Out & out_r, const std::string & name_r, Attr attr_r )
499 : XmlNode( out_r, name_r, { std::move(attr_r) } )
500 {}
501
503 XmlNode( XmlNode && rhs ) noexcept : ParentOut( rhs ) { _node.swap( rhs._node ); }
504
505 private:
507 };
509
515 void xmlNode( const std::string & name_r, const std::initializer_list<XmlNode::Attr> & attrs_r = {} )
516 { if ( typeXML() ) { zypp::xmlout::node( std::cout, name_r, attrs_r ); } }
518 void xmlNode( const std::string & name_r, XmlNode::Attr attr_r )
519 { xmlNode( name_r, { std::move(attr_r) } ); }
520
524 struct TitleNode : public XmlNode
525 {
526 TitleNode( XmlNode && node_r, const std::string & title_r = "" )
527 : XmlNode( std::move(node_r) )
528 { if ( out().typeNORMAL() && ! title_r.empty() ) std::cout << title_r << std::endl; }
529 };
530
531private:
534 template <class TContainer, class TFormater>
535 void container( const std::string & nodeName_r, const std::string & title_r,
536 const TContainer & container_r, const TFormater & formater_r )
537 {
540 switch ( type() )
541 {
542 case TYPE_NORMAL:
543 writeContainer( std::cout, container_r, formater_r );
544 break;
545 case TYPE_XML:
547 break;
548 }
549 }
550
551public:
554 template <class TContainer, class TFormater = out::ListFormater>
555 void list( const std::string & nodeName_r, const std::string & title_r,
556 const TContainer & container_r, const TFormater & formater_r = TFormater() )
558
561 template <class TContainer, class TFormater = out::TableFormater>
562 void table( const std::string & nodeName_r, const std::string & title_r,
563 const TContainer & container_r, const TFormater & formater_r = TFormater() )
565
566public:
568 void gap() { if ( type() == TYPE_NORMAL ) std::cout << std::endl; }
569
570 void printRichText( std::string text, unsigned indent_r = 0U )
571 { ztui::printRichText( std::cout, std::move(text), indent_r, termwidth() ); }
572
573
575 struct ParFormat // placeholder until we need it
576 {};
577
579 template <class Text>
580 void par( size_t indent_r, const Text & text_r, ParFormat format_r = ParFormat() )
581 {
582 gap(); // if needed make it optional via ParFormat
585 info( formated );
586 }
588 template <class Text>
590 { par( 0, text_r, format_r ); }
591
592
594 template <class TText, class Text>
595 void taggedPar( size_t indent_r, const TText & tag_r, const Text & text_r, ParFormat format_r = ParFormat() )
598 template <class TText, class Text>
600 { taggedPar( 0, tag_r, text_r, format_r ); }
601
602
604 template <class Text>
608 template <class Text>
610 { notePar( 0, text_r, format_r ); }
611
613 template <class Text>
617 template <class Text>
620
622 template <class Text>
626 template <class Text>
628 { errorPar( 0, text_r, format_r ); }
629
630public:
644 virtual void info(const std::string & msg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL) = 0;
646 void info( std::string msg, const std::string & msg2, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL )
647 { info( (msg+=msg2), verbosity, mask ); }
648
651 { info( msg_r.get(), verbosity_r, mask_r ); }
652
653 struct Info : protected ParentOut
654 {
656
658 : ParentOut( out_r )
659 , _str( new std::ostringstream )
660 {}
661
663 : ParentOut( rhs )
664 , _str( std::move(rhs._str) )
665 {}
666
668 { out().info( _str->str() ); }
669
670 template<class Tp>
671 std::ostream & operator<<( const Tp & val )
672 { return (*_str) << val; /*return *this;*/ }
673
674 operator std::ostream &()
675 { return *_str; }
676
677 std::ostream & stream()
678 { return *_str; }
679
680 private:
681 std::unique_ptr<std::ostringstream> _str; // work around missing move ctor
682 };
683
684 Info info() { return Info( *this ); }
685
686
688 void infoLR( const std::string & lmsg, const std::string & rmsg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL )
689 {
691 outstr.lhs << lmsg;
692 outstr.rhs << ' ' << rmsg;
694 }
695
697 void infoLRHint( const std::string & lmsg, const std::string & hint, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL )
698 {
700 outstr.lhs << lmsg;
701 outstr.rhs << " (" << hint << ')';
703 }
704
705
719 virtual void warning(const std::string & msg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL) = 0;
720
722 struct Error;
723
732 virtual void error(const std::string & problem_desc, const std::string & hint = "") = 0;
733
742 virtual void error(const zypp::Exception & e,
743 const std::string & problem_desc,
744 const std::string & hint = "") = 0;
745
747
750
752 class ProgressBar;
753
764 virtual void progressStart(const std::string & id,
765 const std::string & label,
766 bool is_tick = false) = 0;
767
777 virtual void progress(const std::string & id,
778 const std::string & label,
779 int value = -1) = 0;
780
791 virtual void progressEnd(const std::string & id,
792 const std::string & label,
793 const std::string & donetag,
794 bool error = false) = 0;
796 void progressEnd( const std::string & id, const std::string & label, ProgressEnd donetag );
798 void progressEnd( const std::string & id, const std::string & label, bool error = false )
801
809 virtual void dwnldProgressStart(const zypp::Url & uri) = 0;
810
818 virtual void dwnldProgress(const zypp::Url & uri,
819 int value = -1,
820 long rate = -1) = 0;
828 virtual void dwnldProgressEnd(const zypp::Url & uri,
829 long rate = -1,
830 zypp::TriBool error = false) = 0;
832
842 virtual void searchResult( const Table & table_r );
843
857 virtual void prompt(PromptId id,
858 const std::string & prompt,
859 const PromptOptions & poptions,
860 const std::string & startdesc = "") = 0;
861
866 virtual void promptHelp(const PromptOptions & poptions) = 0;
867
868public:
870 Verbosity verbosity() const { return _verbosity; }
871
874
887#define SCOPED_VERBOSITY( OUT, LEVEL ) const auto & raii __attribute__ ((__unused__))( (OUT).scopedVerbosity( LEVEL ))
888
895
897 virtual void setUseColors( bool yesno ) {}
898
899public:
901 TypeBit type() const { return _type; }
902
904 bool type( TypeBit type_r ) const { return type() == type_r; }
906 bool typeNORMAL() const { return type( TYPE_NORMAL ); }
908 bool typeXML() const { return type( TYPE_XML ); }
909
914 unsigned defaultFormatWidth( unsigned desired_r = 0 ) const
915 {
916 unsigned ret = termwidth();
918 ret = desired_r ? desired_r : 150U;
919 else if ( desired_r < ret )
920 ret = desired_r;
921 return ret;
922 }
923
925 virtual unsigned termwidth() const { return out::termwidthUnlimited; }
926
927protected:
928
932 virtual bool mine(Type type) = 0;
933
940 virtual bool progressFilter();
941
945 virtual std::string zyppExceptionReport(const zypp::Exception & e);
946
947private:
950};
951
953
989{
990public:
992 struct NoStartBar {};
994 static constexpr NoStartBar noStartBar = NoStartBar();
995
996public:
1001 ProgressBar( Out & out_r, NoStartBar, std::string progressId_r, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1002 : _out( out_r )
1003 , _progressId(std::move( progressId_r ))
1004 {
1005 if ( total_r )
1007 else if ( current_r )
1010 _progress.sendTo( Print( *this ) );
1011 }
1012
1013 ProgressBar( Out & out_r,NoStartBar, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1015 {}
1016
1021 ProgressBar( Out & out_r, const std::string & progressId_r, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1023 {
1024 // print the initial progress bar
1026 }
1027
1028 ProgressBar( Out & out_r, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1030 {}
1031
1037 {
1038 _progress.noSend(); // suppress ~ProgressData final report
1039 if ( not _donetag )
1042 }
1043
1047
1049 void print( const std::string & label_r )
1050 { _progress.name( label_r ); print(); }
1051
1055
1059
1062 { _donetag.reset(); }
1063
1065 void error( const std::string & label_r )
1066 { _progress.name( label_r ); error( true ); }
1067
1069 void error( const char * label_r )
1070 { _progress.name( label_r ); error( true ); }
1071
1072public:
1077
1079 { return &_progress; }
1080
1083
1085 { return _progress; }
1087
1088private:
1095 struct Print
1096 {
1099 { _bar->_out.progress( _bar->_progressId, _bar->outLabel( progress_r.name() ), progress_r.reportValue() ); return true; }
1100 private:
1102 };
1103
1104 std::string outLabel( const std::string & msg_r ) const
1105 { return _labelPrefix.empty() ? msg_r : _labelPrefix + msg_r; }
1106
1107 int numDigits( unsigned num_r ) const
1108 { int ret = 1; while ( num_r /= 10 ) ++ret; return ret; }
1109
1110private:
1112 std::optional<ProgressEnd> _donetag;
1114 std::string _progressId;
1115 std::string _labelPrefix;
1116};
1118
1152{
1155
1156 // basic: code msg hint
1157 Error( int exitcode_r, std::string msg_r, std::string hint_r = std::string() )
1158 : _exitcode( exitcode_r ), _msg( std::move(msg_r) ), _hint( std::move(hint_r) ) {}
1159
1160 // code exception hint
1161 Error( int exitcode_r, const zypp::Exception & ex_r, std::string hint_r = std::string() )
1162 : _exitcode( exitcode_r ), _msg( combine( ex_r ) ), _hint( std::move(hint_r) ) {}
1163
1164 // code (msg exception) hint
1165 Error( int exitcode_r, std::string msg_r, const zypp::Exception & ex_r, std::string hint_r = std::string() )
1166 : _exitcode( exitcode_r ), _msg( combine( std::move(msg_r), ex_r ) ), _hint( std::move(hint_r) ) {}
1167
1173 int report( Application & app_r ) const;
1174
1175 int _exitcode; //< ZYPPER_EXIT_OK indicates exitcode is already set.
1176 std::string _msg;
1177 std::string _hint;
1178
1179private:
1180 static std::string combine( std::string && msg_r, const zypp::Exception & ex_r );
1181 static std::string combine( const zypp::Exception & ex_r );
1182};
1183
1184}
1185
1186#endif /*OUT_H_*/
Convenience class for progress output.
Definition Out.h:989
ProgressBar(Out &out_r, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
Definition Out.h:1028
ProgressBar(Out &out_r, const std::string &progressId_r, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
Ctor displays initial progress bar.
Definition Out.h:1021
zypp::ProgressData * operator->()
Definition Out.h:1075
std::string _progressId
Definition Out.h:1114
zypp::ProgressData & operator*()
Definition Out.h:1081
void print()
Immediately print the progress bar not waiting for a new trigger.
Definition Out.h:1045
void errorreset()
Reset any error condition.
Definition Out.h:1061
const zypp::ProgressData * operator->() const
Definition Out.h:1078
zypp::ProgressData _progress
Definition Out.h:1113
std::string outLabel(const std::string &msg_r) const
Definition Out.h:1104
~ProgressBar()
Dtor displays final progress bar.
Definition Out.h:1036
std::string _labelPrefix
Definition Out.h:1115
void print(const std::string &label_r)
Definition Out.h:1049
void error(bool error_r)
Definition Out.h:1057
void error(ProgressEnd donetag_r=ProgressEnd::error)
Explicitly indicate the error condition for the final progress bar.
Definition Out.h:1053
ProgressBar(Out &out_r, NoStartBar, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
Definition Out.h:1013
std::optional< ProgressEnd > _donetag
Definition Out.h:1112
void error(const char *label_r)
Definition Out.h:1069
static constexpr NoStartBar noStartBar
Indicator argument for ctor not drawing an initial start bar.
Definition Out.h:994
int numDigits(unsigned num_r) const
Definition Out.h:1107
const zypp::ProgressData & operator*() const
Definition Out.h:1084
ProgressBar(Out &out_r, NoStartBar, std::string progressId_r, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
Ctor not displaying an initial progress bar.
Definition Out.h:1001
void error(const std::string &label_r)
Definition Out.h:1065
Base class for producing common (for now) zypper output.
Definition Out.h:430
void table(const std::string &nodeName_r, const std::string &title_r, const TContainer &container_r, const TFormater &formater_r=TFormater())
Write table from container creating a TitleNode with size="nnn" attribute and replacing optional %1% ...
Definition Out.h:562
void warningPar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Warning: '.
Definition Out.h:614
virtual bool mine(Type type)=0
Determine whether the output is intended for the particular type.
void infoLR(const std::string &lmsg, const std::string &rmsg, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)
Info message, 2 strings L/R-adjusted.
Definition Out.h:688
Verbosity verbosity() const
Get current verbosity.
Definition Out.h:870
zypp::DtorReset scopedVerbosity(Verbosity verbosity_r)
Return RAII class for exception safe scoped verbosity change.
Definition Out.h:890
Out(TypeBit type, Verbosity verbosity=NORMAL)
Definition Out.h:456
void par(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:589
unsigned defaultFormatWidth(unsigned desired_r=0) const
Terminal width or 150 if unlimited.
Definition Out.h:914
void setVerbosity(Verbosity verbosity)
Set current verbosity.
Definition Out.h:873
void infoLRHint(const std::string &lmsg, const std::string &hint, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)
Info message with R-adjusted "(hint)".
Definition Out.h:697
void notePar(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:609
Info info()
Definition Out.h:684
void warningPar(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:618
bool typeNORMAL() const
Definition Out.h:906
void progressEnd(const std::string &id, const std::string &label, bool error=false)
Definition Out.h:798
void gap()
NORMAL: An empty line.
Definition Out.h:568
void taggedPar(size_t indent_r, const TText &tag_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph of text preceded by 'tag_r' and a ' '.
Definition Out.h:595
virtual void dwnldProgress(const zypp::Url &uri, int value=-1, long rate=-1)=0
Reports download progress.
virtual void error(const zypp::Exception &e, const std::string &problem_desc, const std::string &hint="")=0
Prints the problem description caused by an exception, its cause and, optionally, a hint for the user...
static constexpr Type TYPE_ALL
Definition Out.h:451
virtual void prompt(PromptId id, const std::string &prompt, const PromptOptions &poptions, const std::string &startdesc="")=0
Prompt the user for a decision.
void info(std::string msg, const std::string &msg2, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)
Definition Out.h:646
void notePar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Note: '.
Definition Out.h:605
virtual void warning(const std::string &msg, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)=0
Show a warning.
void container(const std::string &nodeName_r, const std::string &title_r, const TContainer &container_r, const TFormater &formater_r)
Write container creating a TitleNode with size="nnn" attribute and replacing optional %1% in title_r ...
Definition Out.h:535
virtual unsigned termwidth() const
Width for formatted output [0==unlimited].
Definition Out.h:925
void errorPar(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:627
void list(const std::string &nodeName_r, const std::string &title_r, const TContainer &container_r, const TFormater &formater_r=TFormater())
Write list from container creating a TitleNode with size="nnn" attribute and replacing optional %1% i...
Definition Out.h:555
Verbosity
Verbosity levels.
Definition Out.h:434
@ QUIET
Only important messages (no progress or status, only the result).
Definition Out.h:435
@ NORMAL
Default output verbosity level.
Definition Out.h:436
@ HIGH
More detailed description of the operations.
Definition Out.h:438
@ DEBUG
Definition Out.h:439
void printRichText(std::string text, unsigned indent_r=0U)
Definition Out.h:570
virtual void setUseColors(bool yesno)
Hint for a handler whether config would allow to use colors.
Definition Out.h:897
Verbosity _verbosity
Definition Out.h:948
static constexpr Type TYPE_NONE
Definition Out.h:450
virtual void promptHelp(const PromptOptions &poptions)=0
Print help for prompt, if available.
void xmlNode(const std::string &name_r, const std::initializer_list< XmlNode::Attr > &attrs_r={})
XML only: Write a leaf node without PCDATA.
Definition Out.h:515
virtual bool progressFilter()
Determine whether to show progress.
Definition Out.cc:112
TypeBit type() const
Return the type of the instance.
Definition Out.h:901
virtual void error(const std::string &problem_desc, const std::string &hint="")=0
Show an error message and an optional hint.
virtual void searchResult(const Table &table_r)
Print out a search result.
Definition Out.cc:122
virtual void info(const std::string &msg, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)=0
Show an info message.
virtual std::string zyppExceptionReport(const zypp::Exception &e)
Return a Exception as a string suitable for output.
Definition Out.cc:117
unsigned PromptId
Definition Out.h:453
virtual void dwnldProgressEnd(const zypp::Url &uri, long rate=-1, zypp::TriBool error=false)=0
Reports end of a download.
void xmlNode(const std::string &name_r, XmlNode::Attr attr_r)
Definition Out.h:518
virtual void infoLine(const TermLine &msg_r, Verbosity verbosity_r=NORMAL, Type mask_r=TYPE_ALL)
info taking a TermLine
Definition Out.h:650
virtual void progress(const std::string &id, const std::string &label, int value=-1)=0
Progress report for an on-going operation.
virtual ~Out()
Definition Out.cc:109
bool typeXML() const
Definition Out.h:908
void par(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph of text, optionally indented, or without leading gap.
Definition Out.h:580
TypeBit
Known output types implemented by derived classes.
Definition Out.h:444
@ TYPE_XML
xml output
Definition Out.h:446
@ TYPE_NORMAL
plain text output
Definition Out.h:445
void taggedPar(const TText &tag_r, const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:599
virtual void progressEnd(const std::string &id, const std::string &label, const std::string &donetag, bool error=false)=0
End of an operation with reported progress.
virtual void progressStart(const std::string &id, const std::string &label, bool is_tick=false)=0
Start of an operation with reported progress.
const TypeBit _type
Definition Out.h:949
void errorPar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Error: '.
Definition Out.h:623
virtual void dwnldProgressStart(const zypp::Url &uri)=0
Reoprt start of a download.
bool type(TypeBit type_r) const
Test for a specific type.
Definition Out.h:904
ZYPP_DECLARE_FLAGS(Type, TypeBit)
Example: PromptOptions popts; popts.setOptions(_("y/n/p"), 0 / * default reply * /); popts....
bool empty() const
Definition Table.h:411
Table & setHeader(TableHeader tr)
Definition Table.cc:335
Table & add(TableRow tr)
Definition Table.cc:329
Colored string if do_colors.
Definition ansi.h:497
Class representing an application (appdata.xml)
Definition Application.h:28
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
void reset()
Reset to default Ctor values.
Integral type with defined initial value when default constructed.
Assign a vaiable a certain value when going out of scope.
Definition dtorreset.h:50
Base class for Exception.
Definition Exception.h:147
Maintain [min,max] and counter (value) for progress counting.
bool reportPercent() const
value_type reportValue() const
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
void name(const std::string &name_r)
Set counter name.
void noSend()
Set no ReceiverFnc.
Url manipulation class.
Definition Url.h:92
Definition Arch.h:364
TableHeader asTableHeader< void >()
Definition Out.h:150
void xmlWriteContainer(std::ostream &str_r, const TContainer &container_r, const TFormater &formater_r)
Write XML formatted container to stream.
Definition Out.h:340
TableLayout DefaultTableLayout
Simple Table.
Definition Out.h:129
void writeContainer(std::ostream &str_r, const TContainer &container_r, const TFormater &formater_r, const TLayout &layout_r=TLayout())
Write formatted container to stream.
Definition Out.h:330
detail::ListLayoutInit< true, true, false, 0U > DefaultListLayout
one element per line, no indent
Definition Out.h:114
static constexpr unsigned termwidthUnlimited
Definition Out.h:80
detail::ListLayoutInit< true, false, false, 0U > XmlListLayout
Definition Out.h:113
std::string asListElement(const std::string &val_r)
Definition Out.h:142
unsigned defaultTermwidth()
Definition Out.cc:27
std::string asXmlListElement(const std::string &val_r)
Definition Out.h:136
ColorString tagWarning()
Definition Out.h:53
ColorString tagNote()
Definition Out.h:51
const char * qContinue()
Definition Out.h:57
bool endsOnWS(const std::string &str_r)
Whether the str_r ends with a WS.
Definition Out.h:66
ColorString tagError()
Definition Out.h:55
std::string join(const Tltext &ltext, const Trtext &rtext, const char *sep=" ")
Simple join of two string types.
Definition Out.h:62
const char * optBlankAfter(const std::string &str_r)
Definition Out.h:74
std::ostream & printRichText(std::ostream &str, std::string text, unsigned indent_r=0U, unsigned width_r=0U)
Print [Rich]Text optionally indented.
Definition richtext.h:26
CCString< ColorContext::MSG_ERROR > MSG_ERRORString
Definition colors.h:80
CCString< ColorContext::MSG_WARNING > MSG_WARNINGString
Definition colors.h:81
CCString< ColorContext::HIGHLIGHT > HIGHLIGHTString
Definition colors.h:87
void mbs_write_wrapped(std::ostream &out, boost::string_ref text_r, size_t indent_r, size_t wrap_r, int indentFix_r=0)
Wrap and indent given text and write it to the output stream out.
Definition text.h:631
ProgressEnd
ProgressBars default end tags.
Definition Out.h:46
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
std::string numstring(char n, int w=0)
Definition String.h:289
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition String.h:139
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:37
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
Definition Xml.h:204
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition String.h:30
Convenience class Error reporting.
Definition Out.h:1152
std::string _hint
Definition Out.h:1177
Error(int exitcode_r, const zypp::Exception &ex_r, std::string hint_r=std::string())
Definition Out.h:1161
static std::string combine(std::string &&msg_r, const zypp::Exception &ex_r)
Definition Out.cc:153
std::string _msg
Definition Out.h:1176
Error(int exitcode_r, std::string msg_r, std::string hint_r=std::string())
Definition Out.h:1157
int report(Application &app_r) const
Default way of processing a caught Error exception.
Definition Out.cc:144
Error(int exitcode_r, std::string msg_r, const zypp::Exception &ex_r, std::string hint_r=std::string())
Definition Out.h:1165
Error(int exitcode_r)
Definition Out.h:1153
std::ostream & stream()
Definition Out.h:677
std::unique_ptr< std::ostringstream > _str
Definition Out.h:681
Info(Out::Info &&rhs) noexcept
Definition Out.h:662
std::ostream & operator<<(const Tp &val)
Definition Out.h:671
Info(Out &out_r)
Definition Out.h:657
Less common Paragraph formats.
Definition Out.h:576
Convenience base class storing the back reference to Out.
Definition Out.h:468
ParentOut(Out &out_r)
Definition Out.h:469
Indicator type for ctor not drawing an initial start bar.
Definition Out.h:992
ProgressData::ReceiverFnc printing to a ProgressBar.
Definition Out.h:1096
Print(ProgressBar &bar_r)
Definition Out.h:1097
bool operator()(const zypp::ProgressData &progress_r)
Definition Out.h:1098
XmlNode with optional normal text headline (NL appended)
Definition Out.h:525
TitleNode(XmlNode &&node_r, const std::string &title_r="")
Definition Out.h:526
XML only: RAII writing a XML nodes start/end tag.
Definition Out.h:486
zypp::scoped_ptr< zypp::xmlout::Node > _node
Definition Out.h:506
XmlNode(XmlNode &&rhs) noexcept
Move ctor.
Definition Out.h:503
XmlNode(Out &out_r, const std::string &name_r, const std::initializer_list< Attr > &attrs_r={})
Ctor taking nodename and attribute list.
Definition Out.h:490
XmlNode(Out &out_r, const std::string &name_r, Attr attr_r)
Convenience ctor for one attribute pair.
Definition Out.h:498
TermLine(char exp_r)
Definition Out.h:360
TermLine(SplitFlags flags_r, char exp_r)
Definition Out.h:358
std::string get(unsigned width_r, char exp_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Out.h:383
TermLine(SplitFlags flags_r)
Definition Out.h:359
zypp::DefaultIntegral< char,' '> expHint
Definition Out.h:364
zypp::DefaultIntegral< int,-1 > percentHint
Definition Out.h:365
std::string get() const
Return plain line made of lhs + rhs.
Definition Out.h:372
zypp::str::Str rhs
Definition Out.h:368
std::string get(unsigned width_r, SplitFlags flags_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Out.h:380
ZYPP_DECLARE_FLAGS(SplitFlags, SplitFlag)
std::string get(unsigned width_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Out.h:386
SplitFlags flagsHint
Definition Out.h:363
zypp::str::Str lhs
Definition Out.h:367
Default representation of types in Lists [asListElement].
Definition Out.h:173
std::string listElement(const Tp &val_r) const
Definition Out.h:177
std::string asListElement(const Tp &val_r)
NORMAL representation of types in lists [no default].
Write out a List according to the layout.
Definition Out.h:231
void printAndCount(const std::string &element_r) const
Definition Out.h:277
const ListLayout & _layout
Definition Out.h:285
const unsigned _linewidth
desired line width
Definition Out.h:287
const std::string _indent
Definition Out.h:288
bool fitsOnLine(unsigned size_r) const
Definition Out.h:274
void operator<<(Tp &&val_r) const
Definition Out.h:246
Writer(std::ostream &str_r, const ListLayout &layout_r, const TFormater &formater_r)
Definition Out.h:234
std::ostream & _str
Definition Out.h:284
const TFormater & _formater
Definition Out.h:286
Basic list layout.
Definition Out.h:92
bool _singleline
one list element per line
Definition Out.h:101
unsigned _indent
amount of indent
Definition Out.h:104
bool _gaped
add extra NL before element (if singleline)
Definition Out.h:103
bool _wrapline
fold lines longer than _linewidth
Definition Out.h:102
ListLayout(bool singleline_r, bool wrapline_r, bool gaped_r, unsigned indent_r)
Definition Out.h:95
Special list formater writing a Table [asTableHeader|asTableRow].
Definition Out.h:186
TableHeader header() const
Definition Out.h:189
TableRow asTableRow(const Tp &val_r)
NORMAL representation of types as TableRow [no default].
TableHeader asTableHeader()
NORMAL representation of types as TableHeader [no default].
TableRow row(const Tp &val_r) const
Definition Out.h:193
Write out a Table according to the layout.
Definition Out.h:298
const TableLayout & _layout
Definition Out.h:322
std::ostream & _str
Definition Out.h:321
void operator<<(Tp &&val_r) const
Definition Out.h:317
Writer(std::ostream &str_r, const TableLayout &layout_r, const TFormater &formater_r)
Definition Out.h:301
const TFormater & _formater
Definition Out.h:323
Basic table layout.
Definition Out.h:125
XmlFormaterAdaptor(const TFormater &formater_r)
Definition Out.h:211
std::string listElement(const Tp &val_r) const
Definition Out.h:208
const TFormater & _formater
Definition Out.h:215
XML representation of types in container [asXmlListElement].
Definition Out.h:162
std::string xmlListElement(const Tp &val_r) const
Definition Out.h:164
std::string asXmlListElement(const Tp &val_r)
XML representation of types [no default].
Convenient building of std::string with boost::format.
Definition String.h:253
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:212
(Key, Value) string pair of XML node attributes
Definition Xml.h:44
RAII writing a nodes start/end tag.
Definition Xml.h:85
NodeAttr Attr
Definition Xml.h:87
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177
#define _(MSG)
Definition Gettext.h:39