libzypp 17.37.17
|
Base class for producing common (for now) zypper output. More...
#include <zypp-tui/output/Out.h>
Classes | |
class | Error |
Convenience class Error reporting. More... | |
struct | Info |
class | ParentOut |
Convenience base class storing the back reference to Out. More... | |
struct | ParFormat |
Less common Paragraph formats. More... | |
class | ProgressBar |
Convenience class for progress output. More... | |
class | TitleNode |
XmlNode with optional normal text headline (NL appended) More... | |
class | XmlNode |
XML only: RAII writing a XML nodes start/end tag. More... |
Public Types | |
enum | Verbosity { QUIET = 0 , NORMAL = 1 , HIGH = 2 , DEBUG = 3 } |
Verbosity levels. More... | |
enum | TypeBit { TYPE_NORMAL = 0x01<<0 , TYPE_XML = 0x01<<1 } |
Known output types implemented by derived classes. More... | |
using | PromptId = unsigned |
Public Member Functions | |
ZYPP_DECLARE_FLAGS (Type, TypeBit) | |
virtual | ~Out () |
void | xmlNode (const std::string &name_r, const std::initializer_list< XmlNode::Attr > &attrs_r={}) |
XML only: Write a leaf node without PCDATA. | |
void | xmlNode (const std::string &name_r, XmlNode::Attr attr_r) |
template<class TContainer, class TFormater = out::ListFormater> | |
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% in title_r with size. | |
template<class TContainer, class TFormater = out::TableFormater> | |
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% in title_r with size. | |
void | gap () |
NORMAL: An empty line. | |
void | printRichText (std::string text, unsigned indent_r=0U) |
template<class Text> | |
void | par (size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat()) |
Paragraph of text, optionally indented, or without leading gap. | |
template<class Text> | |
void | par (const Text &text_r, ParFormat format_r=ParFormat()) |
template<class TText, class Text> | |
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 ' '. | |
template<class TText, class Text> | |
void | taggedPar (const TText &tag_r, const Text &text_r, ParFormat format_r=ParFormat()) |
template<class Text> | |
void | notePar (size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat()) |
Paragraph tagged with 'Note: '. | |
template<class Text> | |
void | notePar (const Text &text_r, ParFormat format_r=ParFormat()) |
template<class Text> | |
void | warningPar (size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat()) |
Paragraph tagged with 'Warning: '. | |
template<class Text> | |
void | warningPar (const Text &text_r, ParFormat format_r=ParFormat()) |
template<class Text> | |
void | errorPar (size_t indent_r, const Text &text_r, ParFormat format_r=ParFormat()) |
Paragraph tagged with 'Error: '. | |
template<class Text> | |
void | errorPar (const Text &text_r, ParFormat format_r=ParFormat()) |
virtual void | info (const std::string &msg, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)=0 |
Show an info message. | |
void | info (std::string msg, const std::string &msg2, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL) |
virtual void | infoLine (const TermLine &msg_r, Verbosity verbosity_r=NORMAL, Type mask_r=TYPE_ALL) |
info taking a TermLine | |
Info | info () |
void | infoLR (const std::string &lmsg, const std::string &rmsg, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL) |
Info message, 2 strings L/R-adjusted. | |
void | infoLRHint (const std::string &lmsg, const std::string &hint, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL) |
Info message with R-adjusted "(hint)". | |
virtual void | warning (const std::string &msg, Verbosity verbosity=NORMAL, Type mask=TYPE_ALL)=0 |
Show a warning. | |
virtual void | error (const std::string &problem_desc, const std::string &hint="")=0 |
Show an error message and an optional hint. | |
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. | |
Progress of an operation. | |
virtual void | progressStart (const std::string &id, const std::string &label, bool is_tick=false)=0 |
Start of an operation with reported progress. | |
virtual void | progress (const std::string &id, const std::string &label, int value=-1)=0 |
Progress report for an on-going operation. | |
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. | |
void | progressEnd (const std::string &id, const std::string &label, ProgressEnd donetag) |
void | progressEnd (const std::string &id, const std::string &label, bool error=false) |
Static Public Attributes | |
static constexpr Type | TYPE_NONE = Type(0x00) |
static constexpr Type | TYPE_ALL = Type(0xff) |
Protected Member Functions | |
Out (TypeBit type, Verbosity verbosity=NORMAL) |
Private Member Functions | |
template<class TContainer, class TFormater> | |
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 with size. |
Download progress with download rate | |
Verbosity | _verbosity |
const TypeBit | _type |
virtual void | dwnldProgressStart (const zypp::Url &uri)=0 |
Reoprt start of a download. | |
virtual void | dwnldProgress (const zypp::Url &uri, int value=-1, long rate=-1)=0 |
Reports download progress. | |
virtual void | dwnldProgressEnd (const zypp::Url &uri, long rate=-1, zypp::TriBool error=false)=0 |
Reports end of a download. | |
virtual void | searchResult (const Table &table_r) |
Print out a search result. | |
virtual void | prompt (PromptId id, const std::string &prompt, const PromptOptions &poptions, const std::string &startdesc="")=0 |
Prompt the user for a decision. | |
virtual void | promptHelp (const PromptOptions &poptions)=0 |
Print help for prompt, if available. | |
Verbosity | verbosity () const |
Get current verbosity. | |
void | setVerbosity (Verbosity verbosity) |
Set current verbosity. | |
zypp::DtorReset | scopedVerbosity (Verbosity verbosity_r) |
Return RAII class for exception safe scoped verbosity change. | |
virtual void | setUseColors (bool yesno) |
Hint for a handler whether config would allow to use colors. | |
TypeBit | type () const |
Return the type of the instance. | |
bool | type (TypeBit type_r) const |
Test for a specific type. | |
bool | typeNORMAL () const |
bool | typeXML () const |
unsigned | defaultFormatWidth (unsigned desired_r=0) const |
Terminal width or 150 if unlimited. | |
virtual unsigned | termwidth () const |
Width for formatted output [0==unlimited]. | |
virtual bool | mine (Type type)=0 |
Determine whether the output is intended for the particular type. | |
virtual bool | progressFilter () |
Determine whether to show progress. | |
virtual std::string | zyppExceptionReport (const zypp::Exception &e) |
Return a Exception as a string suitable for output. |
Base class for producing common (for now) zypper output.
This is an abstract class providing interface for writing output like info messages, warnings, error messages, user prompts, progress reports, and download progress reports. See descriptions of the methods for more details.
The output is produced using Out derived class instances.
// create output object
SomePointerType<Out> out;
if (options.count("xmlout"))
out = new OutXML();
else
out = new OutNormal();
out->info("output instance ready to use", Out::HIGH);
out->info("Doing foo");
try
{
foo();
out->prompt(PROMPT_FOO, "Need your action?", "y/n"); // see output/prompt.h
if (action())
out->info("result", Out::QUIET); // always show the result
else
cout << "special result" << endl; // special output must be done
// the usual way for now
}
catch(const Exception & e)
{
out->error(e, "Problem doing foo", "Do 'bar' to deal with this");
}
using ztui::Out::PromptId = unsigned |
enum ztui::Out::Verbosity |
Verbosity levels.
Enumerator | |
---|---|
QUIET | Only important messages (no progress or status, only the result). |
NORMAL | Default output verbosity level. Progress for important tasks, moderate amount of status messages, operation information, result. |
HIGH | More detailed description of the operations. |
DEBUG |
|
enum ztui::Out::TypeBit |
ztui::Out::ZYPP_DECLARE_FLAGS | ( | Type | , |
TypeBit | ) |
|
inline |
|
inline |
|
inlineprivate |
|
inline |
|
inline |
|
inline |
|
pure virtual |
Show an info message.
msg | The message to be displayed. |
verbosity | Minimal level o verbosity in which the message will be shown. Out::QUIET means the message will be always be displayed. Out::HIGH means the message will be displayed only if the current verbosity level is HIGH (-v) or DEBUG (-vv). |
mask | Determines the types of output for which is this message intended. By default, the message will be shown in all types of output. |
Implemented in ztui::OutNormal.
|
pure virtual |
Show a warning.
msg | The warning message to be displayed. |
verbosity | Minimal level o verbosity in which the message will be shown. Out::QUIET means the message will be always be displayed. Out::HIGH means the message will be displayed only if the current verbosity level is HIGH (-v) or DEBUG (-vv). |
mask | Determines the types of output for which is this message intended. By default, the message will be shown in all types of output. |
Implemented in ztui::OutNormal.
|
pure virtual |
Show an error message and an optional hint.
An error message should be shown regardless of the verbosity level.
problem_desc | Problem description (what happened) |
hint | Hint for the user (what to do, or explanation) |
Implemented in ztui::OutNormal.
|
pure virtual |
Prints the problem description caused by an exception, its cause and, optionally, a hint for the user.
e | Exception which caused the problem. |
Problem | description for the user. |
Hint | for the user how to cope with the problem. |
Implemented in ztui::OutNormal.
|
pure virtual |
Start of an operation with reported progress.
id | Identifier. Any string used to match multiple overlapping progress reports (doesn't happen now, but probably will in the future). |
label | Progress description. |
is_tick | false for known progress percentage, true for 'still alive' notifications |
Implemented in ztui::OutNormal.
|
pure virtual |
Progress report for an on-going operation.
id | Identifier. Any string used to match multiple overlapping progress reports. |
label | Progress description. |
value | Percentage value or -1 if unknown ('still alive' notification) |
Implemented in ztui::OutNormal.
|
pure virtual |
End of an operation with reported progress.
id | Identifier. Any string used to match multiple overlapping progress reports. |
label | Progress description. |
donetag | Optional string overwriting the default [done]/[error] tags. |
error | false if the operation finished with success, true otherwise. |
Implemented in ztui::OutNormal.
void ztui::Out::progressEnd | ( | const std::string & | id, |
const std::string & | label, | ||
ProgressEnd | donetag ) |
|
inline |
|
pure virtual |
Reoprt start of a download.
uri | Uri of the file to download. |
Implemented in ztui::OutNormal.
|
pure virtual |
Reports download progress.
uri | Uri of the file being downloaded. |
value | Value of the progress in percents. -1 if unknown. |
rate | Current download rate in B/s. -1 if unknown. |
Implemented in ztui::OutNormal.
|
pure virtual |
Reports end of a download.
uri | Uri of the file to download. |
rate | Average download rate at the end. -1 if unknown. |
error | Error flag - did the download finish with error? indeterminate == 'not found' |
Implemented in ztui::OutNormal.
|
virtual |
|
pure virtual |
Prompt the user for a decision.
id | Unique prompt identifier for use by machines. |
prompt | Prompt text. |
options | A PromptOptions object |
startdesc | Initial detailed description of the prompt to be prepended to the prompt text. Should be used only whe prompting for the first time and left empty when retrying after an invalid answer has been given. |
Implemented in ztui::OutNormal.
|
pure virtual |
Print help for prompt, if available.
This method should be called after '?' prompt option has been entered.
Implemented in ztui::OutNormal.
|
inline |
|
inline |
|
inline |
|
inlinevirtual |
Hint for a handler whether config would allow to use colors.
Reimplemented in ztui::OutNormal.
|
inline |
|
inline |
|
inlinevirtual |
Width for formatted output [0==unlimited].
Reimplemented in ztui::OutNormal.
|
protectedpure virtual |
Determine whether the output is intended for the particular type.
Implemented in ztui::OutNormal.
|
protectedvirtual |
|
protectedvirtual |