58 struct termios old = {};
59 if (tcgetattr(0, &old) < 0) {
60 perror(
"tcsetattr()");
62 old.c_lflag &= ~ICANON;
66 if (tcsetattr(0, TCSANOW, &old) < 0) {
67 perror(
"tcsetattr ICANON");
69 if (::read(0, &buf, 1) < 0) {
72 old.c_lflag |= ICANON;
74 if (tcsetattr(0, TCSADRAIN, &old) < 0) {
75 perror(
"tcsetattr ~ICANON");
89 std::cout << this->prompt << std::flush;
94 bool arrow_key =
false;
101 }
else if (escaped) {
155 history = std::vector<std::string>();
165 bool found_tab =
false;
173 std::cout <<
'\a' << std::flush;
190 std::cout <<
output << std::flush;
213 std::cout <<
'\a' << std::flush;
237 std::cout <<
'\a' << std::flush;
255 std::cout <<
'\a' << std::flush;
271 std::cout << (char)27 <<
'[' <<
'C' << std::flush;
276 std::cout << (char)27 <<
'[' <<
'C' << std::flush;
280 std::cout << (char)27 <<
'[' <<
'C' << std::flush;
286 std::cout << (char)27 <<
'[' <<
'D' << std::flush;
298 std::cout << (char)27 <<
"[C" << std::flush;
300 for (
size_t i = 0;
i < text_len + 1;
i++) {
301 std::cout <<
"\b \b" << std::flush;
306 for (
char i : text) {
307 std::cout <<
i << std::flush;
311 std::cout <<
"\b" << std::flush;