libzypp  17.35.19
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 
23 namespace ztui {
24 
39  {
40  public:
41  using StrVector = std::vector<std::string>;
42 
47 
49  PromptOptions( StrVector options_r, unsigned defaultOpt_r );
50 
59  PromptOptions( const std::string & optionstr_r, unsigned defaultOpt_r );
60 
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:
105  unsigned _default = 0;
109  std::set<unsigned> _disabled;
114  int _shown_count = -1;
115  };
116 
117 
118 
119 }
120 
121 #endif // ZYPP_TUI_OUTPUT_PROMPTOPTIONS_H_INCLUDED
int _shown_count
Number of options to show (the rest will still be available and visible through &#39;?&#39; help).
std::vector< int > getReplyMatches(const std::string &reply_r) const
Return the indices of option string matches (lowercase/prefix or #NUM).
void enable(unsigned opt)
Definition: promptoptions.h:86
Colored string if do_colors.
Definition: ansi.h:496
void setShownCount(unsigned count)
Definition: promptoptions.h:93
bool isYesNoPrompt() const
unsigned defaultOpt() const
Definition: promptoptions.h:68
void disable(unsigned opt)
Definition: promptoptions.h:84
Example: PromptOptions popts; popts.setOptions(_("y/n/p"), 0 / * default reply * /); popts...
Definition: promptoptions.h:38
PromptOptions()
Default c-tor.
Definition: promptoptions.h:46
unsigned shownCount() const
Definition: promptoptions.h:91
bool isEnabled(unsigned opt) const
Definition: promptoptions.h:80
std::set< unsigned > _disabled
set of options to ignore
const StrVector & options() const
Definition: promptoptions.h:64
unsigned _default
index of the default option
bool isDisabled(unsigned opt) const
Definition: promptoptions.h:82
bool helpEmpty() const
Definition: promptoptions.h:78
void setOptionHelp(unsigned opt, const std::string &help_str)
std::string replyMatchesStr(const std::vector< int > &matches_r) const
The returned reply matches as &#39;(,)&#39; list.
ColorString optionString() const
Option string (may have embedded color codes)
const std::string & optionHelp(unsigned opt) const
Definition: promptoptions.h:74
bool empty() const
Definition: promptoptions.h:71
StrVector _opt_help
help strings corresponding to options
void setOptions(StrVector options_r, unsigned defaultOpt_r)
std::vector< std::string > StrVector
Definition: promptoptions.h:41
StrVector _options
option strings