improved demo a bit, refactoring a bit
This commit is contained in:
parent
e42711f123
commit
320f5ba63a
32
App.cpp
32
App.cpp
|
@ -27,11 +27,11 @@ namespace krikkel::NCurses
|
|||
std::recursive_mutex ncursesMutex;
|
||||
VerticalTilingWindowManager windowManager(Root_Window, &ncursesMutex);
|
||||
|
||||
Window *dummyWindow = new Window(&windowManager);
|
||||
dummyWindow->move(0, 0);
|
||||
Window *dummyWindowTop = new Window(&windowManager);
|
||||
dummyWindowTop->move(0, 0);
|
||||
PtyWindow *ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
|
||||
windowManager.addWindow(ptyWindow);
|
||||
new Window(&windowManager);
|
||||
Window *dummyWindowBottom = new Window(&windowManager);
|
||||
windowManager.updateLayout();
|
||||
windowManager.refresh();
|
||||
|
||||
|
@ -60,8 +60,8 @@ namespace krikkel::NCurses
|
|||
ptyWindow->writeUnicodeCharToClient(input.getRawInput());
|
||||
{
|
||||
scoped_lock lock(ncursesMutex);
|
||||
dummyWindow->addch(input.getRawInput());
|
||||
dummyWindow->refresh();
|
||||
dummyWindowTop->addch(input.getRawInput());
|
||||
dummyWindowTop->refresh();
|
||||
}
|
||||
}
|
||||
if(input.isFunctionKey())
|
||||
|
@ -72,22 +72,26 @@ namespace krikkel::NCurses
|
|||
windowManager.updateLayout();
|
||||
break;
|
||||
case KEY_F(1):
|
||||
windowManager.hideWindow(ptyWindow);
|
||||
if(dummyWindowTop->isHidden())
|
||||
windowManager.showWindow(dummyWindowTop);
|
||||
else
|
||||
windowManager.hideWindow(dummyWindowTop);
|
||||
windowManager.updateLayout();
|
||||
windowManager.refresh();
|
||||
break;
|
||||
case KEY_F(2):
|
||||
windowManager.showWindow(ptyWindow);
|
||||
if(ptyWindow->isHidden())
|
||||
windowManager.showWindow(ptyWindow);
|
||||
else
|
||||
windowManager.hideWindow(ptyWindow);
|
||||
windowManager.updateLayout();
|
||||
windowManager.refresh();
|
||||
break;
|
||||
case KEY_F(3):
|
||||
windowManager.hideWindow(dummyWindow);
|
||||
windowManager.updateLayout();
|
||||
windowManager.refresh();
|
||||
break;
|
||||
case KEY_F(4):
|
||||
windowManager.showWindow(dummyWindow);
|
||||
if(dummyWindowBottom->isHidden())
|
||||
windowManager.showWindow(dummyWindowBottom);
|
||||
else
|
||||
windowManager.hideWindow(dummyWindowBottom);
|
||||
windowManager.updateLayout();
|
||||
windowManager.refresh();
|
||||
break;
|
||||
|
@ -95,7 +99,7 @@ namespace krikkel::NCurses
|
|||
windowManager.refresh();
|
||||
break;
|
||||
default:
|
||||
ptyWindow->writeKeyToClient(input.mapKeyNcursesToVTerm());
|
||||
ptyWindow->writeFunctionKeyToClient(input.mapKeyNcursesToVTerm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace krikkel::NCurses
|
|||
|
||||
/// @todo block all signals, this thread does not handle any
|
||||
readPtyClientThread =
|
||||
std::thread(&PtyWindow::readFromPtyClientThreadMethod, this);
|
||||
std::thread(&PtyWindow::readFromPtyClientThreadMethod, this);
|
||||
}
|
||||
|
||||
PtyWindow::~PtyWindow()
|
||||
|
@ -67,9 +67,8 @@ namespace krikkel::NCurses
|
|||
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);
|
||||
//__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);
|
||||
}
|
||||
|
||||
void PtyWindow::writeKeyToClient(VTermKey key)
|
||||
void PtyWindow::writeFunctionKeyToClient(VTermKey key)
|
||||
{
|
||||
scoped_lock lock(ptyMutex);
|
||||
//__debug_log("writing key: " + std::to_string(key));
|
||||
|
@ -160,7 +159,6 @@ namespace krikkel::NCurses
|
|||
int PtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible)
|
||||
{
|
||||
scoped_lock lock(*ncursesMutex);
|
||||
/// @todo maybe use `mvcur()` instead?
|
||||
cursorX = pos.col;
|
||||
cursorY = pos.row;
|
||||
refresh();
|
||||
|
@ -330,6 +328,6 @@ namespace krikkel::NCurses
|
|||
void PtyWindow::staticHandlerOutput(const char *s, size_t len, void *user)
|
||||
{
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
instance->writeToClient(s, len);
|
||||
instance->writeToPtyClient(s, len);
|
||||
}
|
||||
}
|
|
@ -42,6 +42,11 @@ namespace krikkel::NCurses
|
|||
return ::wget_wch(w, character);
|
||||
}
|
||||
|
||||
bool Window::isHidden()
|
||||
{
|
||||
return hidden;
|
||||
}
|
||||
|
||||
SingleUserInput Window::readSingleUserInput()
|
||||
{
|
||||
wint_t input;
|
||||
|
|
|
@ -25,12 +25,11 @@ namespace krikkel::NCurses
|
|||
~PtyWindow();
|
||||
|
||||
int getFdPtyClient() const;
|
||||
void writeToClient(const char * string, size_t length);
|
||||
void writeUnicodeCharToClient(wint_t character);
|
||||
void writeKeyToClient(VTermKey key);
|
||||
void writeFunctionKeyToClient(VTermKey key);
|
||||
|
||||
int refresh() override;
|
||||
virtual int resize(int rows, int cols) override;
|
||||
int resize(int rows, int cols) override;
|
||||
|
||||
private:
|
||||
int fdPtyHost, fdPtyClient;
|
||||
|
@ -48,6 +47,7 @@ namespace krikkel::NCurses
|
|||
std::thread readPtyClientThread;
|
||||
void readFromPtyClientThreadMethod();
|
||||
void readFromPtyClient();
|
||||
void writeToPtyClient(const char * string, size_t length);
|
||||
|
||||
int handlerDamage(VTermRect rect);
|
||||
int handlerMoveRect(VTermRect dest, VTermRect src);
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace krikkel::NCurses
|
|||
int ins_wch(const cchar_t *character);
|
||||
int get_wch(wint_t *character);
|
||||
|
||||
bool isHidden();
|
||||
SingleUserInput readSingleUserInput();
|
||||
virtual int resize(int rows, int cols);
|
||||
virtual int refresh() override;
|
||||
|
|
Loading…
Reference in a new issue