kNCurses/NCursesPtyApp.cpp
Christian Burger 6d02539162 fixes #4 — albeit very slow
#2 needs fixing to remedy that problem with performance
2022-04-05 12:34:35 +02:00

60 lines
1.5 KiB
C++

/**
* @author Christian Burger (christian@krikkel.de)
*/
#include "NCursesPtyApp.hpp"
#include "NCursesPtyWindow.hpp"
#include "Debug.hpp"
#include <unistd.h>
#include <utmp.h>
#include <cstdlib>
namespace krikkel::NCursesPtyWindow
{
NCursesPtyApp::NCursesPtyApp() : NCursesApplication(false)
{
}
int NCursesPtyApp::run()
{
NCursesPtyWindow *ptyWindow = new NCursesPtyWindow(
Root_Window->lines()
, Root_Window->cols()
, 0
, 0);
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, "<CTRL>+C exits shell.\n\n");
execv(shellPath, const_cast<char * const *>(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);
}
int input;
while(true)
{
input = ptyWindow->getch();
if(input == KEY_RESIZE)
{
ptyWindow->wresize(Root_Window->lines(), Root_Window->cols());
continue;
}
ptyWindow->writeToClient((unsigned char) input);
}
return 0;
}
}