26Term::Result Term::prompt(
const std::string& message,
const std::string& first_option,
const std::string& second_option,
const std::string& prompt_indicator,
bool immediate)
29 std::cout << message <<
" [" << first_option <<
'/' << second_option <<
']' << prompt_indicator <<
' ' << std::flush;
33 std::cout <<
'\n' << std::flush;
47 std::cout <<
'\n' << std::flush;
52 std::cout <<
'\n' << std::flush;
57 std::cout <<
'\n' << std::flush;
62 std::cout <<
'\n' << std::flush;
67 std::cout <<
'\n' << std::flush;
68 return Result::Invalid;
79 if(key >=
'a' && key <=
'z')
81 std::cout << (char)key << std::flush;
82 input.push_back(
static_cast<char>(key));
84 else if(key >=
'A' && key <=
'Z')
86 std::cout << (char)key << std::flush;
87 input.push_back(
static_cast<char>(key.
tolower()));
96 if(input.empty() != 0)
98 std::cout <<
"\u001b[D \u001b[D" << std::flush;
104 if(input ==
"y" || input ==
"yes")
106 std::cout <<
'\n' << std::flush;
109 else if(input ==
"n" || input ==
"no")
111 std::cout <<
'\n' << std::flush;
114 else if(input.empty())
116 std::cout <<
'\n' << std::flush;
121 std::cout <<
'\n' << std::flush;
122 return Result::Invalid;
209std::string
Term::prompt_multiline(
const std::string& prompt_string, std::vector<std::string>& m_history, std::function<
bool(std::string)>& iscomplete)
225 std::vector<std::string> history = m_history;
226 std::size_t history_pos = history.size();
231 render(scr, model, screen.columns());
232 std::cout << scr.render(1, cursor.
row(), term_attached) << std::flush;
233 bool not_complete =
true;
242 newchar.push_back(
static_cast<char>(key));
247 else if(key == Key::Ctrl_D)
251 model.
lines[model.
cursor_row - 1].push_back(
static_cast<char>(Key::Ctrl_D));
252 std::cout <<
"\n" << std::flush;
253 m_history.push_back(model.
lines[0]);
254 return model.
lines[0];
294 case Key::ArrowRight:
309 if(model.
lines.size() > scr.columns()) { scr.set_h(model.
lines.size()); }
321 if(history_pos < history.size() - 1)
328 if(model.
lines.size() > scr.columns()) { scr.set_h(model.
lines.size()); }
347 else { model.
lines.push_back(after); }
350 if(model.
lines.size() > scr.columns()) { scr.set_h(model.
lines.size()); }
356 render(scr, model, screen.columns());
357 std::cout << scr.render(1, cursor.
row(), term_attached) << std::flush;
358 if(cursor.
row() + scr.columns() - 1 > screen.rows())
360 cursor.
setRow(
static_cast<std::uint16_t
>(screen.rows() - (scr.columns() - 1)));
361 std::cout << scr.render(1, cursor.
row(), term_attached) << std::flush;
364 std::string line_skips;
365 for(std::size_t i = 0; i <= model.
lines.size() - model.
cursor_row; i++) { line_skips +=
"\n"; }
366 std::cout << line_skips << std::flush;
Result prompt(const std::string &message, const std::string &first_option, const std::string &second_option, const std::string &prompt_indicator, bool)
A simple yes/no prompt, requires the user to press the ENTER key to continue.