^l in ncurses fix

This commit is contained in:
folkert van heusden 2022-03-31 19:41:26 +02:00
parent 07cd3100d1
commit 5064c8e1ec
6 changed files with 36 additions and 25 deletions

View file

@ -101,24 +101,11 @@ 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<t_height; row++) {
put_string_ll(format("\033[%dH", row + 1));
put_string_ll(std::string(screen_buffer[row], t_width));
}
put_string_ll(format("\033[%d;%dH\033[?7h", ty + 1, tx + 1));
}
else {
else if (c == 12) // ^l
refresh_virtual_terminal();
else
input_buffer.push_back(c);
}
}
D(fprintf(stderr, "Console thread terminating\n");)
}

View file

@ -15,10 +15,6 @@ class console
private:
std::vector<char> 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; }

View file

@ -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; row<t_height; row++)
mvwprintw(w_main->win, row + 1, 0, std::string(screen_buffer[row], t_width).c_str());
mydoupdate();
}

View file

@ -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;
};

View file

@ -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<t_height; row++)
printf("%s\n", std::string(screen_buffer[row], t_width).c_str());
}

View file

@ -9,7 +9,7 @@ private:
struct termios org_tty_opts { 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;
@ -19,5 +19,7 @@ public:
void resize_terminal() override;
void refresh_virtual_terminal() override;
void panel_update_thread() override;
};