27#include <zypp-core/base/DefaultIntegral> 
   28#include <zypp-core/base/DtorReset> 
   31#include <zypp-core/ui/ProgressData> 
   38#include <zypp-tui/output/PromptOptions> 
   55  template <
class Tltext, 
class Trtext>
 
   56  inline std::string 
join( 
const Tltext & ltext, 
const Trtext & rtext, 
const char * sep = 
" " )
 
 
   60  inline bool endsOnWS( 
const std::string & str_r )
 
   64    { 
int l = *str_r.rbegin(); 
if ( ::strchr( 
" \n\t", l ) ) ret = 
true; }
 
 
   69  { 
return( 
endsOnWS( str_r ) ? 
"" : 
" " ); }
 
 
   87    template <
class TFormater> 
struct Writer;
 
   89    ListLayout( 
bool singleline_r, 
bool wrapline_r, 
bool gaped_r, 
unsigned indent_r )
 
 
 
  103    template <
bool singleline_, 
bool wrapline_, 
bool gaped_, 
unsigned indent_>
 
 
  120    template <
class TFormater> 
struct Writer;
 
 
  136  inline std::string 
asListElement( 
const std::string & val_r )    { 
return val_r; }
 
  140  template <
class Tp = 
void>
 
  196  template <
class TFormater>
 
  203    { 
return _formater.xmlListElement( val_r ); }
 
 
 
  223  template <
class TFormater>
 
  242      const std::string & element( 
_formater.listElement( std::forward<Tp>(val_r) ) );
 
 
  272    { 
_cpos += element_r.size(); 
_str << element_r; }
 
 
 
  290  template <
class TFormater>
 
  312    { 
_t.add( 
_formater.row( std::forward<Tp>(val_r) ) ); }
 
 
 
  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() )
 
  326    typedef typename TLayout::template Writer<TFormater> Writer;
 
  327    Writer writer( str_r, layout_r, formater_r );
 
  328    for ( 
auto && el : container_r )
 
 
  333  template <
class TContainer, 
class TFormater>
 
  334  void xmlWriteContainer( std::ostream & str_r, 
const TContainer & container_r, 
const TFormater & formater_r )
 
 
  367  { 
return std::string(
lhs) + std::string(
rhs); }
 
 
  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 
 
  377  std::string 
get( 
unsigned width_r, 
char exp_r )
 const 
 
  380  std::string 
get( 
unsigned width_r )
 const 
 
 
  484    XmlNode( 
Out & out_r, 
const std::string & name_r, 
const std::initializer_list<Attr> & attrs_r = {} )
 
  488      { _node.reset( new zypp::xmlout::Node( std::cout, name_r, attrs_r ) ); }
 
 
  493    : 
XmlNode( out_r, name_r, { std::move(attr_r) } )
 
 
  500    zypp::scoped_ptr<zypp::xmlout::Node> 
_node;
 
 
  509  void xmlNode( 
const std::string & name_r, 
const std::initializer_list<XmlNode::Attr> & attrs_r = {} )
 
 
  513  { 
xmlNode( name_r, { std::move(attr_r) } ); }
 
 
  522    { 
if ( 
out().
typeNORMAL() && ! title_r.empty() ) std::cout << title_r << std::endl; }
 
 
 
  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 )
 
  537        writeContainer( std::cout, container_r, formater_r );
 
 
  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 ); }
 
 
  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 ); }
 
 
  573  template <
class Text>
 
  582  template <
class Text>
 
  584  { 
par( 0, text_r, format_r ); }
 
 
  588  template <
class TText, 
class Text>
 
  592  template <
class TText, 
class Text>
 
  594  { 
taggedPar( 0, tag_r, text_r, format_r ); }
 
 
  598  template <
class Text>
 
  602  template <
class Text>
 
  604  { 
notePar( 0, text_r, format_r ); }
 
 
  607  template <
class Text>
 
  611  template <
class Text>
 
  616  template <
class Text>
 
  620  template <
class Text>
 
  622  { 
errorPar( 0, text_r, format_r ); }
 
 
  645  { 
info( msg_r.
get(), verbosity_r, mask_r ); }
 
 
  653      , 
_str( new 
std::ostringstream )
 
 
  658      , 
_str( std::move(rhs._str) )
 
 
  666    { 
return (*
_str) << val;  }
 
 
  668    operator std::ostream &()
 
 
  675      std::unique_ptr<std::ostringstream> 
_str; 
 
 
  686    outstr.
rhs << 
' ' << rmsg;
 
 
  695    outstr.
rhs << 
" (" << hint << 
')';
 
 
  726  virtual void error(
const std::string & problem_desc, 
const std::string & hint = 
"") = 0;
 
  737                     const std::string & problem_desc,
 
  738                     const std::string & hint = 
"") = 0;
 
  759                             const std::string & label,
 
  760                             bool is_tick = 
false) = 0;
 
  772                        const std::string & label,
 
  786                           const std::string & label,
 
  787                           const std::string & donetag,
 
  788                           bool error = 
