^l in ncurses fix
This commit is contained in:
parent
07cd3100d1
commit
5064c8e1ec
6 changed files with 36 additions and 25 deletions
19
console.cpp
19
console.cpp
|
@ -101,23 +101,10 @@ void console::operator()()
|
||||||
|
|
||||||
if (c == 3) // ^c
|
if (c == 3) // ^c
|
||||||
*terminate = true;
|
*terminate = true;
|
||||||
else if (c == 12) { // ^l
|
else if (c == 12) // ^l
|
||||||
// FIXME for other consoles (e.g. ncurses) this doesn't work too well
|
refresh_virtual_terminal();
|
||||||
put_string_ll(format("\033[2J\033[?7l"));
|
else
|
||||||
|
|
||||||
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 {
|
|
||||||
input_buffer.push_back(c);
|
input_buffer.push_back(c);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
D(fprintf(stderr, "Console thread terminating\n");)
|
D(fprintf(stderr, "Console thread terminating\n");)
|
||||||
|
|
12
console.h
12
console.h
|
@ -15,10 +15,6 @@ class console
|
||||||
private:
|
private:
|
||||||
std::vector<char> input_buffer;
|
std::vector<char> input_buffer;
|
||||||
|
|
||||||
char screen_buffer[t_height][t_width];
|
|
||||||
uint8_t tx { 0 };
|
|
||||||
uint8_t ty { 0 };
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::atomic_bool *const terminate { nullptr };
|
std::atomic_bool *const terminate { nullptr };
|
||||||
|
|
||||||
|
@ -28,7 +24,11 @@ protected:
|
||||||
std::atomic_bool disk_write_activity_flag { false };
|
std::atomic_bool disk_write_activity_flag { false };
|
||||||
std::atomic_bool running_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;
|
virtual void put_char_ll(const char c) = 0;
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ public:
|
||||||
|
|
||||||
virtual void resize_terminal() = 0;
|
virtual void resize_terminal() = 0;
|
||||||
|
|
||||||
|
virtual void refresh_virtual_terminal() = 0;
|
||||||
|
|
||||||
void operator()();
|
void operator()();
|
||||||
|
|
||||||
std::atomic_bool * get_running_flag() { return &running_flag; }
|
std::atomic_bool * get_running_flag() { return &running_flag; }
|
||||||
|
|
|
@ -52,7 +52,7 @@ console_ncurses::~console_ncurses()
|
||||||
endwin();
|
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 } };
|
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, 0 } };
|
||||||
|
|
||||||
|
@ -166,3 +166,13 @@ void console_ncurses::panel_update_thread()
|
||||||
mydoupdate();
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ private:
|
||||||
int ty { 0 };
|
int ty { 0 };
|
||||||
|
|
||||||
protected:
|
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;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
|
@ -31,5 +31,7 @@ public:
|
||||||
|
|
||||||
void resize_terminal() override;
|
void resize_terminal() override;
|
||||||
|
|
||||||
|
void refresh_virtual_terminal() override;
|
||||||
|
|
||||||
void panel_update_thread() override;
|
void panel_update_thread() override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 } };
|
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::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());
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ private:
|
||||||
struct termios org_tty_opts { 0 };
|
struct termios org_tty_opts { 0 };
|
||||||
|
|
||||||
protected:
|
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;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
|
@ -19,5 +19,7 @@ public:
|
||||||
|
|
||||||
void resize_terminal() override;
|
void resize_terminal() override;
|
||||||
|
|
||||||
|
void refresh_virtual_terminal() override;
|
||||||
|
|
||||||
void panel_update_thread() override;
|
void panel_update_thread() override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue