refactoring: wide character methods to Window

This commit is contained in:
Christian Burger 2022-04-25 15:55:39 +02:00
parent 746e458cd2
commit 3af1284cf8
5 changed files with 72 additions and 36 deletions

View file

@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 17)
include(CTest)
enable_testing()
add_library(NCursesPtyWindow PtyWindow.cpp SingleUserInput.cpp Debug.cpp)
add_library(NCursesPtyWindow Window.cpp PtyWindow.cpp SingleUserInput.cpp Debug.cpp)
### path to own system includes
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/include")

View file

@ -19,7 +19,7 @@ namespace krikkel::NCursesPtyWindow
using std::lock_guard;
PtyWindow::PtyWindow(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x)
: writeToNCursesMutex(writeToNCursesMutex), NCursesWindow(lines, columns, y, x)
: writeToNCursesMutex(writeToNCursesMutex), Window(lines, columns, y, x)
{
// to get the original terminal we need to shutdown ncurses for a moment
/// @todo maybe try `reset_prog_mode()` and `reset_shell_mode()` instead
@ -83,13 +83,6 @@ namespace krikkel::NCursesPtyWindow
vterm_keyboard_key(pseudoTerminal, key, VTERM_MOD_NONE);
}
SingleUserInput PtyWindow::readSingleUserInput()
{
wint_t input;
int result = get_wch(&input);
return SingleUserInput(result, input);
}
void PtyWindow::readFromPtyClientThreadMethod()
{
/// @todo in theory, there is no need for a timeout or select …
@ -254,16 +247,6 @@ namespace krikkel::NCursesPtyWindow
}
}
int PtyWindow::add_wch(const cchar_t *character)
{
return ::wadd_wch(w, character);
}
int PtyWindow::get_wch(wint_t *character)
{
return ::wget_wch(w, character);
}
int PtyWindow::refresh()
{
lock_guard nCursesLock(*writeToNCursesMutex);

30
Window.cpp Normal file
View file

@ -0,0 +1,30 @@
/**
* @author Christian Burger (christian@krikkel.de)
*/
#include <NCursesPtyWindow/Window.hpp>
namespace krikkel::NCursesPtyWindow
{
Window::Window(int lines, int columns, int y, int x)
: NCursesWindow(lines, columns, y, x)
{}
int Window::add_wch(const cchar_t *character)
{
return ::wadd_wch(w, character);
}
int Window::get_wch(wint_t *character)
{
return ::wget_wch(w, character);
}
SingleUserInput Window::readSingleUserInput()
{
wint_t input;
int result = get_wch(&input);
return SingleUserInput(result, input);
}
}

View file

@ -7,6 +7,7 @@
#define __WINDOW_H__
#include "SingleUserInput.hpp"
#include "Window.hpp"
#include <cursesw.h>
#include <pty.h>
@ -15,21 +16,9 @@
#include <thread>
#include <mutex>
#ifdef add_wch
inline void UNDEF(add_wch)(const cchar_t *character) { add_wch(character); }
#undef add_wch
#define add_wch UNDEF(add_wch)
#endif
#ifdef get_wch
inline void UNDEF(get_wch)(wint_t *character) { get_wch(character); }
#undef get_wch
#define get_wch UNDEF(get_wch)
#endif
namespace krikkel::NCursesPtyWindow
{
class PtyWindow : public NCursesWindow
class PtyWindow : public Window
{
public:
PtyWindow(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x);
@ -40,10 +29,6 @@ namespace krikkel::NCursesPtyWindow
void writeUnicodeCharToClient(wint_t character);
void writeKeyToClient(VTermKey key);
SingleUserInput readSingleUserInput();
int add_wch(const cchar_t *character);
int get_wch(wint_t *character);
int refresh() override;
int wresize(int rows, int cols);

View file

@ -0,0 +1,38 @@
/**
* @brief Providing wide character methods missing in NCursesWindow.
* @author Christian Burger (christian@krikkel.de)
*/
#ifndef A2C3FDB7_7A85_4527_BC85_366E14149EB8
#define A2C3FDB7_7A85_4527_BC85_366E14149EB8
#include "SingleUserInput.hpp"
#include <ncursesw/cursesw.h>
#ifdef add_wch
inline void UNDEF(add_wch)(const cchar_t *character) { add_wch(character); }
#undef add_wch
#define add_wch UNDEF(add_wch)
#endif
#ifdef get_wch
inline void UNDEF(get_wch)(wint_t *character) { get_wch(character); }
#undef get_wch
#define get_wch UNDEF(get_wch)
#endif
namespace krikkel::NCursesPtyWindow
{
class Window : public NCursesWindow
{
public:
Window(int lines, int columns, int y, int x);
int add_wch(const cchar_t *character);
int get_wch(wint_t *character);
SingleUserInput readSingleUserInput();
};
}
#endif /* A2C3FDB7_7A85_4527_BC85_366E14149EB8 */