improved demo a bit, refactoring a bit

This commit is contained in:
Christian Burger 2022-05-06 22:05:57 +02:00
parent e42711f123
commit 320f5ba63a
5 changed files with 31 additions and 23 deletions

32
App.cpp
View file

@ -27,11 +27,11 @@ namespace krikkel::NCurses
std::recursive_mutex ncursesMutex; std::recursive_mutex ncursesMutex;
VerticalTilingWindowManager windowManager(Root_Window, &ncursesMutex); VerticalTilingWindowManager windowManager(Root_Window, &ncursesMutex);
Window *dummyWindow = new Window(&windowManager); Window *dummyWindowTop = new Window(&windowManager);
dummyWindow->move(0, 0); dummyWindowTop->move(0, 0);
PtyWindow *ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0); PtyWindow *ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
windowManager.addWindow(ptyWindow); windowManager.addWindow(ptyWindow);
new Window(&windowManager); Window *dummyWindowBottom = new Window(&windowManager);
windowManager.updateLayout(); windowManager.updateLayout();
windowManager.refresh(); windowManager.refresh();
@ -60,8 +60,8 @@ namespace krikkel::NCurses
ptyWindow->writeUnicodeCharToClient(input.getRawInput()); ptyWindow->writeUnicodeCharToClient(input.getRawInput());
{ {
scoped_lock lock(ncursesMutex); scoped_lock lock(ncursesMutex);
dummyWindow->addch(input.getRawInput()); dummyWindowTop->addch(input.getRawInput());
dummyWindow->refresh(); dummyWindowTop->refresh();
} }
} }
if(input.isFunctionKey()) if(input.isFunctionKey())
@ -72,22 +72,26 @@ namespace krikkel::NCurses
windowManager.updateLayout(); windowManager.updateLayout();
break; break;
case KEY_F(1): case KEY_F(1):
windowManager.hideWindow(ptyWindow); if(dummyWindowTop->isHidden())
windowManager.showWindow(dummyWindowTop);
else
windowManager.hideWindow(dummyWindowTop);
windowManager.updateLayout(); windowManager.updateLayout();
windowManager.refresh(); windowManager.refresh();
break; break;
case KEY_F(2): case KEY_F(2):
windowManager.showWindow(ptyWindow); if(ptyWindow->isHidden())
windowManager.showWindow(ptyWindow);
else
windowManager.hideWindow(ptyWindow);
windowManager.updateLayout(); windowManager.updateLayout();
windowManager.refresh(); windowManager.refresh();
break; break;
case KEY_F(3): case KEY_F(3):
windowManager.hideWindow(dummyWindow); if(dummyWindowBottom->isHidden())
windowManager.updateLayout(); windowManager.showWindow(dummyWindowBottom);
windowManager.refresh(); else
break; windowManager.hideWindow(dummyWindowBottom);
case KEY_F(4):
windowManager.showWindow(dummyWindow);
windowManager.updateLayout(); windowManager.updateLayout();
windowManager.refresh(); windowManager.refresh();
break; break;
@ -95,7 +99,7 @@ namespace krikkel::NCurses
windowManager.refresh(); windowManager.refresh();
break; break;
default: default:
ptyWindow->writeKeyToClient(input.mapKeyNcursesToVTerm()); ptyWindow->writeFunctionKeyToClient(input.mapKeyNcursesToVTerm());
} }
} }
} }

View file

