libzypp: zypp-tui/output/promptoptions.h Source File

libzypp 17.38.6

promptoptions.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* Strictly for internal use!
12*/
13
14#ifndef ZYPP_TUI_OUTPUT_PROMPTOPTIONS_H_INCLUDED
15#define ZYPP_TUI_OUTPUT_PROMPTOPTIONS_H_INCLUDED
16
17#include <vector>
18#include <string>
19#include <set>
20
21#include <zypp-tui/utils/colors.h>
22
23namespace ztui {
24
38 class PromptOptions
39 {
40 public:
41 using StrVector = std::vector<std::string>;
42
46 PromptOptions() {};
47
49 PromptOptions( StrVector options_r, unsigned defaultOpt_r );
50
59 PromptOptions( const std::string & optionstr_r, unsigned defaultOpt_r );
60
62 ~PromptOptions();
63
64 const StrVector & options() const { return _options; }
65 void setOptions( StrVector options_r, unsigned defaultOpt_r );
66 void setOptions( const std::string & optionstr_r, unsigned defaultOpt_r );
67
68 unsigned defaultOpt() const { return _default; }
70 ColorString optionString() const;
71 bool empty() const { return _options.empty(); }
72 bool isYesNoPrompt() const;
73
74 const std::string & optionHelp(unsigned opt) const
75 { static std::string empty; return opt < _opt_help.size() ? _opt_help[opt] : empty; }
76 //const std::string getOptionHelp(const std::string & opt_str);
77 void setOptionHelp(unsigned opt, const std::string & help_str);
78 bool helpEmpty() const { return _opt_help.empty(); }
79
80 bool isEnabled(unsigned opt) const
81 { return !isDisabled(opt); }
82 bool isDisabled(unsigned opt) const
83 { return _disabled.count(opt); }
84 void disable(unsigned opt)
85 { _disabled.insert(opt); }
86 void enable(unsigned opt)
87 { _disabled.erase(opt); }
88 void enableAll()
89 { _disabled.clear(); }
90
91 unsigned shownCount() const
92 { return _shown_count; }
93 void setShownCount(unsigned count)
94 { _shown_count = count; }
95
97 std::vector<int> getReplyMatches( const std::string & reply_r ) const;
99 std::string replyMatchesStr( const std::vector<int> & matches_r ) const;
100
101 private:
103 StrVector _options;
105 unsigned _default = 0;
107 StrVector _opt_help;
109 std::set<unsigned> _disabled;
114 int _shown_count = -1;
115 };
116
117
118
119}
120
121#endif // ZYPP_TUI_OUTPUT_PROMPTOPTIONS_H_INCLUDED
ztui::PromptOptions::disable
void disable(unsigned opt)
Definition promptoptions.h:84
ztui::PromptOptions::_default
unsigned _default
index of the default option
Definition promptoptions.h:105
ztui::PromptOptions::setShownCount
void setShownCount(unsigned count)
Definition promptoptions.h:93
ztui::PromptOptions::options
const StrVector & options() const
Definition promptoptions.h:64
ztui::PromptOptions::shownCount
unsigned shownCount() const
Definition promptoptions.h:91
ztui::PromptOptions::helpEmpty
bool helpEmpty() const
Definition promptoptions.h:78
ztui::PromptOptions::optionHelp
const std::string & optionHelp(unsigned opt) const
Definition promptoptions.h:74
ztui::PromptOptions::enableAll
void enableAll()
Definition promptoptions.h:88
ztui::PromptOptions::isYesNoPrompt
bool isYesNoPrompt() const
Definition promptoptions.cc:193
ztui::PromptOptions::optionString
ColorString optionString() const
Option string (may have embedded color codes).
Definition promptoptions.cc:52
ztui::PromptOptions::_shown_count
int _shown_count
Number of options to show (the rest will still be available and visible through '?
Definition promptoptions.h:114
ztui::PromptOptions::getReplyMatches
std::vector< int > getReplyMatches(const std::string &reply_r) const
Return the indices of option string matches (lowercase/prefix or NUM).
Definition promptoptions.cc:117
ztui::PromptOptions::~PromptOptions
~PromptOptions()
D-tor.
Definition promptoptions.cc:28
ztui::PromptOptions::replyMatchesStr
std::string replyMatchesStr(const std::vector< int > &matches_r) const
The returned reply matches as '(,)' list.
Definition promptoptions.cc:181
ztui::PromptOptions::PromptOptions
PromptOptions()
Default c-tor.
Definition promptoptions.h:46
ztui::PromptOptions::_opt_help
StrVector _opt_help
help strings corresponding to options
Definition promptoptions.h:107
ztui::PromptOptions::isDisabled
bool isDisabled(unsigned opt) const
Definition promptoptions.h:82
ztui::PromptOptions::defaultOpt
unsigned defaultOpt() const
Definition promptoptions.h:68
ztui::PromptOptions::_disabled
std::set< unsigned > _disabled
set of options to ignore
Definition promptoptions.h:109
ztui::PromptOptions::isEnabled
bool isEnabled(unsigned opt) const
Definition promptoptions.h:80
ztui::PromptOptions::_options
StrVector _options
option strings
Definition promptoptions.h:103
ztui::PromptOptions::StrVector
std::vector< std::string > StrVector
Definition promptoptions.h:41
ztui::PromptOptions::empty
bool empty() const
Definition promptoptions.h:71
ztui::PromptOptions::setOptionHelp
void setOptionHelp(unsigned opt, const std::string &help_str)
Definition promptoptions.cc:97
ztui::PromptOptions::enable
void enable(unsigned opt)
Definition promptoptions.h:86
ztui::PromptOptions::setOptions
void setOptions(StrVector options_r, unsigned defaultOpt_r)
Definition promptoptions.cc:33
ztui::ansi::ColorString
Colored string if do_colors.
Definition ansi.h:497
colors.h
ztui
Definition application.cc:13