27Term::Result Term::prompt(
const std::string& message,
const std::string& first_option,
const std::string& second_option,
const std::string& prompt_indicator,
bool immediate)
30 std::cout << message <<
" [" << first_option <<
'/' << second_option <<
']' << prompt_indicator <<
' ' << std::flush;
34 std::cout <<
'\n' << std::flush;
48 std::cout <<
'\n' << std::flush;
53 std::cout <<
'\n' << std::flush;
58 std::cout <<
'\n' << std::flush;
63 std::cout <<
'\n' << std::flush;
68 std::cout <<
'\n' << std::flush;
69 return Result::Invalid;
80 if(key >=
'a' && key <=
'z')
82 std::cout << (char)key << std::flush;
83 input.push_back(
static_cast<char>(key));
85 else if(key >=
'A' && key <=
'Z')
87 std::cout << (char)key << std::flush;
88 input.push_back(
static_cast<char>(key.
tolower()));
97 if(input.empty() != 0)
99 std::cout <<
"\u001b[D \u001b[D" << std::flush;
105 if(input ==
"y" || input ==
"yes")
107 std::cout <<
'\n' << std::flush;
110 else if(input ==
"n" || input ==
"no")
112 std::cout <<
'\n' << std::flush;
115 else if(input.empty())
117 std::cout <<
'\n' << std::flush;
122 std::cout <<
'\n' << std::flush;
123 return Result::Invalid;
210std::string
Term::prompt_multiline(
const std::string& prompt_string, std::vector<std::string>& m_history, std::function<
bool(std::string)>& iscomplete)
226 std::vector<std::string> history = m_history;
227 std::size_t history_pos = history.size();
232 render(scr, model, screen.columns());
233 std::cout << scr.render(1, cursor.
row(), term_attached) << std::flush;
234 bool not_complete =
true;
243 newchar.push_back(
static_cast<char>(key));
248 else if(key == Key::Ctrl_D)
252 model.
lines[model.
cursor_row - 1].push_back(
static_cast<char>(Key::Ctrl_D));
253 std::cout <<
"\n" << std::flush;
254 m_history.push_back(model.
lines[0]);
255 return model.
lines[0];
295 case Key::ArrowRight:
310 if(model.
lines.size() > scr.columns()) { scr.set_h(model.
lines.size()); }
322 if(history_pos < history.size() - 1)
329 if(model.
lines.size() > scr.columns()) { scr.set_h(model.
lines.size()); }
348 else { model.
lines.push_back(after); }
351 if(model.
lines.size() > scr.columns()) { scr.set_h(model.
lines.size()); }
357 render(scr, model, screen.columns());
358 std::cout << scr.render(1, cursor.
row(), term_attached) << std::flush;
359 if(cursor.
row() + scr.columns() - 1 > screen.rows())
361 cursor =
Cursor({
Row(
static_cast<std::uint16_t
>(screen.rows() - (scr.columns() - 1))),
Column(cursor.
column())});
362 std::cout << scr.render(1, cursor.
row(), term_attached) << std::flush;
365 std::string line_skips;
366 for(std::size_t i = 0; i <= model.
lines.size() - model.
cursor_row; i++) { line_skips +=
"\n"; }
367 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.