/** * @author Christian Burger (christian@krikkel.de) */ #include "App.hpp" #include "Debug.hpp" #include #include #include #include #include #include #include namespace krikkel::NCurses { using std::scoped_lock; DemoApp::DemoApp() : NCursesApplication(false) { } int DemoApp::run() { std::recursive_mutex ncursesMutex; VerticalTilingWindowManager windowManager(Root_Window, &ncursesMutex); Window *dummyWindow = new Window(&windowManager); dummyWindow->move(0, 0); PtyWindow *ptyWindow = new PtyWindow(&ncursesMutex, 0, 0, 0, 0); windowManager.addWindow(ptyWindow); new Window(&windowManager); windowManager.updateLayout(); windowManager.refresh(); if(fork() == 0) { const char *shellPath = getenv("SHELL"); if(!shellPath) shellPath = "/bin/bash"; login_tty(ptyWindow->getFdPtyClient()); const int sizeArg = 2; const char *arg[sizeArg] = {shellPath, NULL}; fprintf(stderr, "+C exits shell.\n\n"); execv(shellPath, const_cast(arg)); fprintf(stderr, "Well, well, well … could not start a shell. We " "tried `%s`. Maybe set `SHELL` environment variable" " to a working value?", shellPath); exit(1); } while(true) { SingleUserInput input = windowManager.readSingleUserInput(); if(input.isNormalKey()) { ptyWindow->writeUnicodeCharToClient(input.getRawInput()); { scoped_lock lock(ncursesMutex); dummyWindow->addch(input.getRawInput()); dummyWindow->refresh(); } } if(input.isFunctionKey()) { switch(input.getRawInput()) { case KEY_RESIZE: windowManager.updateLayout(); break; case KEY_F(1): windowManager.hideWindow(ptyWindow); windowManager.updateLayout(); windowManager.refresh(); break; case KEY_F(2): windowManager.showWindow(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); windowManager.updateLayout(); windowManager.refresh(); break; case KEY_F(5): windowManager.refresh(); break; default: ptyWindow->writeKeyToClient(input.mapKeyNcursesToVTerm()); } } } return 0; } }