-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringPrompt.cc
More file actions
29 lines (23 loc) · 911 Bytes
/
Copy pathStringPrompt.cc
File metadata and controls
29 lines (23 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "StringPrompt.h"
#include "Colors.h"
#include "Log.h"
#include <iostream>
#include <sstream>
StringPrompt::StringPrompt(const string& prompt, const StringList& choices) : _prompt(prompt), _choices(choices) {}
StringPrompt::~StringPrompt() {}
StringPrompt::StringList StringPrompt::execute() const {
StringList responses;
responses.reserve(_choices.size());
Log::log("%s%s" __RESET "\n", Style::New(Formatting::Color::YELLOW).with(Formatting::Format::BOLD).text().c_str(), _prompt.c_str());
for(int i = 0;i<_choices.size();i++) {
Log::log(" %s%s " __RESET, Style::New(Formatting::Color::GREEN).with(Formatting::Format::BOLD).text().c_str(), _choices[i].c_str());
responses.push_back(getResponse());
}
Log::log("\n");
return responses;
}
string StringPrompt::getResponse() const {
string line;
std::getline(std::cin, line);
return line;
}