renamed Window
to PtyWindow
Making space for a more general base window class with support for wide characters.
This commit is contained in:
parent
ae6130f095
commit
746e458cd2
17
.vscode/c_cpp_properties.json
vendored
Normal file
17
.vscode/c_cpp_properties.json
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${default}"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -55,5 +55,8 @@
|
|||
"typeinfo": "cpp",
|
||||
"pointers": "cpp"
|
||||
},
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||
"C_Cpp.default.includePath": [
|
||||
"${workspaceFolder}/include"
|
||||
]
|
||||
}
|
5
App.cpp
5
App.cpp
|
@ -4,11 +4,12 @@
|
|||
|
||||
#include "App.hpp"
|
||||
#include "Debug.hpp"
|
||||
#include <NCursesPtyWindow/Window.hpp>
|
||||
#include <NCursesPtyWindow/PtyWindow.hpp>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
|
||||
namespace krikkel::NCursesPtyWindow
|
||||
{
|
||||
|
@ -21,7 +22,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
{
|
||||
std::mutex writeMutex;
|
||||
|
||||
Window *ptyWindow = new Window(&writeMutex
|
||||
PtyWindow *ptyWindow = new PtyWindow(&writeMutex
|
||||
, Root_Window->lines()
|
||||
, Root_Window->cols()
|
||||
, 0
|
||||
|
|
|
@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 17)
|
|||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
add_library(NCursesPtyWindow Window.cpp SingleUserInput.cpp Debug.cpp)
|
||||
add_library(NCursesPtyWindow PtyWindow.cpp SingleUserInput.cpp Debug.cpp)
|
||||
|
||||
### path to own system includes
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/include")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @author Christian Burger (christian@krikkel.de)
|
||||
*/
|
||||
|
||||
#include <NCursesPtyWindow/Window.hpp>
|
||||
#include <NCursesPtyWindow/PtyWindow.hpp>
|
||||
#include "Debug.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
|
@ -18,7 +18,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
using gsl::narrow;
|
||||
using std::lock_guard;
|
||||
|
||||
Window::Window(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x)
|
||||
PtyWindow::PtyWindow(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x)
|
||||
: writeToNCursesMutex(writeToNCursesMutex), NCursesWindow(lines, columns, y, x)
|
||||
{
|
||||
// to get the original terminal we need to shutdown ncurses for a moment
|
||||
|
@ -50,47 +50,47 @@ namespace krikkel::NCursesPtyWindow
|
|||
|
||||
/// @todo block all signals, this thread does not handle any
|
||||
readPtyClientThread =
|
||||
std::thread(&Window::readFromPtyClientThreadMethod, this);
|
||||
std::thread(&PtyWindow::readFromPtyClientThreadMethod, this);
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
PtyWindow::~PtyWindow()
|
||||
{
|
||||
close(fdPtyHost);
|
||||
close(fdPtyClient);
|
||||
vterm_free(pseudoTerminal);
|
||||
}
|
||||
|
||||
int Window::getFdPtyClient() const
|
||||
int PtyWindow::getFdPtyClient() const
|
||||
{
|
||||
return fdPtyClient;
|
||||
}
|
||||
|
||||
void Window::writeToClient(const char *output, size_t length)
|
||||
void PtyWindow::writeToClient(const char *output, size_t length)
|
||||
{
|
||||
lock_guard writeLock(writeToPseudoTerminalMutex);
|
||||
write(fdPtyHost, output, length);
|
||||
__debug_log("written to PTY client: '" + __debug_make_bytes_printable(std::string(output, length)) + '\'');
|
||||
}
|
||||
|
||||
void Window::writeUnicodeCharToClient(wint_t character)
|
||||
void PtyWindow::writeUnicodeCharToClient(wint_t character)
|
||||
{
|
||||
vterm_keyboard_unichar(pseudoTerminal, character, VTERM_MOD_NONE);
|
||||
}
|
||||
|
||||
void Window::writeKeyToClient(VTermKey key)
|
||||
void PtyWindow::writeKeyToClient(VTermKey key)
|
||||
{
|
||||
__debug_log("writing key: " + std::to_string(key));
|
||||
vterm_keyboard_key(pseudoTerminal, key, VTERM_MOD_NONE);
|
||||
}
|
||||
|
||||
SingleUserInput Window::readSingleUserInput()
|
||||
SingleUserInput PtyWindow::readSingleUserInput()
|
||||
{
|
||||
wint_t input;
|
||||
int result = get_wch(&input);
|
||||
return SingleUserInput(result, input);
|
||||
}
|
||||
|
||||
void Window::readFromPtyClientThreadMethod()
|
||||
void PtyWindow::readFromPtyClientThreadMethod()
|
||||
{
|
||||
/// @todo in theory, there is no need for a timeout or select …
|
||||
/// file descriptor is blocking
|
||||
|
@ -107,7 +107,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
}
|
||||
}
|
||||
|
||||
void Window::readFromPtyClient()
|
||||
void PtyWindow::readFromPtyClient()
|
||||
{
|
||||
size_t bytesRead = read(fdPtyHost, ptyClientOutputBuffer, PTY_CLIENT_OUTPUT_BUFFER_SIZE);
|
||||
if(bytesRead != -1 && bytesRead != 0)
|
||||
|
@ -118,7 +118,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
__debug_log("read from PTY client: '" + __debug_make_bytes_printable(std::string(ptyClientOutputBuffer, bytesRead)) + '\'');
|
||||
}
|
||||
|
||||
VTermScreenCallbacks Window::screenCallbacks =
|
||||
VTermScreenCallbacks PtyWindow::screenCallbacks =
|
||||
{
|
||||
.damage = staticHandlerDamage,
|
||||
.moverect = staticHandlerMoveRect,
|
||||
|
@ -130,7 +130,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
.sb_popline = staticHandlerPopLine,
|
||||
};
|
||||
|
||||
int Window::handlerDamage(VTermRect rect)
|
||||
int PtyWindow::handlerDamage(VTermRect rect)
|
||||
{
|
||||
for(int x = rect.start_col; x < rect.end_col; ++x)
|
||||
for(int y = rect.start_row; y < rect.end_row; ++y)
|
||||
|
@ -141,7 +141,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerMoveRect(VTermRect dest, VTermRect src)
|
||||
int PtyWindow::handlerMoveRect(VTermRect dest, VTermRect src)
|
||||
{
|
||||
__debug_log("(unimplemented) move content in rectangle from ("
|
||||
+ std::to_string(src.start_col) + ", "
|
||||
|
@ -158,7 +158,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible)
|
||||
int PtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible)
|
||||
{
|
||||
/// @todo maybe use `mvcur()` instead?
|
||||
cursorX = pos.col;
|
||||
|
@ -167,7 +167,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerSetTermProp(VTermProp prop, VTermValue *val)
|
||||
int PtyWindow::handlerSetTermProp(VTermProp prop, VTermValue *val)
|
||||
{
|
||||
/// @todo maybe use "vterm_get_prop_type() —> bool, number, string"?
|
||||
__debug_stringify_switch_begin(handlerSetTermProp, prop, val);
|
||||
|
@ -190,44 +190,44 @@ namespace krikkel::NCursesPtyWindow
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerBell()
|
||||
int PtyWindow::handlerBell()
|
||||
{
|
||||
beep();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerResize(int rows, int cols)
|
||||
int PtyWindow::handlerResize(int rows, int cols)
|
||||
{
|
||||
__debug_log("unimplemented handler called");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerPushLine(int cols, const VTermScreenCell *cells)
|
||||
int PtyWindow::handlerPushLine(int cols, const VTermScreenCell *cells)
|
||||
{
|
||||
__debug_log("(unimplemented) push line with " + std::to_string(cols) + " columns");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Window::handlerPopLine(int cols, VTermScreenCell *cells)
|
||||
int PtyWindow::handlerPopLine(int cols, VTermScreenCell *cells)
|
||||
{
|
||||
__debug_log("unimplemented handler called");
|
||||
return 0;
|
||||
}
|
||||
|
||||
attr_t Window::extractAttributesFromVTermCell(VTermScreenCell vTermCell)
|
||||
attr_t PtyWindow::extractAttributesFromVTermCell(VTermScreenCell vTermCell)
|
||||
{
|
||||
attr_t result = A_NORMAL;
|
||||
//__debug_log("unimplemented method called");
|
||||
return result;
|
||||
}
|
||||
|
||||
short Window::extractColorFromVTermCell(VTermScreenCell vTermCell)
|
||||
short PtyWindow::extractColorFromVTermCell(VTermScreenCell vTermCell)
|
||||
{
|
||||
//__debug_log("unimplemented method called");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Window::copyPtyCellToNCursesWindow(int x, int y)
|
||||
void PtyWindow::copyPtyCellToNCursesWindow(int x, int y)
|
||||
{
|
||||
VTermPos cellPosition = {y, x};
|
||||
VTermScreenCell vTermCell;
|
||||
|
@ -254,17 +254,17 @@ namespace krikkel::NCursesPtyWindow
|
|||
}
|
||||
}
|
||||
|
||||
int Window::add_wch(const cchar_t *character)
|
||||
int PtyWindow::add_wch(const cchar_t *character)
|
||||
{
|
||||
return ::wadd_wch(w, character);
|
||||
}
|
||||
|
||||
int Window::get_wch(wint_t *character)
|
||||
int PtyWindow::get_wch(wint_t *character)
|
||||
{
|
||||
return ::wget_wch(w, character);
|
||||
}
|
||||
|
||||
int Window::refresh()
|
||||
int PtyWindow::refresh()
|
||||
{
|
||||
lock_guard nCursesLock(*writeToNCursesMutex);
|
||||
move(cursorY, cursorX);
|
||||
|
@ -273,7 +273,7 @@ namespace krikkel::NCursesPtyWindow
|
|||
|
||||
/// @todo potential racing condition where drawing into terminal while
|
||||
/// resizing?
|
||||
int Window::wresize(int rows, int cols)
|
||||
int PtyWindow::wresize(int rows, int cols)
|
||||
{
|
||||
lock_guard nCursesLock(*writeToNCursesMutex);
|
||||
lock_guard writeLock(writeToPseudoTerminalMutex);
|
||||
|
@ -288,57 +288,57 @@ namespace krikkel::NCursesPtyWindow
|
|||
return NCursesWindow::wresize(rows, cols);
|
||||
}
|
||||
|
||||
int Window::staticHandlerDamage(VTermRect rect, void *user)
|
||||
int PtyWindow::staticHandlerDamage(VTermRect rect, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerDamage(rect);
|
||||
}
|
||||
|
||||
int Window::staticHandlerMoveRect(VTermRect dest, VTermRect src, void *user)
|
||||
int PtyWindow::staticHandlerMoveRect(VTermRect dest, VTermRect src, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerMoveRect(dest, src);
|
||||
}
|
||||
|
||||
int Window::staticHandlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible, void *user)
|
||||
int PtyWindow::staticHandlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerMoveCursor(pos, oldpos, visible);
|
||||
}
|
||||
|
||||
int Window::staticHandlerSetTermProp(VTermProp prop, VTermValue *val, void *user)
|
||||
int PtyWindow::staticHandlerSetTermProp(VTermProp prop, VTermValue *val, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerSetTermProp(prop, val);
|
||||
}
|
||||
|
||||
int Window::staticHandlerBell(void *user)
|
||||
int PtyWindow::staticHandlerBell(void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerBell();
|
||||
}
|
||||
|
||||
int Window::staticHandlerResize(int rows, int cols, void *user)
|
||||
int PtyWindow::staticHandlerResize(int rows, int cols, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerResize(rows, cols);
|
||||
}
|
||||
|
||||
int Window::staticHandlerPushLine(int cols, const VTermScreenCell *cells, void *user)
|
||||
int PtyWindow::staticHandlerPushLine(int cols, const VTermScreenCell *cells, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerPushLine(cols, cells);
|
||||
}
|
||||
|
||||
int Window::staticHandlerPopLine(int cols, VTermScreenCell *cells, void *user)
|
||||
int PtyWindow::staticHandlerPopLine(int cols, VTermScreenCell *cells, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
return instance->handlerPopLine(cols, cells);
|
||||
}
|
||||
|
||||
void Window::staticHandlerOutput(const char *s, size_t len, void *user)
|
||||
void PtyWindow::staticHandlerOutput(const char *s, size_t len, void *user)
|
||||
{
|
||||
Window *instance = static_cast<Window *>(user);
|
||||
PtyWindow *instance = static_cast<PtyWindow *>(user);
|
||||
__debug_log("output handler writing to client: '" + __debug_make_bytes_printable(std::string(s, len)) + "'");
|
||||
instance->writeToClient(s, len);
|
||||
}
|
|
@ -29,11 +29,11 @@ inline void UNDEF(get_wch)(wint_t *character) { get_wch(character); }
|
|||
|
||||
namespace krikkel::NCursesPtyWindow
|
||||
{
|
||||
class Window : public NCursesWindow
|
||||
class PtyWindow : public NCursesWindow
|
||||
{
|
||||
public:
|
||||
Window(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x);
|
||||
~Window();
|
||||
PtyWindow(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x);
|
||||
~PtyWindow();
|
||||
|
||||
int getFdPtyClient() const;
|
||||
void writeToClient(const char * string, size_t length);
|
Loading…
Reference in a new issue