basic choices view

This commit is contained in:
Tristan Krause 2019-04-05 08:33:31 +02:00
parent 9f4aebef64
commit d508c308b5
10 changed files with 69 additions and 53 deletions

View file

@ -23,11 +23,24 @@ WINDOW* View::getWinContext()
return win;
}
void View::addCall(std::function<void(int)> call)
// from: https://stackoverflow.com/a/37454181
std::vector<std::string> View::str_split(const std::string& str, const std::string delim)
{
calls.push_back(call);
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
do
{
pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev);
if (!token.empty()) tokens.push_back(token);
prev = pos + delim.length();
}
while (pos < str.length() && prev < str.length());
return tokens;
}
void View::setTitle(std::string title)
{
this->title = title;
@ -59,20 +72,3 @@ void View::repaint()
refresh();
wrefresh(win);
}
// from: https://stackoverflow.com/a/37454181
std::vector<std::string> View::str_split(const std::string& str, const std::string delim)
{
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
do
{
pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos-prev);
if (!token.empty()) tokens.push_back(token);
prev = pos + delim.length();
}
while (pos < str.length() && prev < str.length());
return tokens;
}