tweaks to get history working

This commit is contained in:
folkert van heusden 2024-04-11 17:20:56 +02:00
parent 75c476f200
commit c3ddce554b
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
2 changed files with 4 additions and 6 deletions

View file

@ -212,16 +212,13 @@ std::string console::read_line(const std::string & prompt)
if (c == 'A') { // up if (c == 'A') { // up
if (line_nr > 0) if (line_nr > 0)
line_nr--; line_nr--;
else
line_nr = edit_lines_hist.size() - 1;
} }
else if (c == 'B') { // down else if (c == 'B') { // down
if (line_nr < edit_lines_hist.size() - 1) if (line_nr < edit_lines_hist.size() - 1)
line_nr++; line_nr++;
else
line_nr = 0;
} }
else { else {
printf("[%c]\n", c);
continue; continue;
} }
@ -344,7 +341,6 @@ void console::operator()()
while(*stop_event != EVENT_TERMINATE && !stop_thread_flag) { while(*stop_event != EVENT_TERMINATE && !stop_thread_flag) {
int c = wait_for_char_ll(500); int c = wait_for_char_ll(500);
if (c == -1) if (c == -1)
continue; continue;

View file

@ -28,6 +28,8 @@ console_posix::console_posix(std::atomic_uint32_t *const stop_event, bus *const
if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1) if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1)
error_exit(true, "console_posix: tcsetattr failed"); error_exit(true, "console_posix: tcsetattr failed");
setvbuf(stdin, nullptr, _IONBF, 0);
#endif #endif
} }
@ -53,7 +55,7 @@ int console_posix::wait_for_char_ll(const short timeout)
if (select(STDIN_FILENO + 1, &rfds, nullptr, nullptr, &to) == 1 && FD_ISSET(STDIN_FILENO, &rfds)) if (select(STDIN_FILENO + 1, &rfds, nullptr, nullptr, &to) == 1 && FD_ISSET(STDIN_FILENO, &rfds))
return _getch(); return _getch();
#else #else
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, timeout } }; struct pollfd fds[] = { { STDIN_FILENO, POLLIN, 0 } };
if (poll(fds, 1, timeout) == 1 && fds[0].revents) if (poll(fds, 1, timeout) == 1 && fds[0].revents)
return getchar(); return getchar();