76 lines
3 KiB
C++
76 lines
3 KiB
C++
/**
|
|
* @brief `ncurses` window displaying contents of a pseudo terminal
|
|
* @author Christian Burger (christian@krikkel.de)
|
|
* @todo remove all invalid constructors
|
|
*/
|
|
|
|
#ifndef __WINDOW_H__
|
|
#define __WINDOW_H__
|
|
|
|
#include "Window.hpp"
|
|
|
|
#include <cursesw.h>
|
|
#include <pty.h>
|
|
#include <vterm.h>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <mutex>
|
|
|
|
namespace krikkel::NCurses
|
|
{
|
|
class PtyWindow : public Window
|
|
{
|
|
public:
|
|
PtyWindow(std::recursive_mutex *ncursesMutex, int lines, int columns, int y, int x);
|
|
~PtyWindow();
|
|
|
|
int getFdPtyClient() const;
|
|
void writeUnicodeCharToClient(wint_t character);
|
|
void writeFunctionKeyToClient(VTermKey key);
|
|
|
|
int refresh() override;
|
|
int resize(int rows, int cols) override;
|
|
|
|
private:
|
|
int fdPtyHost, fdPtyClient;
|
|
struct termios terminalParameters;
|
|
VTerm *pseudoTerminal;
|
|
std::recursive_mutex ptyMutex;
|
|
std::recursive_mutex *ncursesMutex;
|
|
VTermScreen *pseudoTerminalScreen;
|
|
static VTermScreenCallbacks screenCallbacks;
|
|
/// @todo one line is at most 4096 chars long
|
|
static const uint16_t PTY_CLIENT_OUTPUT_BUFFER_SIZE = 2 * 4096;
|
|
char ptyClientOutputBuffer[PTY_CLIENT_OUTPUT_BUFFER_SIZE];
|
|
uint16_t cursorX, cursorY;
|
|
|
|
std::thread readPtyClientThread;
|
|
void readFromPtyClientThreadMethod();
|
|
void readFromPtyClient();
|
|
void writeToPtyClient(const char * string, size_t length);
|
|
|
|
int handlerDamage(VTermRect rect);
|
|
int handlerMoveRect(VTermRect dest, VTermRect src);
|
|
int handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible);
|
|
int handlerSetTermProp(VTermProp prop, VTermValue *val);
|
|
int handlerBell();
|
|
int handlerResize(int rows, int cols);
|
|
int handlerPushLine(int cols, const VTermScreenCell *cells);
|
|
int handlerPopLine(int cols, VTermScreenCell *cells);
|
|
|
|
attr_t extractAttributesFromVTermCell(VTermScreenCell cell);
|
|
short extractColorFromVTermCell(VTermScreenCell cell);
|
|
void copyPtyCellToNCursesWindow(int x, int y);
|
|
|
|
static int staticHandlerDamage(VTermRect rect, void *user);
|
|
static int staticHandlerMoveRect(VTermRect dest, VTermRect src, void *user);
|
|
static int staticHandlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible, void *user);
|
|
static int staticHandlerSetTermProp(VTermProp prop, VTermValue *val, void *user);
|
|
static int staticHandlerBell(void *user);
|
|
static int staticHandlerResize(int rows, int cols, void *user);
|
|
static int staticHandlerPushLine(int cols, const VTermScreenCell *cells, void *user);
|
|
static int staticHandlerPopLine(int cols, VTermScreenCell *cells, void *user);
|
|
static void staticHandlerOutput(const char *s, size_t len, void *user);
|
|
};
|
|
}
|
|
#endif // __WINDOW_H__
|