libzypp 17.37.17
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>
29#include <zypp-core/Url.h>
30#include <zypp-core/TriBool.h>
31#include <zypp-core/ui/ProgressData>
33
34#include <zypp-tui/utils/text.h>
37#include <zypp-tui/Table.h>
38#include <zypp-tui/output/PromptOptions>
39
40namespace ztui {
41
42class Application;
43
46
47namespace text
48{
49 ColorString tagNote();
50 ColorString tagWarning();
51 ColorString tagError();
52 const char * qContinue();
53
55 template <class Tltext, class Trtext>
56 inline std::string join( const Tltext & ltext, const Trtext & rtext, const char * sep = " " )
57 { std::string ret( zypp::str::asString(ltext) ); ret += sep; ret += zypp::str::asString(rtext); return ret; }
58
60 inline bool endsOnWS( const std::string & str_r )
61 {
62 bool ret = false;
63 if ( !str_r.empty() )
64 { int l = *str_r.rbegin(); if ( ::strchr( " \n\t", l ) ) ret = true; }
65 return ret;
66 }
67
68 inline const char * optBlankAfter( const std::string & str_r )
69 { return( endsOnWS( str_r ) ? "" : " " ); }
70}
71
72namespace out
73{
74 static constexpr unsigned termwidthUnlimited = 0u;
75 unsigned defaultTermwidth(); // Zypper::instance().out().termwidth()
76} // namespace out
77
78namespace out
79{
86 {
87 template <class TFormater> struct Writer;
88
89 ListLayout( bool singleline_r, bool wrapline_r, bool gaped_r, unsigned indent_r )
90 : _singleline( singleline_r )
91 , _wrapline( wrapline_r )
92 , _gaped( gaped_r )
93 , _indent( indent_r )
94 {}
96 bool _wrapline;
97 bool _gaped;
98 unsigned _indent;
99 };
100
101 namespace detail
102 {
103 template <bool singleline_, bool wrapline_, bool gaped_, unsigned indent_>
104 struct ListLayoutInit : public ListLayout { ListLayoutInit() : ListLayout( singleline_, wrapline_, gaped_, indent_ ) {} };
105 }
106
113
119 {
120 template <class TFormater> struct Writer;
121 };
122
124
125 // Either specialize per Type or define a custom Formater:
126
128 template <class Tp>
129 std::string asXmlListElement( const Tp & val_r );
130 inline std::string asXmlListElement( const std::string & val_r ){ return val_r; }
131 inline std::string asXmlListElement( const char * val_r ) { return val_r; }
132
134 template <class Tp>
135 std::string asListElement( const Tp & val_r );
136 inline std::string asListElement( const std::string & val_r ) { return val_r; }
137 inline std::string asListElement( const char * val_r ) { return val_r; }
138
140 template <class Tp = void>
142
143 template <>
145 { return TableHeader(); }
146
148 template <class Tp>
149 TableRow asTableRow( const Tp & val_r );
150
156 {
157 template <class Tp>
158 std::string xmlListElement( const Tp & val_r ) const//< XML representation of element
159 { return asXmlListElement( val_r ); }
160 };
161
166 struct ListFormater : public XmlFormater
167 {
168 using NormalLayout = DefaultListLayout; //< ListLayout for NORMAL lists
169
170 template <class Tp>
171 std::string listElement( const Tp & val_r ) const //< NORMAL representation of list element
172 { return asListElement( val_r ); }
173 };
174
180 {
181 using NormalLayout = DefaultTableLayout; //< NORMAL layout as Table
182
183 TableHeader header() const //< TableHeader for TableRow representation
184 { return asTableHeader<>(); }
185
186 template <class Tp> //< Representation as TableRow
187 TableRow row( const Tp & val_r ) const
188 { return asTableRow( val_r ); }
189 };
190
195
196 template <class TFormater>
198 {
199 using NormalLayout = XmlListLayout; //< Layout as XML list
200
201 template <class Tp>
202 std::string listElement( const Tp & val_r ) const //< use TFormater::asXmlListElement
203 { return _formater.xmlListElement( val_r ); }
204
205 XmlFormaterAdaptor( const TFormater & formater_r )
206 : _formater( formater_r )
207 {}
208 private:
209 const TFormater & _formater;
210 };
211
212} // namespace out
214
216namespace out
217{
221 // TODO: wrap singlelines; support for attributed text;
223 template <class TFormater>
225 {
227
228 Writer( std::ostream & str_r, const ListLayout & layout_r, const TFormater & formater_r )
229 : _str( str_r )
230 , _layout( layout_r )
231 , _formater( formater_r )
233 , _indent( _layout._indent, ' ' )
234 {}
235
237 { if ( !_layout._singleline && _cpos ) _str << std::endl; }
238
239 template <class Tp>
240 void operator<<( Tp && val_r ) const
241 {
242 const std::string & element( _formater.listElement( std::forward<Tp>(val_r) ) );
243
244 if ( _layout._singleline )
245 {
246 if ( _layout._gaped )
247 _str << std::endl;
248 _str << _indent << element << std::endl;
249 }
250 else
251 {
252 if ( _cpos != 0 && ! fitsOnLine( 1/*' '*/ + element.size() ) )
253 endLine();
254
255 if ( _cpos == 0 )
256 {
257 if ( !_indent.empty() )
259 }
260 else
261 printAndCount( " " );
262
263 printAndCount( element );
264 }
265 }
266
267 private:
268 bool fitsOnLine( unsigned size_r ) const
269 { return( !_layout._wrapline || _linewidth == out::termwidthUnlimited || _cpos + size_r <= _linewidth ); }
270
271 void printAndCount( const std::string & element_r ) const
272 { _cpos += element_r.size(); _str << element_r; }
273
274 void endLine() const
275 { _str << std::endl; _cpos = 0U; }
276
277 private:
278 std::ostream & _str;
280 const TFormater & _formater;
281 const unsigned _linewidth;
282 const std::string _indent;
283 mutable unsigned _cpos = 0U;
284 };
285
290 template <class TFormater>
292 {
294
295 Writer( std::ostream & str_r, const TableLayout & layout_r, const TFormater & formater_r )
296 : _str( str_r )
297 , _layout( layout_r )
298 , _formater( formater_r )
299 {}
300
302 {
303 if ( !_t.empty() )
304 {
305 _t.setHeader( _formater.header() );
306 _str << _t;
307 }
308 }
309
310 template <class Tp>
311 void operator<<( Tp && val_r ) const
312 { _t.add( _formater.row( std::forward<Tp>(val_r) ) ); }
313
314 private:
315 std::ostream & _str;
317 const TFormater & _formater;
318 mutable Table _t;
319 };
320
321
323 template <class TContainer, class TFormater, class TLayout = typename TFormater::NormalLayout>
324 void writeContainer( std::ostream & str_r, const TContainer & container_r, const TFormater & formater_r, const TLayout & layout_r = TLayout() )
325 {
326 typedef typename TLayout::template Writer<TFormater> Writer;
327 Writer writer( str_r, layout_r, formater_r );
328 for ( auto && el : container_r )
329 writer << el;
330 }
331
333 template <class TContainer, class TFormater>
334 void xmlWriteContainer( std::ostream & str_r, const TContainer & container_r, const TFormater & formater_r )
335 { writeContainer( str_r, container_r, out::XmlFormaterAdaptor<TFormater>(formater_r) ); }
336
337} // namespace out
339
340// Too simple on small terminals as esc-sequences may get truncated.
341// A table like writer for attributed strings is desirable.
343{
345 {
346 SF_CRUSH = 1<<0, //< truncate lhs, then rhs
347 SF_SPLIT = 1<<1, //< split line across two
348 SF_EXPAND = 1<<2 //< expand short lines iff stdout is a tty
349 };
351
352 TermLine( SplitFlags flags_r, char exp_r ) : flagsHint( flags_r ), expHint( exp_r ) {}
353 TermLine( SplitFlags flags_r ) : flagsHint( flags_r ) {}
354 TermLine( char exp_r ) : expHint( exp_r ) {}
356
357 SplitFlags flagsHint; //< flags to use if not passed to \ref get
358 zypp::DefaultIntegral<char,' '> expHint; //< expand char to use if not passed to \ref get
359 zypp::DefaultIntegral<int,-1> percentHint; //< draw progress indicator in expanded space if in [0,100]
360
361 zypp::str::Str lhs; //< left side
362 zypp::str::Str rhs; //< right side
363
364
366 std::string get() const
367 { return std::string(lhs) + std::string(rhs); }
368
372 std::string get( unsigned width_r, SplitFlags flags_r, char exp_r ) const;
374 std::string get( unsigned width_r, SplitFlags flags_r ) const
375 { return get( width_r, flags_r, expHint ); }
376
377 std::string get( unsigned width_r, char exp_r ) const
378 { return get( width_r, flagsHint, exp_r ); }
379
380 std::string get( unsigned width_r ) const
381 { return get( width_r, flagsHint, expHint ); }
382};
383ZYPP_DECLARE_OPERATORS_FOR_FLAGS( TermLine::SplitFlags );
384
424{
425public:
427 typedef enum
428 {
429 QUIET = 0,
430 NORMAL = 1,
432 HIGH = 2,
433 DEBUG = 3
434 } Verbosity;
435
438 {
439 TYPE_NORMAL = 0x01<<0,
440 TYPE_XML = 0x01<<1
441 };
443
444 static constexpr Type TYPE_NONE = Type(0x00);
445 static constexpr Type TYPE_ALL = Type(0xff);
446
447 using PromptId = unsigned;
448
449protected:
453
454public:
455 virtual ~Out();
456
457protected:
462 {
463 ParentOut( Out & out_r ) : _out( out_r ) {}
464 Out & out() { return _out; }
465 private:
467 };
468
469public:
479 struct XmlNode : protected ParentOut
480 {
482
484 XmlNode( Out & out_r, const std::string & name_r, const std::initializer_list<Attr> & attrs_r = {} )
485 : ParentOut( out_r )
486 {
487 if ( out().typeXML() && ! name_r.empty() )
488 { _node.reset( new zypp::xmlout::Node( std::cout, name_r, attrs_r ) ); }
489 }
490
492 XmlNode( Out & out_r, const std::string & name_r, Attr attr_r )
493 : XmlNode( out_r, name_r, { std::move(attr_r) } )
494 {}
495
497 XmlNode( XmlNode && rhs ) noexcept : ParentOut( rhs ) { _node.swap( rhs._node ); }
498
499 private:
500 zypp::scoped_ptr<zypp::xmlout::Node> _node;
501 };
502
503
509 void xmlNode( const std::string & name_r, const std::initializer_list<XmlNode::Attr> & attrs_r = {} )
510 { if ( typeXML() ) { zypp::xmlout::node( std::cout, name_r, attrs_r ); } }
511
512 void xmlNode( const std::string & name_r, XmlNode::Attr attr_r )
513 { xmlNode( name_r, { std::move(attr_r) } ); }
514
518 struct TitleNode : public XmlNode
519 {
520 TitleNode( XmlNode && node_r, const std::string & title_r = "" )
521 : XmlNode( std::move(node_r) )
522 { if ( out().typeNORMAL() && ! title_r.empty() ) std::cout << title_r << std::endl; }
523 };
524
525private:
528 template <class TContainer, class TFormater>
529 void container( const std::string & nodeName_r, const std::string & title_r,
530 const TContainer & container_r, const TFormater & formater_r )
531 {
532 TitleNode guard( XmlNode( *this, nodeName_r, XmlNode::Attr( "size", zypp::str::numstring( container_r.size() ) ) ),
533 zypp::str::Format( title_r ) % container_r.size() );
534 switch ( type() )
535 {
536 case TYPE_NORMAL:
537 writeContainer( std::cout, container_r, formater_r );
538 break;
539 case TYPE_XML:
540 ztui::out::xmlWriteContainer( std::cout, container_r, formater_r );
541 break;
542 }
543 }
544
545public:
548 template <class TContainer, class TFormater = out::ListFormater>
549 void list( const std::string & nodeName_r, const std::string & title_r,
550 const TContainer & container_r, const TFormater & formater_r = TFormater() )
551 { container( nodeName_r, title_r, container_r, formater_r ); }
552
555 template <class TContainer, class TFormater = out::TableFormater>
556 void table( const std::string & nodeName_r, const std::string & title_r,
557 const TContainer & container_r, const TFormater & formater_r = TFormater() )
558 { container( nodeName_r, title_r, container_r, formater_r ); }
559
560public:
562 void gap() { if ( type() == TYPE_NORMAL ) std::cout << std::endl; }
563
564 void printRichText( std::string text, unsigned indent_r = 0U )
565 { ztui::printRichText( std::cout, std::move(text), indent_r, termwidth() ); }
566
567
569 struct ParFormat // placeholder until we need it
570 {};
571
573 template <class Text>
574 void par( size_t indent_r, const Text & text_r, ParFormat format_r = ParFormat() )
575 {
576 gap(); // if needed make it optional via ParFormat
577 zypp::str::Str formated;
578 mbs_write_wrapped( formated.stream(), zypp::str::asString(text_r), indent_r, defaultFormatWidth( 100 ) );
579 info( formated );
580 }
581
582 template <class Text>
583 void par( const Text & text_r, ParFormat format_r = ParFormat() )
584 { par( 0, text_r, format_r ); }
585
586
588 template <class TText, class Text>
589 void taggedPar( size_t indent_r, const TText & tag_r, const Text & text_r, ParFormat format_r = ParFormat() )
590 { par( indent_r, text::join( tag_r, text_r ), format_r ); }
591
592 template <class TText, class Text>
593 void taggedPar( const TText & tag_r, const Text & text_r, ParFormat format_r = ParFormat() )
594 { taggedPar( 0, tag_r, text_r, format_r ); }
595
596
598 template <class Text>
599 void notePar( size_t indent_r, const Text & text_r, ParFormat format_r = ParFormat() )
600 { taggedPar( indent_r, text::tagNote(), text_r, format_r ); }
601
602 template <class Text>
603 void notePar( const Text & text_r, ParFormat format_r = ParFormat() )
604 { notePar( 0, text_r, format_r ); }
605
607 template <class Text>
608 void warningPar( size_t indent_r, const Text & text_r, ParFormat format_r = ParFormat() )
609 { taggedPar( indent_r, text::tagWarning(), text_r, format_r ); }
610
611 template <class Text>
612 void warningPar( const Text & text_r, ParFormat format_r = ParFormat() )
613 { warningPar( 0, text_r, format_r ); }
614
616 template <class Text>
617 void errorPar( size_t indent_r, const Text & text_r, ParFormat format_r = ParFormat() )
618 { taggedPar( indent_r, text::tagError(), text_r, format_r ); }
619
620 template <class Text>
621 void errorPar( const Text & text_r, ParFormat format_r = ParFormat() )
622 { errorPar( 0, text_r, format_r ); }
623
624public:
638 virtual void info(const std::string & msg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL) = 0;
640 void info( std::string msg, const std::string & msg2, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL )
641 { info( (msg+=msg2), verbosity, mask ); }
642
644 virtual void infoLine(const TermLine & msg_r, Verbosity verbosity_r = NORMAL, Type mask_r = TYPE_ALL)
645 { info( msg_r.get(), verbosity_r, mask_r ); }
646
647 struct Info : protected ParentOut
648 {
650
651 Info( Out & out_r )
652 : ParentOut( out_r )
653 , _str( new std::ostringstream )
654 {}
655
656 Info( Out::Info && rhs ) noexcept
657 : ParentOut( rhs )
658 , _str( std::move(rhs._str) )
659 {}
660
662 { out().info( _str->str() ); }
663
664 template<class Tp>
665 std::ostream & operator<<( const Tp & val )
666 { return (*_str) << val; /*return *this;*/ }
667
668 operator std::ostream &()
669 { return *_str; }
670
671 std::ostream & stream()
672 { return *_str; }
673
674 private:
675 std::unique_ptr<std::ostringstream> _str; // work around missing move ctor
676 };
677
678 Info info() { return Info( *this ); }
679
680
682 void infoLR( const std::string & lmsg, const std::string & rmsg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL )
683 {
685 outstr.lhs << lmsg;
686 outstr.rhs << ' ' << rmsg;
687 infoLine( outstr, verbosity, mask );
688 }
689
691 void infoLRHint( const std::string & lmsg, const std::string & hint, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL )
692 {
694 outstr.lhs << lmsg;
695 outstr.rhs << " (" << hint << ')';
696 infoLine( outstr, verbosity, mask );
697 }
698
699
713 virtual void warning(const std::string & msg, Verbosity verbosity = NORMAL, Type mask = TYPE_ALL) = 0;
714
716 struct Error;
717
726 virtual void error(const std::string & problem_desc, const std::string & hint = "") = 0;
727
736 virtual void error(const zypp::Exception & e,
737 const std::string & problem_desc,
738 const std::string & hint = "") = 0;
739
741
744
746 class ProgressBar;
747
758 virtual void progressStart(const std::string & id,
759 const std::string & label,
760 bool is_tick = false) = 0;
761
771 virtual void progress(const std::string & id,
772 const std::string & label,
773 int value = -1) = 0;
774
785 virtual void progressEnd(const std::string & id,
786 const std::string & label,
787 const std::string & donetag,
788 bool error = false) = 0;
790 void progressEnd( const std::string & id, const std::string & label, ProgressEnd donetag );
792 void progressEnd( const std::string & id, const std::string & label, bool error = false )
794
795
798
803 virtual void dwnldProgressStart(const zypp::Url & uri) = 0;
804
812 virtual void dwnldProgress(const zypp::Url & uri,
813 int value = -1,
814 long rate = -1) = 0;
822 virtual void dwnldProgressEnd(const zypp::Url & uri,
823 long rate = -1,
824 zypp::TriBool error = false) = 0;
826
836 virtual void searchResult( const Table & table_r );
837
851 virtual void prompt(PromptId id,
852 const std::string & prompt,
853 const PromptOptions & poptions,
854 const std::string & startdesc = "") = 0;
855
860 virtual void promptHelp(const PromptOptions & poptions) = 0;
861
862public:
864 Verbosity verbosity() const { return _verbosity; }
865
868
881#define SCOPED_VERBOSITY( OUT, LEVEL ) const auto & raii __attribute__ ((__unused__))( (OUT).scopedVerbosity( LEVEL ))
882
885 {
886 std::swap( _verbosity, verbosity_r );
887 return zypp::DtorReset( _verbosity, verbosity_r );
888 }
889
891 virtual void setUseColors( bool yesno ) {}
892
893public:
895 TypeBit type() const { return _type; }
896
898 bool type( TypeBit type_r ) const { return type() == type_r; }
900 bool typeNORMAL() const { return type( TYPE_NORMAL ); }
902 bool typeXML() const { return type( TYPE_XML ); }
903
908 unsigned defaultFormatWidth( unsigned desired_r = 0 ) const
909 {
910 unsigned ret = termwidth();
911 if ( ret == out::termwidthUnlimited )
912 ret = desired_r ? desired_r : 150U;
913 else if ( desired_r < ret )
914 ret = desired_r;
915 return ret;
916 }
917
919 virtual unsigned termwidth() const { return out::termwidthUnlimited; }
920
921protected:
922
926 virtual bool mine(Type type) = 0;
927
934 virtual bool progressFilter();
935
939 virtual std::string zyppExceptionReport(const zypp::Exception & e);
940
941private:
944};
945
947
983{
984public:
986 struct NoStartBar {};
988 static constexpr NoStartBar noStartBar = NoStartBar();
989
990public:
995 ProgressBar( Out & out_r, NoStartBar, std::string progressId_r, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
996 : _out( out_r )
997 , _progressId(std::move( progressId_r ))
998 {
999 if ( total_r )
1000 _labelPrefix = zypp::str::form( "(%*u/%u) ", numDigits( total_r ), current_r, total_r );
1001 else if ( current_r )
1002 _labelPrefix = zypp::str::form( "(%u) ", current_r );
1003 _progress.name( label_r );
1004 _progress.sendTo( Print( *this ) );
1005 }
1006
1007 ProgressBar( Out & out_r,NoStartBar, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1008 : ProgressBar( out_r, noStartBar, "", label_r, current_r, total_r )
1009 {}
1010
1015 ProgressBar( Out & out_r, const std::string & progressId_r, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1016 : ProgressBar( out_r, noStartBar, progressId_r, label_r, current_r, total_r )
1017 {
1018 // print the initial progress bar
1019 _out.progressStart( _progressId, outLabel( _progress.name() ) );
1020 }
1021
1022 ProgressBar( Out & out_r, const std::string & label_r, unsigned current_r = 0, unsigned total_r = 0 )
1023 : ProgressBar( out_r, "", label_r, current_r, total_r )
1024 {}
1025
1031 {
1032 _progress.noSend(); // suppress ~ProgressData final report
1033 if ( not _donetag )
1034 error( _progress.reportValue() != 100 && _progress.reportPercent() );
1035 _out.progressEnd( _progressId, outLabel( _progress.name() ), *_donetag );
1036 }
1037
1039 void print()
1040 { _out.progress( _progressId, outLabel( _progress.name() ), _progress.reportValue() ); }
1041
1043 void print( const std::string & label_r )
1044 { _progress.name( label_r ); print(); }
1045
1048 { _donetag = donetag_r; }
1049
1051 void error( bool error_r )
1053
1056 { _donetag.reset(); }
1057
1059 void error( const std::string & label_r )
1060 { _progress.name( label_r ); error( true ); }
1061
1063 void error( const char * label_r )
1064 { _progress.name( label_r ); error( true ); }
1065
1066public:
1071
1073 { return &_progress; }
1074
1077
1079 { return _progress; }
1080
1081
1082private:
1089 struct Print
1090 {
1091 Print( ProgressBar & bar_r ) : _bar( &bar_r ) {}
1092 bool operator()( const zypp::ProgressData & progress_r )
1093 { _bar->_out.progress( _bar->_progressId, _bar->outLabel( progress_r.name() ), progress_r.reportValue() ); return true; }
1094 private:
1096 };
1097
1098 std::string outLabel( const std::string & msg_r ) const
1099 { return _labelPrefix.empty() ? msg_r : _labelPrefix + msg_r; }
1100
1101 int numDigits( unsigned num_r ) const
1102 { int ret = 1; while ( num_r /= 10 ) ++ret; return ret; }
1103
1104private:
1106 std::optional<ProgressEnd> _donetag;
1108 std::string _progressId;
1109 std::string _labelPrefix;
1110};
1111
1112
1146{
1147 Error( int exitcode_r )
1148 : _exitcode( exitcode_r ) {}
1149
1150 // basic: code msg hint
1151 Error( int exitcode_r, std::string msg_r, std::string hint_r = std::string() )
1152 : _exitcode( exitcode_r ), _msg( std::move(msg_r) ), _hint( std::move(hint_r) ) {}
1153
1154 // code exception hint
1155 Error( int exitcode_r, const zypp::Exception & ex_r, std::string hint_r = std::string() )
1156 : _exitcode( exitcode_r ), _msg( combine( ex_r ) ), _hint( std::move(hint_r) ) {}
1157
1158 // code (msg exception) hint
1159 Error( int exitcode_r, std::string msg_r, const zypp::Exception & ex_r, std::string hint_r = std::string() )
1160 : _exitcode( exitcode_r ), _msg( combine( std::move(msg_r), ex_r ) ), _hint( std::move(hint_r) ) {}
1161
1167 int report( Application & app_r ) const;
1168
1169 int _exitcode; //< ZYPPER_EXIT_OK indicates exitcode is already set.
1170 std::string _msg;
1171 std::string _hint;
1172
1173private:
1174 static std::string combine( std::string && msg_r, const zypp::Exception & ex_r );
1175 static std::string combine( const zypp::Exception & ex_r );
1176};
1177
1178}
1179
1180#endif /*OUT_H_*/
Convenience class for progress output.
Definition Out.h:983
ProgressBar(Out &out_r, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
Definition Out.h:1022
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:1015
zypp::ProgressData * operator->()
Definition Out.h:1069
std::string _progressId
Definition Out.h:1108
zypp::ProgressData & operator*()
Definition Out.h:1075
void print()
Immediately print the progress bar not waiting for a new trigger.
Definition Out.h:1039
void errorreset()
Reset any error condition.
Definition Out.h:1055
const zypp::ProgressData * operator->() const
Definition Out.h:1072
zypp::ProgressData _progress
Definition Out.h:1107
std::string outLabel(const std::string &msg_r) const
Definition Out.h:1098
~ProgressBar()
Dtor displays final progress bar.
Definition Out.h:1030
std::string _labelPrefix
Definition Out.h:1109
void print(const std::string &label_r)
Definition Out.h:1043
void error(bool error_r)
Definition Out.h:1051
void error(ProgressEnd donetag_r=ProgressEnd::error)
Explicitly indicate the error condition for the final progress bar.
Definition Out.h:1047
ProgressBar(Out &out_r, NoStartBar, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
Definition Out.h:1007
std::optional< ProgressEnd > _donetag
Definition Out.h:1106
void error(const char *label_r)
Definition Out.h:1063
static constexpr NoStartBar noStartBar
Indicator argument for ctor not drawing an initial start bar.
Definition Out.h:988
int numDigits(unsigned num_r) const
Definition Out.h:1101
const zypp::ProgressData & operator*() const
Definition Out.h:1078
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:995
void error(const std::string &label_r)
Definition Out.h:1059
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:556
void warningPar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Warning: '.
Definition Out.h:608
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:682
Verbosity verbosity() const
Get current verbosity.
Definition Out.h:864
zypp::DtorReset scopedVerbosity(Verbosity verbosity_r)
Return RAII class for exception safe scoped verbosity change.
Definition Out.h:884
Out(TypeBit type, Verbosity verbosity=NORMAL)
Definition Out.h:450
void par(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:583
unsigned defaultFormatWidth(unsigned desired_r=0) const
Terminal width or 150 if unlimited.
Definition Out.h:908
void setVerbosity(Verbosity verbosity)
Set current verbosity.
Definition Out.h:867
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:691
void notePar(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:603
Info info()
Definition Out.h:678
void warningPar(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:612
bool typeNORMAL() const
Definition Out.h:900
void progressEnd(const std::string &id, const std::string &label, bool error=false)
Definition Out.h:792
void gap()
NORMAL: An empty line.
Definition Out.h:562
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:589
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:445
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:640
void notePar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Note: '.
Definition Out.h:599
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:529
virtual unsigned termwidth() const
Width for formatted output [0==unlimited].
Definition Out.h:919
void errorPar(const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:621
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:549
Verbosity
Verbosity levels.
Definition Out.h:428
@ QUIET
Only important messages (no progress or status, only the result).
Definition Out.h:429
@ NORMAL
Default output verbosity level.
Definition Out.h:430
@ HIGH
More detailed description of the operations.
Definition Out.h:432
@ DEBUG
Definition Out.h:433
void printRichText(std::string text, unsigned indent_r=0U)
Definition Out.h:564
virtual void setUseColors(bool yesno)
Hint for a handler whether config would allow to use colors.
Definition Out.h:891
Verbosity _verbosity
Definition Out.h:942
static constexpr Type TYPE_NONE
Definition Out.h:444
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:509
virtual bool progressFilter()
Determine whether to show progress.
Definition Out.cc:123
TypeBit type() const
Return the type of the instance.
Definition Out.h:895
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:133
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:128
unsigned PromptId
Definition Out.h:447
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:512
virtual void infoLine(const TermLine &msg_r, Verbosity verbosity_r=NORMAL, Type mask_r=TYPE_ALL)
info taking a TermLine
Definition Out.h:644
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:120
bool typeXML() const
Definition Out.h:902
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:574
TypeBit
Known output types implemented by derived classes.
Definition Out.h:438
@ TYPE_XML
xml output
Definition Out.h:440
@ TYPE_NORMAL
plain text output
Definition Out.h:439
void taggedPar(const TText &tag_r, const Text &text_r, ParFormat format_r=ParFormat())
Definition Out.h:593
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:943
void errorPar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Error: '.
Definition Out.h:617
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:898
ZYPP_DECLARE_FLAGS(Type, TypeBit)
Example: PromptOptions popts; popts.setOptions(_("y/n/p"), 0 / * default reply * /); popts....
Class representing an application (appdata.xml)
Definition Application.h:28
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:153
Maintain [min,max] and counter (value) for progress counting.
value_type reportValue() const
void name(const std::string &name_r)
Set counter name.
Url manipulation class.
Definition Url.h:93
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition String.h:31
Definition Arch.h:364
TableHeader asTableHeader< void >()
Definition Out.h:144
detail::ListLayoutInit< true, true, true, 0U > DefaultGapedListLayout
one element per line, no indent, gaped
Definition Out.h:109
void xmlWriteContainer(std::ostream &str_r, const TContainer &container_r, const TFormater &formater_r)
Write XML formatted container to stream.
Definition Out.h:334
TableLayout DefaultTableLayout
Simple Table.
Definition Out.h:123
detail::ListLayoutInit< true, true, true, 2U > IndentedGapedListLayout
one element per line, indented, gaped
Definition Out.h:111
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:324
detail::ListLayoutInit< false, true, false, 2U > CompressedListLayout
multiple elements per line, indented
Definition Out.h:112
detail::ListLayoutInit< true, true, false, 0U > DefaultListLayout
one element per line, no indent
Definition Out.h:108
static constexpr unsigned termwidthUnlimited
Definition Out.h:74
detail::ListLayoutInit< true, true, false, 2U > IndentedListLayout
one element per line, indented
Definition Out.h:110
detail::ListLayoutInit< true, false, false, 0U > XmlListLayout
Definition Out.h:107
std::string asListElement(const std::string &val_r)
Definition Out.h:136
unsigned defaultTermwidth()
Definition Out.cc:38
std::string asXmlListElement(const std::string &val_r)
Definition Out.h:130
ColorString tagWarning()
translated "Warning:" warning color
Definition Out.cc:28
ColorString tagNote()
translated "Note:" highlighted
Definition Out.cc:26
const char * qContinue()
translated "Continue?"
Definition Out.cc:32
bool endsOnWS(const std::string &str_r)
Whether the str_r ends with a WS.
Definition Out.h:60
ColorString tagError()
translated "Error:" error color
Definition Out.cc:30
std::string join(const Tltext &ltext, const Trtext &rtext, const char *sep=" ")
Simple join of two string types.
Definition Out.h:56
const char * optBlankAfter(const std::string &str_r)
Definition Out.h:68
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
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:45
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
std::string numstring(char n, int w=0)
Definition String.h:290
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition String.h:140
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
Definition Xml.h:204
Convenience class Error reporting.
Definition Out.h:1146
std::string _hint
Definition Out.h:1171
Error(int exitcode_r, const zypp::Exception &ex_r, std::string hint_r=std::string())
Definition Out.h:1155
static std::string combine(std::string &&msg_r, const zypp::Exception &ex_r)
Definition Out.cc:164
std::string _msg
Definition Out.h:1170
Error(int exitcode_r, std::string msg_r, std::string hint_r=std::string())
Definition Out.h:1151
int report(Application &app_r) const
Default way of processing a caught Error exception.
Definition Out.cc:155
Error(int exitcode_r, std::string msg_r, const zypp::Exception &ex_r, std::string hint_r=std::string())
Definition Out.h:1159
Error(int exitcode_r)
Definition Out.h:1147
std::ostream & stream()
Definition Out.h:671
std::unique_ptr< std::ostringstream > _str
Definition Out.h:675
Info(Out::Info &&rhs) noexcept
Definition Out.h:656
std::ostream & operator<<(const Tp &val)
Definition Out.h:665
Info(Out &out_r)
Definition Out.h:651
Less common Paragraph formats.
Definition Out.h:570
Convenience base class storing the back reference to Out.
Definition Out.h:462
ParentOut(Out &out_r)
Definition Out.h:463
Indicator type for ctor not drawing an initial start bar.
Definition Out.h:986
ProgressData::ReceiverFnc printing to a ProgressBar.
Definition Out.h:1090
Print(ProgressBar &bar_r)
Definition Out.h:1091
bool operator()(const zypp::ProgressData &progress_r)
Definition Out.h:1092
XmlNode with optional normal text headline (NL appended)
Definition Out.h:519
TitleNode(XmlNode &&node_r, const std::string &title_r="")
Definition Out.h:520
XML only: RAII writing a XML nodes start/end tag.
Definition Out.h:480
zypp::scoped_ptr< zypp::xmlout::Node > _node
Definition Out.h:500
zypp::xmlout::Node::Attr Attr
Definition Out.h:481
XmlNode(XmlNode &&rhs) noexcept
Move ctor.
Definition Out.h:497
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:484
XmlNode(Out &out_r, const std::string &name_r, Attr attr_r)
Convenience ctor for one attribute pair.
Definition Out.h:492
TermLine(char exp_r)
Definition Out.h:354
TermLine(SplitFlags flags_r, char exp_r)
Definition Out.h:352
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:377
TermLine(SplitFlags flags_r)
Definition Out.h:353
zypp::DefaultIntegral< char,' '> expHint
Definition Out.h:358
zypp::DefaultIntegral< int,-1 > percentHint
Definition Out.h:359
std::string get() const
Return plain line made of lhs + rhs.
Definition Out.h:366
zypp::str::Str rhs
Definition Out.h:362
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:374
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:380
SplitFlags flagsHint
Definition Out.h:357
zypp::str::Str lhs
Definition Out.h:361
Default representation of types in Lists [asListElement].
Definition Out.h:167
DefaultListLayout NormalLayout
Definition Out.h:168
std::string listElement(const Tp &val_r) const
Definition Out.h:171
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:225
void printAndCount(const std::string &element_r) const
Definition Out.h:271
const ListLayout & _layout
Definition Out.h:279
const unsigned _linewidth
desired line width
Definition Out.h:281
const std::string _indent
Definition Out.h:282
bool fitsOnLine(unsigned size_r) const
Definition Out.h:268
void operator<<(Tp &&val_r) const
Definition Out.h:240
Writer(std::ostream &str_r, const ListLayout &layout_r, const TFormater &formater_r)
Definition Out.h:228
std::ostream & _str
Definition Out.h:278
const TFormater & _formater
Definition Out.h:280
bool _singleline
one list element per line
Definition Out.h:95
unsigned _indent
amount of indent
Definition Out.h:98
bool _gaped
add extra NL before element (if singleline)
Definition Out.h:97
bool _wrapline
fold lines longer than _linewidth
Definition Out.h:96
ListLayout(bool singleline_r, bool wrapline_r, bool gaped_r, unsigned indent_r)
Definition Out.h:89
Special list formater writing a Table [asTableHeader|asTableRow].
Definition Out.h:180
TableHeader header() const
Definition Out.h:183
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:187
DefaultTableLayout NormalLayout
Definition Out.h:181
Write out a Table according to the layout.
Definition Out.h:292
const TableLayout & _layout
Definition Out.h:316
std::ostream & _str
Definition Out.h:315
void operator<<(Tp &&val_r) const
Definition Out.h:311
Writer(std::ostream &str_r, const TableLayout &layout_r, const TFormater &formater_r)
Definition Out.h:295
const TFormater & _formater
Definition Out.h:317
Basic table layout.
Definition Out.h:119
XmlFormaterAdaptor(const TFormater &formater_r)
Definition Out.h:205
std::string listElement(const Tp &val_r) const
Definition Out.h:202
const TFormater & _formater
Definition Out.h:209
XmlListLayout NormalLayout
Definition Out.h:199
XML representation of types in container [asXmlListElement].
Definition Out.h:156
std::string xmlListElement(const Tp &val_r) const
Definition Out.h:158
std::string asXmlListElement(const Tp &val_r)
XML representation of types [no default].
Convenient building of std::string with boost::format.
Definition String.h:254
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:213
const std::ostream & stream() const
Definition String.h:225
NodeAttr Attr
Definition Xml.h:87
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177