libzypp 17.37.17
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
22
23namespace 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; }
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
void disable(unsigned opt)
unsigned _default
index of the default option
void setShownCount(unsigned count)
const StrVector & options() const
unsigned shownCount() const
bool helpEmpty() const
const std::string & optionHelp(unsigned opt) const
bool isYesNoPrompt() const
ColorString optionString() const
Option string (may have embedded color codes)
int _shown_count
Number of options to show (the rest will still be available and visible through '?
std::vector< int > getReplyMatches(const std::string &reply_r) const
Return the indices of option string matches (lowercase/prefix or NUM).
std::string replyMatchesStr(const std::vector< int > &matches_r) const
The returned reply matches as '(,)' list.
PromptOptions()
Default c-tor.
StrVector _opt_help
help strings corresponding to options
bool isDisabled(unsigned opt) const
unsigned defaultOpt() const
std::set< unsigned > _disabled
set of options to ignore
bool isEnabled(unsigned opt) const
StrVector _options
option strings
std::vector< std::string > StrVector
void setOptionHelp(unsigned opt, const std::string &help_str)
void enable(unsigned opt)
void setOptions(StrVector options_r, unsigned defaultOpt_r)
Colored string if do_colors.
Definition ansi.h:497