diff --git a/NCursesPtyApp.cpp b/NCursesPtyApp.cpp index 971b303..7d3e3b8 100644 --- a/NCursesPtyApp.cpp +++ b/NCursesPtyApp.cpp @@ -46,6 +46,11 @@ namespace krikkel::NCursesPtyWindow while(true) { input = ptyWindow->getch(); + if(input == KEY_RESIZE) + { + ptyWindow->wresize(Root_Window->lines(), Root_Window->cols()); + continue; + } ptyWindow->writeToClient((unsigned char) input); } diff --git a/NCursesPtyWindow.cpp b/NCursesPtyWindow.cpp index 44167bd..6bb3b9d 100644 --- a/NCursesPtyWindow.cpp +++ b/NCursesPtyWindow.cpp @@ -20,6 +20,7 @@ namespace krikkel::NCursesPtyWindow : NCursesWindow(lines, columns, y, x) { // to get the original terminal we need to shutdown ncurses for a moment + /// @todo maybe try `reset_prog_mode()` and `reset_shell_mode()` instead ::endwin(); tcgetattr(STDIN_FILENO, &terminalParameters); ::refresh(); @@ -32,7 +33,6 @@ namespace krikkel::NCursesPtyWindow openpty(&fdPtyHost, &fdPtyClient, NULL, &terminalParameters, &windowSize); pseudoTerminal = vterm_new(windowSize.ws_row, windowSize.ws_col); - __debug_log("window size (x: " + std::to_string(windowSize.ws_col) + ", y: " + std::to_string(windowSize.ws_row) + ")"); vterm_set_utf8(pseudoTerminal, true); pseudoTerminalScreen = vterm_obtain_screen(pseudoTerminal); vterm_screen_reset(pseudoTerminalScreen, true); @@ -42,7 +42,8 @@ namespace krikkel::NCursesPtyWindow keypad(false); /// @todo block all signals, this thread does not handle any - readPtyClientThread = std::thread(&NCursesPtyWindow::readFromPtyClientThreadMethod, this); + readPtyClientThread = + std::thread(&NCursesPtyWindow::readFromPtyClientThreadMethod, this); } NCursesPtyWindow::~NCursesPtyWindow() @@ -129,6 +130,7 @@ namespace krikkel::NCursesPtyWindow int NCursesPtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible) { + /// @todo maybe use `mvcur()` instead? cursorX = pos.col; cursorY = pos.row; refresh(); @@ -249,6 +251,21 @@ namespace krikkel::NCursesPtyWindow return NCursesWindow::refresh(); } + /// @todo potential racing condition where drawing into terminal while + /// resizing? + int NCursesPtyWindow::wresize(int rows, int cols) + { + winsize windowSize = + { + .ws_row = narrow(rows) + , .ws_col = narrow(cols) + }; + ioctl(fdPtyHost, TIOCSWINSZ, &windowSize); + vterm_set_size(pseudoTerminal, rows, cols); + + return NCursesWindow::wresize(rows, cols); + } + int NCursesPtyWindow::staticHandlerDamage(VTermRect rect, void *user) { NCursesPtyWindow *instance = static_cast(user); diff --git a/NCursesPtyWindow.hpp b/NCursesPtyWindow.hpp index 3ea1470..823bb26 100644 --- a/NCursesPtyWindow.hpp +++ b/NCursesPtyWindow.hpp @@ -28,6 +28,7 @@ namespace krikkel::NCursesPtyWindow int add_wch(cchar_t *character); int refresh() override; + int wresize(int rows, int cols); private: int fdPtyHost, fdPtyClient;