diff --git a/App.cpp b/App.cpp index 51f327a..7ca4480 100644 --- a/App.cpp +++ b/App.cpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace krikkel::NCurses { @@ -24,16 +23,23 @@ namespace krikkel::NCurses int DemoApp::run() { - std::recursive_mutex ncursesMutex; - VerticalTilingWindowManager windowManager(Root_Window, &ncursesMutex); + setUpWindows(); + mainLoop(); - Window *dummyWindowTop = new Window(&windowManager); + return 0; + } + + void DemoApp::setUpWindows() + { + windowManager = new VerticalTilingWindowManager(Root_Window, &ncursesMutex); + + dummyWindowTop = new Window(windowManager); dummyWindowTop->move(0, 0); - PtyWindow *ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0); - windowManager.addWindow(ptyWindow); - Window *dummyWindowBottom = new Window(&windowManager); - windowManager.updateLayout(); - windowManager.refresh(); + ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0); + windowManager->addWindow(ptyWindow); + dummyWindowBottom = new Window(windowManager); + windowManager->updateLayout(); + windowManager->refresh(); if(fork() == 0) { @@ -51,10 +57,13 @@ namespace krikkel::NCurses " to a working value?", shellPath); exit(1); } + } + void DemoApp::mainLoop() + { while(true) { - SingleUserInput input = windowManager.readSingleUserInput(); + SingleUserInput input = windowManager->readSingleUserInput(); if(input.isNormalKey()) { ptyWindow->writeUnicodeCharToClient(input.getRawInput()); @@ -69,41 +78,39 @@ namespace krikkel::NCurses switch(input.getRawInput()) { case KEY_RESIZE: - windowManager.updateLayout(); + windowManager->updateLayout(); break; case KEY_F(1): if(dummyWindowTop->isHidden()) - windowManager.showWindow(dummyWindowTop); + windowManager->showWindow(dummyWindowTop); else - windowManager.hideWindow(dummyWindowTop); - windowManager.updateLayout(); - windowManager.refresh(); + windowManager->hideWindow(dummyWindowTop); + windowManager->updateLayout(); + windowManager->refresh(); break; case KEY_F(2): if(ptyWindow->isHidden()) - windowManager.showWindow(ptyWindow); + windowManager->showWindow(ptyWindow); else - windowManager.hideWindow(ptyWindow); - windowManager.updateLayout(); - windowManager.refresh(); + windowManager->hideWindow(ptyWindow); + windowManager->updateLayout(); + windowManager->refresh(); break; case KEY_F(3): if(dummyWindowBottom->isHidden()) - windowManager.showWindow(dummyWindowBottom); + windowManager->showWindow(dummyWindowBottom); else - windowManager.hideWindow(dummyWindowBottom); - windowManager.updateLayout(); - windowManager.refresh(); + windowManager->hideWindow(dummyWindowBottom); + windowManager->updateLayout(); + windowManager->refresh(); break; case KEY_F(5): - windowManager.refresh(); + windowManager->refresh(); break; default: ptyWindow->writeFunctionKeyToClient(input.mapKeyNcursesToVTerm()); } } } - - return 0; } } diff --git a/App.hpp b/App.hpp index 72a11eb..41b2844 100644 --- a/App.hpp +++ b/App.hpp @@ -7,16 +7,28 @@ #define A3B2AE4E_0A39_468C_8CCA_E6508166702A #include +#include namespace krikkel::NCurses { + class VerticalTilingWindowManager; + class Window; + class PtyWindow; + class DemoApp : public NCursesApplication { public: DemoApp(); private: + VerticalTilingWindowManager *windowManager; + Window *dummyWindowTop, *dummyWindowBottom; + PtyWindow *ptyWindow; + std::recursive_mutex ncursesMutex; + int run() override; + void setUpWindows(); + void mainLoop(); }; }