2022-04-03 10:16:20 +02:00
|
|
|
/**
|
|
|
|
* @author Christian Burger (christian@krikkel.de)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NCursesPtyApp.hpp"
|
|
|
|
#include "NCursesPtyWindow.hpp"
|
|
|
|
#include "Debug.hpp"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utmp.h>
|
2022-04-05 10:23:50 +02:00
|
|
|
#include <cstdlib>
|
2022-04-03 10:16:20 +02:00
|
|
|
|
2022-04-05 10:28:10 +02:00
|
|
|
namespace krikkel::NCursesPtyWindow
|
2022-04-03 10:16:20 +02:00
|
|
|
{
|
2022-04-05 10:23:50 +02:00
|
|
|
NCursesPtyApp::NCursesPtyApp() : NCursesApplication(false)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-04-03 10:16:20 +02:00
|
|
|
int NCursesPtyApp::run()
|
|
|
|
{
|
|
|
|
NCursesPtyWindow *ptyWindow = new NCursesPtyWindow(
|
|
|
|
Root_Window->lines()
|
|
|
|
, Root_Window->cols()
|
|
|
|
, 0
|
|
|
|
, 0);
|
|
|
|
|
|
|
|
if(fork() == 0)
|
|
|
|
{
|
2022-04-05 10:23:50 +02:00
|
|
|
const char *shellPath = getenv("SHELL");
|
|
|
|
if(!shellPath)
|
|
|
|
shellPath = "/bin/bash";
|
|
|
|
|
2022-04-03 10:16:20 +02:00
|
|
|
login_tty(ptyWindow->getFdPtyClient());
|
|
|
|
const int sizeArg = 2;
|
2022-04-05 10:23:50 +02:00
|
|
|
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);
|
2022-04-03 10:16:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int input;
|
2022-04-05 10:23:50 +02:00
|
|
|
while(true)
|
2022-04-03 10:16:20 +02:00
|
|
|
{
|
2022-04-05 10:23:50 +02:00
|
|
|
input = ptyWindow->getch();
|
2022-04-05 12:34:35 +02:00
|
|
|
if(input == KEY_RESIZE)
|
|
|
|
{
|
|
|
|
ptyWindow->wresize(Root_Window->lines(), Root_Window->cols());
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-03 10:16:20 +02:00
|
|
|
ptyWindow->writeToClient((unsigned char) input);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|