refactored DemoApp
Separated `run()` into `setUpWindows()` and `mainLoop()`.
This commit is contained in:
parent
a801752620
commit
7e7372ee52
59
App.cpp
59
App.cpp
|
@ -11,7 +11,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utmp.h>
|
#include <utmp.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace krikkel::NCurses
|
namespace krikkel::NCurses
|
||||||
{
|
{
|
||||||
|
@ -24,16 +23,23 @@ namespace krikkel::NCurses
|
||||||
|
|
||||||
int DemoApp::run()
|
int DemoApp::run()
|
||||||
{
|
{
|
||||||
std::recursive_mutex ncursesMutex;
|
setUpWindows();
|
||||||
VerticalTilingWindowManager windowManager(Root_Window, &ncursesMutex);
|
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);
|
dummyWindowTop->move(0, 0);
|
||||||
PtyWindow *ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
|
ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0);
|
||||||
windowManager.addWindow(ptyWindow);
|
windowManager->addWindow(ptyWindow);
|
||||||
Window *dummyWindowBottom = new Window(&windowManager);
|
dummyWindowBottom = new Window(windowManager);
|
||||||
windowManager.updateLayout();
|
windowManager->updateLayout();
|
||||||
windowManager.refresh();
|
windowManager->refresh();
|
||||||
|
|
||||||
if(fork() == 0)
|
if(fork() == 0)
|
||||||
{
|
{
|
||||||
|
@ -51,10 +57,13 @@ namespace krikkel::NCurses
|
||||||
" to a working value?", shellPath);
|
" to a working value?", shellPath);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemoApp::mainLoop()
|
||||||
|
{
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
SingleUserInput input = windowManager.readSingleUserInput();
|
SingleUserInput input = windowManager->readSingleUserInput();
|
||||||
if(input.isNormalKey())
|
if(input.isNormalKey())
|
||||||
{
|
{
|
||||||
ptyWindow->writeUnicodeCharToClient(input.getRawInput());
|
ptyWindow->writeUnicodeCharToClient(input.getRawInput());
|
||||||
|
@ -69,41 +78,39 @@ namespace krikkel::NCurses
|
||||||
switch(input.getRawInput())
|
switch(input.getRawInput())
|
||||||
{
|
{
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
windowManager.updateLayout();
|
windowManager->updateLayout();
|
||||||
break;
|
break;
|
||||||
case KEY_F(1):
|
case KEY_F(1):
|
||||||
if(dummyWindowTop->isHidden())
|
if(dummyWindowTop->isHidden())
|
||||||
windowManager.showWindow(dummyWindowTop);
|
windowManager->showWindow(dummyWindowTop);
|
||||||
else
|
else
|
||||||
windowManager.hideWindow(dummyWindowTop);
|
windowManager->hideWindow(dummyWindowTop);
|
||||||
windowManager.updateLayout();
|
windowManager->updateLayout();
|
||||||
windowManager.refresh();
|
windowManager->refresh();
|
||||||
break;
|
break;
|
||||||
case KEY_F(2):
|
case KEY_F(2):
|
||||||
if(ptyWindow->isHidden())
|
if(ptyWindow->isHidden())
|
||||||
windowManager.showWindow(ptyWindow);
|
windowManager->showWindow(ptyWindow);
|
||||||
else
|
else
|
||||||
windowManager.hideWindow(ptyWindow);
|
windowManager->hideWindow(ptyWindow);
|
||||||
windowManager.updateLayout();
|
windowManager->updateLayout();
|
||||||
windowManager.refresh();
|
windowManager->refresh();
|
||||||
break;
|
break;
|
||||||
case KEY_F(3):
|
case KEY_F(3):
|
||||||
if(dummyWindowBottom->isHidden())
|
if(dummyWindowBottom->isHidden())
|
||||||
windowManager.showWindow(dummyWindowBottom);
|
windowManager->showWindow(dummyWindowBottom);
|
||||||
else
|
else
|
||||||
windowManager.hideWindow(dummyWindowBottom);
|
windowManager->hideWindow(dummyWindowBottom);
|
||||||
windowManager.updateLayout();
|
windowManager->updateLayout();
|
||||||
windowManager.refresh();
|
windowManager->refresh();
|
||||||
break;
|
break;
|
||||||
case KEY_F(5):
|
case KEY_F(5):
|
||||||
windowManager.refresh();
|
windowManager->refresh();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ptyWindow->writeFunctionKeyToClient(input.mapKeyNcursesToVTerm());
|
ptyWindow->writeFunctionKeyToClient(input.mapKeyNcursesToVTerm());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
App.hpp
12
App.hpp
|
@ -7,16 +7,28 @@
|
||||||
#define A3B2AE4E_0A39_468C_8CCA_E6508166702A
|
#define A3B2AE4E_0A39_468C_8CCA_E6508166702A
|
||||||
|
|
||||||
#include <cursesapp.h>
|
#include <cursesapp.h>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace krikkel::NCurses
|
namespace krikkel::NCurses
|
||||||
{
|
{
|
||||||
|
class VerticalTilingWindowManager;
|
||||||
|
class Window;
|
||||||
|
class PtyWindow;
|
||||||
|
|
||||||
class DemoApp : public NCursesApplication
|
class DemoApp : public NCursesApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DemoApp();
|
DemoApp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
VerticalTilingWindowManager *windowManager;
|
||||||
|
Window *dummyWindowTop, *dummyWindowBottom;
|
||||||
|
PtyWindow *ptyWindow;
|
||||||
|
std::recursive_mutex ncursesMutex;
|
||||||
|
|
||||||
int run() override;
|
int run() override;
|
||||||
|
void setUpWindows();
|
||||||
|
void mainLoop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue