From c3ddce554b7b484f7fa86a6cae8fa7997559a538 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 11 Apr 2024 17:20:56 +0200 Subject: [PATCH] tweaks to get history working --- console.cpp | 6 +----- console_posix.cpp | 4 +++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/console.cpp b/console.cpp index ef6310a..1717e06 100644 --- a/console.cpp +++ b/console.cpp @@ -212,16 +212,13 @@ std::string console::read_line(const std::string & prompt) if (c == 'A') { // up if (line_nr > 0) line_nr--; - else - line_nr = edit_lines_hist.size() - 1; } else if (c == 'B') { // down if (line_nr < edit_lines_hist.size() - 1) line_nr++; - else - line_nr = 0; } else { + printf("[%c]\n", c); continue; } @@ -344,7 +341,6 @@ void console::operator()() while(*stop_event != EVENT_TERMINATE && !stop_thread_flag) { int c = wait_for_char_ll(500); - if (c == -1) continue; diff --git a/console_posix.cpp b/console_posix.cpp index baffc4d..5d9b9ee 100644 --- a/console_posix.cpp +++ b/console_posix.cpp @@ -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) error_exit(true, "console_posix: tcsetattr failed"); + + setvbuf(stdin, nullptr, _IONBF, 0); #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)) return _getch(); #else - struct pollfd fds[] = { { STDIN_FILENO, POLLIN, timeout } }; + struct pollfd fds[] = { { STDIN_FILENO, POLLIN, 0 } }; if (poll(fds, 1, timeout) == 1 && fds[0].revents) return getchar();