false) = 0;
 
  852                      const std::string & 
prompt,
 
  854                      const std::string & startdesc = 
"") = 0;
 
  881#define SCOPED_VERBOSITY( OUT, LEVEL ) const auto & raii __attribute__ ((__unused__))( (OUT).scopedVerbosity( LEVEL )) 
  912      ret = desired_r ? desired_r : 150U;
 
  913    else if ( desired_r < ret )
 
 
 
  995  ProgressBar( 
Out & out_r, 
NoStartBar, std::string  progressId_r, 
const std::string & label_r, 
unsigned current_r = 0, 
unsigned total_r = 0 )
 
 1001    else if ( current_r )
 
 
 1015  ProgressBar( 
Out & out_r, 
const std::string & progressId_r, 
const std::string & label_r, 
unsigned current_r = 0, 
unsigned total_r = 0 )
 
 
 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 )
 
 
 1043  void print( 
const std::string & label_r )
 
 
 1059  void error( 
const std::string & label_r )
 
 
 1098  std::string 
outLabel( 
const std::string & msg_r )
 const 
 
 1102  { 
int ret = 1; 
while ( num_r /= 10 ) ++ret; 
return ret; }
 
 
 
 1151  Error( 
int exitcode_r, std::string msg_r, std::string hint_r = std::string() )
 
 
 
