From 5064c8e1ece8cfa4796e6c2cf44bc67d6cda011f Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 31 Mar 2022 19:41:26 +0200 Subject: [PATCH] ^l in ncurses fix --- console.cpp | 19 +++---------------- console.h | 12 +++++++----- console_ncurses.cpp | 12 +++++++++++- console_ncurses.h | 4 +++- console_posix.cpp | 10 +++++++++- console_posix.h | 4 +++- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/console.cpp b/console.cpp index 3cea48b..2a66ab6 100644 --- a/console.cpp +++ b/console.cpp @@ -101,23 +101,10 @@ void console::operator()() if (c == 3) // ^c *terminate = true; - else if (c == 12) { // ^l - // FIXME for other consoles (e.g. ncurses) this doesn't work too well - put_string_ll(format("\033[2J\033[?7l")); - - fprintf(stderr, "%d %d\n", tx, ty); - - for(int row=0; row input_buffer; - char screen_buffer[t_height][t_width]; - uint8_t tx { 0 }; - uint8_t ty { 0 }; - protected: std::atomic_bool *const terminate { nullptr }; @@ -28,7 +24,11 @@ protected: std::atomic_bool disk_write_activity_flag { false }; std::atomic_bool running_flag { false }; - virtual int wait_for_char(const int timeout) = 0; + char screen_buffer[t_height][t_width]; + uint8_t tx { 0 }; + uint8_t ty { 0 }; + + virtual int wait_for_char(const short timeout) = 0; virtual void put_char_ll(const char c) = 0; @@ -48,6 +48,8 @@ public: virtual void resize_terminal() = 0; + virtual void refresh_virtual_terminal() = 0; + void operator()(); std::atomic_bool * get_running_flag() { return &running_flag; } diff --git a/console_ncurses.cpp b/console_ncurses.cpp index 821bb90..0307566 100644 --- a/console_ncurses.cpp +++ b/console_ncurses.cpp @@ -52,7 +52,7 @@ console_ncurses::~console_ncurses() endwin(); } -int console_ncurses::wait_for_char(const int timeout) +int console_ncurses::wait_for_char(const short timeout) { struct pollfd fds[] = { { STDIN_FILENO, POLLIN, 0 } }; @@ -166,3 +166,13 @@ void console_ncurses::panel_update_thread() mydoupdate(); } } + +void console_ncurses::refresh_virtual_terminal() +{ + wclear(w_main->win); + + for(int row=0; rowwin, row + 1, 0, std::string(screen_buffer[row], t_width).c_str()); + + mydoupdate(); +} diff --git a/console_ncurses.h b/console_ncurses.h index 1d41059..0259d67 100644 --- a/console_ncurses.h +++ b/console_ncurses.h @@ -21,7 +21,7 @@ private: int ty { 0 }; protected: - int wait_for_char(const int timeout) override; + int wait_for_char(const short timeout) override; void put_char_ll(const char c) override; @@ -31,5 +31,7 @@ public: void resize_terminal() override; + void refresh_virtual_terminal() override; + void panel_update_thread() override; }; diff --git a/console_posix.cpp b/console_posix.cpp index 94caa26..753352f 100644 --- a/console_posix.cpp +++ b/console_posix.cpp @@ -35,7 +35,7 @@ console_posix::~console_posix() } -int console_posix::wait_for_char(const int timeout) +int console_posix::wait_for_char(const short timeout) { struct pollfd fds[] = { { STDIN_FILENO, POLLIN, timeout } }; @@ -59,3 +59,11 @@ void console_posix::resize_terminal() void console_posix::panel_update_thread() { } + +void console_posix::refresh_virtual_terminal() +{ + printf("%c\n", 12); // form feed + + for(int row=0; row