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;
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;
132 switch(
prompt(message,
"y",
"N",
":",
false))
147 for(
auto& line: lines) { s.append(line +
"\n"); }
154 std::vector<std::string> lines;
155 lines.emplace_back(
"");
157 for(std::size_t i = 0; i < s.size() - 1; i++)
162 lines.emplace_back(
"");
164 else { lines[j].push_back(s[i]); }
169char32_t UU(
const std::string& s)
178 std::size_t h{y2 - y1 + 1};
183 for(std::size_t j = y1 + 1; j <= y2 - 1; j++) { scr.
set_char(x, j,
UU(
"│")); }
193 for(std::size_t j = 0; j < model.
lines.size(); j++)
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));
253 std::cout <<
"\n" << std::flush;
254 m_history.push_back(model.
lines[0]);
255 return model.
lines[0];
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;
@ Green
Green FG: 32, BG: 42.
std::size_t column() const
constexpr Key tolower() const
std::vector< std::string > lines
std::string prompt_string
Represents a rectangular window, as a 2D array of characters and their attributes.
void print_str(const std::size_t &column, const std::size_t &, const std::string &, const std::size_t &=0, bool=false)
void set_char(const std::size_t &column, const std::size_t &row, const char32_t &character)
void fill_style(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Style &)
void set_cursor_pos(const std::size_t &column, const std::size_t &row)
void fill_fg(const std::size_t &column, const std::size_t &, const std::size_t &, const std::size_t &, const Color &)
#define CPP_TERMINAL_FALLTHROUGH
std::u32string utf8_to_utf32(const std::string &str)
std::string prompt_multiline(const std::string &, std::vector< std::string > &, std::function< bool(std::string)> &)
std::vector< std::string > split(const std::string &)
void print_left_curly_bracket(Term::Window &, const std::size_t &, const std::size_t &, const std::size_t &)
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.
std::string concat(const std::vector< std::string > &)
Result_simple prompt_simple(const std::string &message)
The most simple prompt possible, requires the user to press enter to continue.
void render(Term::Window &, const Model &, const std::size_t &)
@ NoClearScreen
Doesn't clear the screen.
@ Raw
Set terminal in raw mode.
@ NoSignalKeys
Disable the signal keys (Ctrl+C, etc...) will not be processed by the OS and will appears has standar...
Term::Cursor cursor_position()
@ Invalid
Returned if the given input did not match the case yes of no.
@ None
Returned if the enter key was pressed without additional input.
@ Abort
Returned if CTRL+C was pressed.
@ Error
Returned if no terminal is attached to the program.
@ Yes
Returned if the user chose yes.
@ No
Returned if the user chose no.
Term::Terminal & terminal
bool is_stdin_a_tty()
Check if stdin is a tty.
@ Abort
Returned if CTRL+C was pressed.
@ Yes
Returned if the user chose yes.
@ No
Returned if the user chose no or invalid / no input or if no terminal is attached.
char32_t UU(const std::string &s)