Convenience class for progress output.
ProgressBar(Out &out_r, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
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.
zypp::ProgressData * operator->()
zypp::ProgressData & operator*()
void print()
Immediately print the progress bar not waiting for a new trigger.
void errorreset()
Reset any error condition.
const zypp::ProgressData * operator->() const
zypp::ProgressData _progress
std::string outLabel(const std::string &msg_r) const
~ProgressBar()
Dtor displays final progress bar.
void print(const std::string &label_r)
void error(ProgressEnd donetag_r=ProgressEnd::error)
Explicitly indicate the error condition for the final progress bar.
ProgressBar(Out &out_r, NoStartBar, const std::string &label_r, unsigned current_r=0, unsigned total_r=0)
std::optional< ProgressEnd > _donetag
void error(const char *label_r)
static constexpr NoStartBar noStartBar
Indicator argument for ctor not drawing an initial start bar.
int numDigits(unsigned num_r) const
const zypp::ProgressData & operator*() const
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.
void error(const std::string &label_r)
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% ...
void warningPar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Warning: '.
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.
Verbosity verbosity() const
Get current verbosity.
zypp::DtorReset scopedVerbosity(Verbosity verbosity_r)
Return RAII class for exception safe scoped verbosity change.
Out(TypeBit type, Verbosity verbosity=NORMAL)
void par(const Text &text_r, ParFormat format_r=ParFormat())
unsigned defaultFormatWidth(unsigned desired_r=0) const
Terminal width or 150 if unlimited.
void setVerbosity(Verbosity verbosity)
Set current verbosity.
void infoLRHint(const std::string &lmsg, const std::string &hint, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)
Info message with R-adjusted "(hint)".
void notePar(const Text &text_r, ParFormat format_r=ParFormat())
void warningPar(const Text &text_r, ParFormat format_r=ParFormat())
void progressEnd(const std::string &id, const std::string &label, bool error=false)
void gap()
NORMAL: An empty line.
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 ' '.
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
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)
void notePar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Note: '.
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 ...
virtual unsigned termwidth() const
Width for formatted output [0==unlimited].
void errorPar(const Text &text_r, ParFormat format_r=ParFormat())
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...
Verbosity
Verbosity levels.
@ QUIET
Only important messages (no progress or status, only the result).
@ NORMAL
Default output verbosity level.
@ HIGH
More detailed description of the operations.
void printRichText(std::string text, unsigned indent_r=0U)
virtual void setUseColors(bool yesno)
Hint for a handler whether config would allow to use colors.
static constexpr Type TYPE_NONE
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.
virtual bool progressFilter()
Determine whether to show progress.
TypeBit type() const
Return the type of the instance.
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.
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.
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)
virtual void infoLine(const TermLine &msg_r, Verbosity verbosity_r=NORMAL, Type mask_r=TYPE_ALL)
info taking a TermLine
virtual void progress(const std::string &id, const std::string &label, int value=-1)=0
Progress report for an on-going operation.
void par(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph of text, optionally indented, or without leading gap.
TypeBit
Known output types implemented by derived classes.
@ TYPE_NORMAL
plain text output
void taggedPar(const TText &tag_r, const Text &text_r, ParFormat format_r=ParFormat())
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.
void errorPar(size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat())
Paragraph tagged with 'Error: '.
virtual void dwnldProgressStart(const zypp::Url &uri)=0
Reoprt start of a download.
bool type(TypeBit type_r) const
Test for a specific type.
ZYPP_DECLARE_FLAGS(Type, TypeBit)
Example:  PromptOptions popts; popts.setOptions(_("y/n/p"), 0 / * default reply * /); popts....
Class representing an application (appdata.xml)
Integral type with defined initial value when default constructed.
Assign a vaiable a certain value when going out of scope.
Base class for Exception.
Maintain [min,max] and counter (value) for progress counting.
value_type reportValue() const
void name(const std::string &name_r)
Set counter name.
TableHeader asTableHeader< void >()
detail::ListLayoutInit< true, true, true, 0U > DefaultGapedListLayout
one element per line, no indent, gaped
void xmlWriteContainer(std::ostream &str_r, const TContainer &container_r, const TFormater &formater_r)
Write XML formatted container to stream.
TableLayout DefaultTableLayout
Simple Table.
detail::ListLayoutInit< true, true, true, 2U > IndentedGapedListLayout
one element per line, indented, gaped
void writeContainer(std::ostream &str_r, const TContainer &container_r, const TFormater &formater_r, const TLayout &layout_r=TLayout())
Write formatted container to stream.
detail::ListLayoutInit< false, true, false, 2U > CompressedListLayout
multiple elements per line, indented
detail::ListLayoutInit< true, true, false, 0U > DefaultListLayout
one element per line, no indent
static constexpr unsigned termwidthUnlimited
detail::ListLayoutInit< true, true, false, 2U > IndentedListLayout
one element per line, indented
detail::ListLayoutInit< true, false, false, 0U > XmlListLayout
std::string asListElement(const std::string &val_r)
unsigned defaultTermwidth()
std::string asXmlListElement(const std::string &val_r)
ColorString tagWarning()
translated "Warning:" warning color
ColorString tagNote()
translated "Note:" highlighted
const char * qContinue()
translated "Continue?"
bool endsOnWS(const std::string &str_r)
Whether the str_r ends with a WS.
ColorString tagError()
translated "Error:" error color
std::string join(const Tltext <ext, const Trtext &rtext, const char *sep=" ")
Simple join of two string types.
const char * optBlankAfter(const std::string &str_r)
std::ostream & printRichText(std::ostream &str, std::string text, unsigned indent_r=0U, unsigned width_r=0U)
Print [Rich]Text optionally indented.
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.
ProgressEnd
ProgressBars default end tags.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
std::string numstring(char n, int w=0)
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Convenience class Error reporting.
Error(int exitcode_r, const zypp::Exception &ex_r, std::string hint_r=std::string())
static std::string combine(std::string &&msg_r, const zypp::Exception &ex_r)
Error(int exitcode_r, std::string msg_r, std::string hint_r=std::string())
int report(Application &app_r) const
Default way of processing a caught Error exception.
Error(int exitcode_r, std::string msg_r, const zypp::Exception &ex_r, std::string hint_r=std::string())
std::unique_ptr< std::ostringstream > _str
Info(Out::Info &&rhs) noexcept
std::ostream & operator<<(const Tp &val)
Convenience base class storing the back reference to Out.
Indicator type for ctor not drawing an initial start bar.
ProgressData::ReceiverFnc printing to a ProgressBar.
Print(ProgressBar &bar_r)
bool operator()(const zypp::ProgressData &progress_r)
XmlNode with optional normal text headline (NL appended)
TitleNode(XmlNode &&node_r, const std::string &title_r="")
XML only: RAII writing a XML nodes start/end tag.
zypp::scoped_ptr< zypp::xmlout::Node > _node
zypp::xmlout::Node::Attr Attr
XmlNode(XmlNode &&rhs) noexcept
Move ctor.
XmlNode(Out &out_r, const std::string &name_r, const std::initializer_list< Attr > &attrs_r={})
Ctor taking nodename and attribute list.
XmlNode(Out &out_r, const std::string &name_r, Attr attr_r)
Convenience ctor for one attribute pair.
TermLine(SplitFlags flags_r, char exp_r)
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...
TermLine(SplitFlags flags_r)
zypp::DefaultIntegral< char,' '> expHint
zypp::DefaultIntegral< int,-1 > percentHint
std::string get() const
Return plain line made of lhs + rhs.
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...
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...
Write out a List according to the layout.
void printAndCount(const std::string &element_r) const
const ListLayout & _layout
const unsigned _linewidth
desired line width
const std::string _indent
bool fitsOnLine(unsigned size_r) const
void operator<<(Tp &&val_r) const
Writer(std::ostream &str_r, const ListLayout &layout_r, const TFormater &formater_r)
const TFormater & _formater
bool _singleline
one list element per line
unsigned _indent
amount of indent
bool _gaped
add extra NL before element (if singleline)
bool _wrapline
fold lines longer than _linewidth
ListLayout(bool singleline_r, bool wrapline_r, bool gaped_r, unsigned indent_r)
Write out a Table according to the layout.
const TableLayout & _layout
void operator<<(Tp &&val_r) const
Writer(std::ostream &str_r, const TableLayout &layout_r, const TFormater &formater_r)
const TFormater & _formater
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
const std::ostream & stream() const
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)