From 3af1284cf881cbb29ac7e2b1f09e3d14cd8ba3b8 Mon Sep 17 00:00:00 2001 From: Christian Burger Date: Mon, 25 Apr 2022 15:55:39 +0200 Subject: [PATCH] refactoring: wide character methods to `Window` --- CMakeLists.txt | 2 +- PtyWindow.cpp | 19 +------------ Window.cpp | 30 ++++++++++++++++++++ include/NCursesPtyWindow/PtyWindow.hpp | 19 ++----------- include/NCursesPtyWindow/Window.hpp | 38 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 Window.cpp create mode 100644 include/NCursesPtyWindow/Window.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f8d7ad5..2d58218 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/PtyWindow.cpp b/PtyWindow.cpp index 6e2e913..4c73428 100644 --- a/PtyWindow.cpp +++ b/PtyWindow.cpp @@ -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); diff --git a/Window.cpp b/Window.cpp new file mode 100644 index 0000000..4647ff2 --- /dev/null +++ b/Window.cpp @@ -0,0 +1,30 @@ +/** + * @author Christian Burger (christian@krikkel.de) + */ + +#include + +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); + } + +} \ No newline at end of file diff --git a/include/NCursesPtyWindow/PtyWindow.hpp b/include/NCursesPtyWindow/PtyWindow.hpp index ee8fb84..d050521 100644 --- a/include/NCursesPtyWindow/PtyWindow.hpp +++ b/include/NCursesPtyWindow/PtyWindow.hpp @@ -7,6 +7,7 @@ #define __WINDOW_H__ #include "SingleUserInput.hpp" +#include "Window.hpp" #include #include @@ -15,21 +16,9 @@ #include #include -#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); diff --git a/include/NCursesPtyWindow/Window.hpp b/include/NCursesPtyWindow/Window.hpp new file mode 100644 index 0000000..6598a82 --- /dev/null +++ b/include/NCursesPtyWindow/Window.hpp @@ -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 + +#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 */