@ -52,7 +52,7 @@ namespace krikkel::NCurses
/// @todo block all signals, this thread does not handle any /// @todo block all signals, this thread does not handle any
readPtyClientThread = readPtyClientThread =
std::thread(&PtyWindow::readFromPtyClientThreadMethod, this); std::thread(&PtyWindow::readFromPtyClientThreadMethod, this);
} }
PtyWindow::~PtyWindow() PtyWindow::~PtyWindow()
@ -67,9 +67,8 @@ namespace krikkel::NCurses
return fdPtyClient; return fdPtyClient;
} }
void PtyWindow::writeToClient(const char *output, size_t length) void PtyWindow::writeToPtyClient(const char *output, size_t length)
{ {
scoped_lock lock(ptyMutex);
write(fdPtyHost, output, length); write(fdPtyHost, output, length);
//__debug_log("written to PTY client: '" + __debug_make_bytes_printable(std::string(output, length)) + '\''); //__debug_log("written to PTY client: '" + __debug_make_bytes_printable(std::string(output, length)) + '\'');
} }
@ -80,7 +79,7 @@ namespace krikkel::NCurses
vterm_keyboard_unichar(pseudoTerminal, character, VTERM_MOD_NONE); vterm_keyboard_unichar(pseudoTerminal, character, VTERM_MOD_NONE);
} }
void PtyWindow::writeKeyToClient(VTermKey key) void PtyWindow::writeFunctionKeyToClient(VTermKey key)
{ {
scoped_lock lock(ptyMutex); scoped_lock lock(ptyMutex);
//__debug_log("writing key: " + std::to_string(key)); //__debug_log("writing key: " + std::to_string(key));
@ -160,7 +159,6 @@ namespace krikkel::NCurses
int PtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible) int PtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible)
{ {
scoped_lock lock(*ncursesMutex); scoped_lock lock(*ncursesMutex);
/// @todo maybe use `mvcur()` instead?
cursorX = pos.col; cursorX = pos.col;
cursorY = pos.row; cursorY = pos.row;
refresh(); refresh();
@ -330,6 +328,6 @@ namespace krikkel::NCurses
void PtyWindow::staticHandlerOutput(const char *s, size_t len, void *user) void PtyWindow::staticHandlerOutput(const char *s, size_t len, void *user)
{ {
PtyWindow *instance = static_cast<PtyWindow *>(user); PtyWindow *instance = static_cast<PtyWindow *>(user);
instance->writeToClient(s, len); instance->writeToPtyClient(s, len);
} }
} }

View file

@ -42,6 +42,11 @@ namespace krikkel::NCurses
return ::wget_wch(w, character); return ::wget_wch(w, character);
} }
bool Window::isHidden()
{
return hidden;
}
SingleUserInput Window::readSingleUserInput() SingleUserInput Window::readSingleUserInput()
{ {
wint_t input; wint_t input;

View file

@ -25,12 +25,11 @@ namespace krikkel::NCurses
~PtyWindow(); ~PtyWindow();
int getFdPtyClient() const; int getFdPtyClient() const;
void writeToClient(const char * string, size_t length);
void writeUnicodeCharToClient(wint_t character); void writeUnicodeCharToClient(wint_t character);
void writeKeyToClient(VTermKey key); void writeFunctionKeyToClient(VTermKey key);
int refresh() override; int refresh() override;
virtual int resize(int rows, int cols) override; int resize(int rows, int cols) override;
private: private:
int fdPtyHost, fdPtyClient; int fdPtyHost, fdPtyClient;
@ -48,6 +47,7 @@ namespace krikkel::NCurses
std::thread readPtyClientThread; std::thread readPtyClientThread;
void readFromPtyClientThreadMethod(); void readFromPtyClientThreadMethod();
void readFromPtyClient(); void readFromPtyClient();
void writeToPtyClient(const char * string, size_t length);
int handlerDamage(VTermRect rect); int handlerDamage(VTermRect rect);
int handlerMoveRect(VTermRect dest, VTermRect src); int handlerMoveRect(VTermRect dest, VTermRect src);

View file

@ -51,6 +51,7 @@ namespace krikkel::NCurses
int ins_wch(const cchar_t *character); int ins_wch(const cchar_t *character);
int get_wch(wint_t *character); int get_wch(wint_t *character);
bool isHidden();
SingleUserInput readSingleUserInput(); SingleUserInput readSingleUserInput();
virtual int resize(int rows, int cols); virtual int resize(int rows, int cols);
virtual int refresh() override; virtual int refresh() override;