refactored DemoApp

Separated `run()` into `setUpWindows()` and
`mainLoop()`.
This commit is contained in:
Christian Burger 2022-05-08 21:24:40 +02:00
parent a801752620
commit 7e7372ee52
2 changed files with 45 additions and 26 deletions

59
App.cpp
View file

@ -11,7 +11,6 @@
#include <unistd.h>
#include <utmp.h>
#include <cstdlib>
#include <mutex>
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;
}
}

12
App.hpp
View file

@ -7,16 +7,28 @@
#define A3B2AE4E_0A39_468C_8CCA_E6508166702A
#include <cursesapp.h>
#include <mutex>
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();
};
}