From 2a70695bcb42fed385f601a818c6841eff94e673 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Thu, 22 Aug 2024 15:45:46 +0200 Subject: [PATCH] Support for custom descriptors (#26) --- include/replxx.h | 2 +- include/replxx.hxx | 2 +- src/escape.cxx | 412 ++++++++++++++++++++++---------------------- src/escape.hxx | 4 +- src/replxx.cxx | 18 +- src/replxx_impl.cxx | 70 ++++---- src/replxx_impl.hxx | 8 +- src/terminal.cxx | 68 ++++---- src/terminal.hxx | 14 +- src/util.cxx | 4 +- src/util.hxx | 2 +- src/windows.cxx | 1 + 12 files changed, 315 insertions(+), 290 deletions(-) diff --git a/include/replxx.h b/include/replxx.h index b02baa3..fef0977 100644 --- a/include/replxx.h +++ b/include/replxx.h @@ -224,7 +224,7 @@ typedef struct ReplxxHistoryEntryTag { * * \return Replxx library resource holder. */ -REPLXX_IMPEXP Replxx* replxx_init( void ); +// REPLXX_IMPEXP Replxx* replxx_init( void ); /*! \brief Cleanup resources used by Replxx library. * diff --git a/include/replxx.hxx b/include/replxx.hxx index 4928cb2..c58991b 100644 --- a/include/replxx.hxx +++ b/include/replxx.hxx @@ -391,7 +391,7 @@ private: #endif public: - Replxx( void ); + Replxx( std::istream & input_stream_, std::ostream & output_stream_, int in_fd_, int out_fd_, int err_fd_ ); Replxx( Replxx&& ) = default; Replxx& operator = ( Replxx&& ) = default; diff --git a/src/escape.cxx b/src/escape.cxx index dda1ab0..a0a14c3 100644 --- a/src/escape.cxx +++ b/src/escape.cxx @@ -49,80 +49,80 @@ static char32_t thisKeyMetaCtrl = 0; // holds pre-set Meta and/or Ctrl modifiers // a called routine returns either a character or -1 to indicate parsing // failure. // -char32_t doDispatch(char32_t c, CharacterDispatch& dispatchTable) { +char32_t doDispatch(int in_fd_, int err_fd_, char32_t c, CharacterDispatch& dispatchTable) { for (unsigned int i = 0; i < dispatchTable.len; ++i) { if (static_cast(dispatchTable.chars[i]) == c) { - return dispatchTable.dispatch[i](c); + return dispatchTable.dispatch[i](in_fd_, err_fd_, c); } } - return dispatchTable.dispatch[dispatchTable.len](c); + return dispatchTable.dispatch[dispatchTable.len](in_fd_, err_fd_, c); } // Final dispatch routines -- return something // -static char32_t normalKeyRoutine(char32_t c) { return thisKeyMetaCtrl | c; } -static char32_t upArrowKeyRoutine(char32_t) { +static char32_t normalKeyRoutine(int, int, char32_t c) { return thisKeyMetaCtrl | c; } +static char32_t upArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::UP;; } -static char32_t downArrowKeyRoutine(char32_t) { +static char32_t downArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::DOWN; } -static char32_t rightArrowKeyRoutine(char32_t) { +static char32_t rightArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::RIGHT; } -static char32_t leftArrowKeyRoutine(char32_t) { +static char32_t leftArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::LEFT; } -static char32_t homeKeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::HOME; } -static char32_t endKeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::END; } -static char32_t shiftTabRoutine(char32_t) { return Replxx::KEY::BASE_SHIFT | Replxx::KEY::TAB; } -static char32_t f1KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F1; } -static char32_t f2KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F2; } -static char32_t f3KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F3; } -static char32_t f4KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F4; } -static char32_t f5KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F5; } -static char32_t f6KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F6; } -static char32_t f7KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F7; } -static char32_t f8KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F8; } -static char32_t f9KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F9; } -static char32_t f10KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F10; } -static char32_t f11KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F11; } -static char32_t f12KeyRoutine(char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F12; } -static char32_t pageUpKeyRoutine(char32_t) { +static char32_t homeKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::HOME; } +static char32_t endKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::END; } +static char32_t shiftTabRoutine(int, int, char32_t) { return Replxx::KEY::BASE_SHIFT | Replxx::KEY::TAB; } +static char32_t f1KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F1; } +static char32_t f2KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F2; } +static char32_t f3KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F3; } +static char32_t f4KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F4; } +static char32_t f5KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F5; } +static char32_t f6KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F6; } +static char32_t f7KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F7; } +static char32_t f8KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F8; } +static char32_t f9KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F9; } +static char32_t f10KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F10; } +static char32_t f11KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F11; } +static char32_t f12KeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::F12; } +static char32_t pageUpKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::PAGE_UP; } -static char32_t pageDownKeyRoutine(char32_t) { +static char32_t pageDownKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::PAGE_DOWN; } -static char32_t deleteCharRoutine(char32_t) { +static char32_t deleteCharRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::BACKSPACE; } // key labeled Backspace -static char32_t insertKeyRoutine(char32_t) { +static char32_t insertKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::INSERT; } // key labeled Delete -static char32_t deleteKeyRoutine(char32_t) { +static char32_t deleteKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::DELETE; } // key labeled Delete -static char32_t ctrlUpArrowKeyRoutine(char32_t) { +static char32_t ctrlUpArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::BASE_CONTROL | Replxx::KEY::UP; } -static char32_t ctrlDownArrowKeyRoutine(char32_t) { +static char32_t ctrlDownArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::BASE_CONTROL | Replxx::KEY::DOWN; } -static char32_t ctrlRightArrowKeyRoutine(char32_t) { +static char32_t ctrlRightArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::BASE_CONTROL | Replxx::KEY::RIGHT; } -static char32_t ctrlLeftArrowKeyRoutine(char32_t) { +static char32_t ctrlLeftArrowKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::BASE_CONTROL | Replxx::KEY::LEFT; } -static char32_t bracketPasteStartKeyRoutine(char32_t) { +static char32_t bracketPasteStartKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::PASTE_START; } -static char32_t bracketPasteFinishKeyRoutine(char32_t) { +static char32_t bracketPasteFinishKeyRoutine(int, int, char32_t) { return thisKeyMetaCtrl | Replxx::KEY::PASTE_FINISH; } -static char32_t escFailureRoutine(char32_t) { - beep(); +static char32_t escFailureRoutine(int, int err_fd_, char32_t) { + beep(err_fd_); return -1; } @@ -147,23 +147,23 @@ static CharacterDispatch escLeftBracket1Semicolon2or3or5Dispatch = { // Handle ESC [ 1 ; escape sequences // -static char32_t escLeftBracket1Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket1Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket1Semicolon2or3or5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket1Semicolon2or3or5Dispatch); } -static char32_t escLeftBracket1Semicolon3Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket1Semicolon3Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_META; - return doDispatch(c, escLeftBracket1Semicolon2or3or5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket1Semicolon2or3or5Dispatch); } -static char32_t escLeftBracket1Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket1Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket1Semicolon2or3or5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket1Semicolon2or3or5Dispatch); } static CharacterDispatchRoutine escLeftBracket1SemicolonRoutines[] = { escLeftBracket1Semicolon2Routine, @@ -177,10 +177,10 @@ static CharacterDispatch escLeftBracket1SemicolonDispatch = { // Handle ESC [ 1 ; escape sequences // -static char32_t escLeftBracket1SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket1SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket1SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket1SemicolonDispatch); } // (S)-F5 @@ -190,11 +190,11 @@ static CharacterDispatchRoutine escLeftBracket15Semicolon2Routines[] = { static CharacterDispatch escLeftBracket15Semicolon2Dispatch = { 1, "~", escLeftBracket15Semicolon2Routines }; -static char32_t escLeftBracket15Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket15Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket15Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket15Semicolon2Dispatch); } // (C)-F5 @@ -204,11 +204,11 @@ static CharacterDispatchRoutine escLeftBracket15Semicolon5Routines[] = { static CharacterDispatch escLeftBracket15Semicolon5Dispatch = { 1, "~", escLeftBracket15Semicolon5Routines }; -static char32_t escLeftBracket15Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket15Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket15Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket15Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket15SemicolonRoutines[] = { @@ -217,10 +217,10 @@ static CharacterDispatchRoutine escLeftBracket15SemicolonRoutines[] = { static CharacterDispatch escLeftBracket15SemicolonDispatch = { 2, "25", escLeftBracket15SemicolonRoutines }; -static char32_t escLeftBracket15SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket15SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket15SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket15SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket15Routines[] = { @@ -229,10 +229,10 @@ static CharacterDispatchRoutine escLeftBracket15Routines[] = { static CharacterDispatch escLeftBracket15Dispatch = { 2, "~;", escLeftBracket15Routines }; -static char32_t escLeftBracket15Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket15Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket15Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket15Dispatch); } // (S)-F6 @@ -242,11 +242,11 @@ static CharacterDispatchRoutine escLeftBracket17Semicolon2Routines[] = { static CharacterDispatch escLeftBracket17Semicolon2Dispatch = { 1, "~", escLeftBracket17Semicolon2Routines }; -static char32_t escLeftBracket17Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket17Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket17Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket17Semicolon2Dispatch); } // (C)-F6 @@ -256,11 +256,11 @@ static CharacterDispatchRoutine escLeftBracket17Semicolon5Routines[] = { static CharacterDispatch escLeftBracket17Semicolon5Dispatch = { 1, "~", escLeftBracket17Semicolon5Routines }; -static char32_t escLeftBracket17Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket17Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket17Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket17Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket17SemicolonRoutines[] = { @@ -269,10 +269,10 @@ static CharacterDispatchRoutine escLeftBracket17SemicolonRoutines[] = { static CharacterDispatch escLeftBracket17SemicolonDispatch = { 2, "25", escLeftBracket17SemicolonRoutines }; -static char32_t escLeftBracket17SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket17SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket17SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket17SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket17Routines[] = { @@ -281,10 +281,10 @@ static CharacterDispatchRoutine escLeftBracket17Routines[] = { static CharacterDispatch escLeftBracket17Dispatch = { 2, "~;", escLeftBracket17Routines }; -static char32_t escLeftBracket17Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket17Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket17Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket17Dispatch); } // (S)-F7 @@ -294,11 +294,11 @@ static CharacterDispatchRoutine escLeftBracket18Semicolon2Routines[] = { static CharacterDispatch escLeftBracket18Semicolon2Dispatch = { 1, "~", escLeftBracket18Semicolon2Routines }; -static char32_t escLeftBracket18Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket18Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket18Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket18Semicolon2Dispatch); } // (C)-F7 @@ -308,11 +308,11 @@ static CharacterDispatchRoutine escLeftBracket18Semicolon5Routines[] = { static CharacterDispatch escLeftBracket18Semicolon5Dispatch = { 1, "~", escLeftBracket18Semicolon5Routines }; -static char32_t escLeftBracket18Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket18Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket18Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket18Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket18SemicolonRoutines[] = { @@ -321,10 +321,10 @@ static CharacterDispatchRoutine escLeftBracket18SemicolonRoutines[] = { static CharacterDispatch escLeftBracket18SemicolonDispatch = { 2, "25", escLeftBracket18SemicolonRoutines }; -static char32_t escLeftBracket18SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket18SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket18SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket18SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket18Routines[] = { @@ -333,10 +333,10 @@ static CharacterDispatchRoutine escLeftBracket18Routines[] = { static CharacterDispatch escLeftBracket18Dispatch = { 2, "~;", escLeftBracket18Routines }; -static char32_t escLeftBracket18Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket18Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket18Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket18Dispatch); } // (S)-F8 @@ -346,11 +346,11 @@ static CharacterDispatchRoutine escLeftBracket19Semicolon2Routines[] = { static CharacterDispatch escLeftBracket19Semicolon2Dispatch = { 1, "~", escLeftBracket19Semicolon2Routines }; -static char32_t escLeftBracket19Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket19Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket19Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket19Semicolon2Dispatch); } // (C)-F8 @@ -360,11 +360,11 @@ static CharacterDispatchRoutine escLeftBracket19Semicolon5Routines[] = { static CharacterDispatch escLeftBracket19Semicolon5Dispatch = { 1, "~", escLeftBracket19Semicolon5Routines }; -static char32_t escLeftBracket19Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket19Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket19Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket19Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket19SemicolonRoutines[] = { @@ -373,10 +373,10 @@ static CharacterDispatchRoutine escLeftBracket19SemicolonRoutines[] = { static CharacterDispatch escLeftBracket19SemicolonDispatch = { 2, "25", escLeftBracket19SemicolonRoutines }; -static char32_t escLeftBracket19SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket19SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket19SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket19SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket19Routines[] = { @@ -385,10 +385,10 @@ static CharacterDispatchRoutine escLeftBracket19Routines[] = { static CharacterDispatch escLeftBracket19Dispatch = { 2, "~;", escLeftBracket19Routines }; -static char32_t escLeftBracket19Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket19Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket19Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket19Dispatch); } // Handle ESC [ 1 escape sequences @@ -415,11 +415,11 @@ static CharacterDispatchRoutine escLeftBracket20Semicolon2Routines[] = { static CharacterDispatch escLeftBracket20Semicolon2Dispatch = { 1, "~", escLeftBracket20Semicolon2Routines }; -static char32_t escLeftBracket20Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket20Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket20Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket20Semicolon2Dispatch); } // (C)-F9 @@ -429,11 +429,11 @@ static CharacterDispatchRoutine escLeftBracket20Semicolon5Routines[] = { static CharacterDispatch escLeftBracket20Semicolon5Dispatch = { 1, "~", escLeftBracket20Semicolon5Routines }; -static char32_t escLeftBracket20Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket20Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket20Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket20Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket20SemicolonRoutines[] = { @@ -442,10 +442,10 @@ static CharacterDispatchRoutine escLeftBracket20SemicolonRoutines[] = { static CharacterDispatch escLeftBracket20SemicolonDispatch = { 2, "25", escLeftBracket20SemicolonRoutines }; -static char32_t escLeftBracket20SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket20SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket20SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket20SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket200Routines[] = { @@ -454,10 +454,10 @@ static CharacterDispatchRoutine escLeftBracket200Routines[] = { static CharacterDispatch escLeftBracket200Dispatch = { 1, "~", escLeftBracket200Routines }; -static char32_t escLeftBracket200Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket200Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket200Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket200Dispatch); } static CharacterDispatchRoutine escLeftBracket201Routines[] = { @@ -466,10 +466,10 @@ static CharacterDispatchRoutine escLeftBracket201Routines[] = { static CharacterDispatch escLeftBracket201Dispatch = { 1, "~", escLeftBracket201Routines }; -static char32_t escLeftBracket201Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket201Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket201Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket201Dispatch); } static CharacterDispatchRoutine escLeftBracket20Routines[] = { @@ -478,10 +478,10 @@ static CharacterDispatchRoutine escLeftBracket20Routines[] = { static CharacterDispatch escLeftBracket20Dispatch = { 4, "~;01", escLeftBracket20Routines }; -static char32_t escLeftBracket20Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket20Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket20Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket20Dispatch); } // (S)-F10 @@ -491,11 +491,11 @@ static CharacterDispatchRoutine escLeftBracket21Semicolon2Routines[] = { static CharacterDispatch escLeftBracket21Semicolon2Dispatch = { 1, "~", escLeftBracket21Semicolon2Routines }; -static char32_t escLeftBracket21Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket21Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket21Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket21Semicolon2Dispatch); } // (C)-F10 @@ -505,11 +505,11 @@ static CharacterDispatchRoutine escLeftBracket21Semicolon5Routines[] = { static CharacterDispatch escLeftBracket21Semicolon5Dispatch = { 1, "~", escLeftBracket21Semicolon5Routines }; -static char32_t escLeftBracket21Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket21Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket21Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket21Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket21SemicolonRoutines[] = { @@ -518,10 +518,10 @@ static CharacterDispatchRoutine escLeftBracket21SemicolonRoutines[] = { static CharacterDispatch escLeftBracket21SemicolonDispatch = { 2, "25", escLeftBracket21SemicolonRoutines }; -static char32_t escLeftBracket21SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket21SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket21SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket21SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket21Routines[] = { @@ -530,10 +530,10 @@ static CharacterDispatchRoutine escLeftBracket21Routines[] = { static CharacterDispatch escLeftBracket21Dispatch = { 2, "~;", escLeftBracket21Routines }; -static char32_t escLeftBracket21Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket21Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket21Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket21Dispatch); } // (S)-F11 @@ -543,11 +543,11 @@ static CharacterDispatchRoutine escLeftBracket23Semicolon2Routines[] = { static CharacterDispatch escLeftBracket23Semicolon2Dispatch = { 1, "~", escLeftBracket23Semicolon2Routines }; -static char32_t escLeftBracket23Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket23Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket23Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket23Semicolon2Dispatch); } // (C)-F11 @@ -557,11 +557,11 @@ static CharacterDispatchRoutine escLeftBracket23Semicolon5Routines[] = { static CharacterDispatch escLeftBracket23Semicolon5Dispatch = { 1, "~", escLeftBracket23Semicolon5Routines }; -static char32_t escLeftBracket23Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket23Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket23Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket23Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket23SemicolonRoutines[] = { @@ -570,10 +570,10 @@ static CharacterDispatchRoutine escLeftBracket23SemicolonRoutines[] = { static CharacterDispatch escLeftBracket23SemicolonDispatch = { 2, "25", escLeftBracket23SemicolonRoutines }; -static char32_t escLeftBracket23SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket23SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket23SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket23SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket23Routines[] = { @@ -582,10 +582,10 @@ static CharacterDispatchRoutine escLeftBracket23Routines[] = { static CharacterDispatch escLeftBracket23Dispatch = { 2, "~;", escLeftBracket23Routines }; -static char32_t escLeftBracket23Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket23Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket23Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket23Dispatch); } // (S)-F12 @@ -595,11 +595,11 @@ static CharacterDispatchRoutine escLeftBracket24Semicolon2Routines[] = { static CharacterDispatch escLeftBracket24Semicolon2Dispatch = { 1, "~", escLeftBracket24Semicolon2Routines }; -static char32_t escLeftBracket24Semicolon2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket24Semicolon2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_SHIFT; - return doDispatch(c, escLeftBracket24Semicolon2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket24Semicolon2Dispatch); } // (C)-F12 @@ -609,11 +609,11 @@ static CharacterDispatchRoutine escLeftBracket24Semicolon5Routines[] = { static CharacterDispatch escLeftBracket24Semicolon5Dispatch = { 1, "~", escLeftBracket24Semicolon5Routines }; -static char32_t escLeftBracket24Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket24Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket24Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket24Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket24SemicolonRoutines[] = { @@ -622,10 +622,10 @@ static CharacterDispatchRoutine escLeftBracket24SemicolonRoutines[] = { static CharacterDispatch escLeftBracket24SemicolonDispatch = { 2, "25", escLeftBracket24SemicolonRoutines }; -static char32_t escLeftBracket24SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket24SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket24SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket24SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket24Routines[] = { @@ -634,10 +634,10 @@ static CharacterDispatchRoutine escLeftBracket24Routines[] = { static CharacterDispatch escLeftBracket24Dispatch = { 2, "~;", escLeftBracket24Routines }; -static char32_t escLeftBracket24Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket24Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket24Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket24Dispatch); } // Handle ESC [ 2 escape sequences @@ -681,11 +681,11 @@ static CharacterDispatchRoutine escLeftBracket5Semicolon5Routines[] = { static CharacterDispatch escLeftBracket5Semicolon5Dispatch = { 1, "~", escLeftBracket5Semicolon5Routines }; -static char32_t escLeftBracket5Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket5Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket5Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket5Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket5SemicolonRoutines[] = { escLeftBracket5Semicolon5Routine, @@ -694,10 +694,10 @@ static CharacterDispatchRoutine escLeftBracket5SemicolonRoutines[] = { static CharacterDispatch escLeftBracket5SemicolonDispatch = { 1, "5", escLeftBracket5SemicolonRoutines }; -static char32_t escLeftBracket5SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket5SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket5SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket5SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket5Routines[] = { @@ -715,11 +715,11 @@ static CharacterDispatchRoutine escLeftBracket6Semicolon5Routines[] = { static CharacterDispatch escLeftBracket6Semicolon5Dispatch = { 1, "~", escLeftBracket6Semicolon5Routines }; -static char32_t escLeftBracket6Semicolon5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket6Semicolon5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; thisKeyMetaCtrl |= Replxx::KEY::BASE_CONTROL; - return doDispatch(c, escLeftBracket6Semicolon5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket6Semicolon5Dispatch); } static CharacterDispatchRoutine escLeftBracket6SemicolonRoutines[] = { escLeftBracket6Semicolon5Routine, @@ -728,10 +728,10 @@ static CharacterDispatchRoutine escLeftBracket6SemicolonRoutines[] = { static CharacterDispatch escLeftBracket6SemicolonDispatch = { 1, "5", escLeftBracket6SemicolonRoutines }; -static char32_t escLeftBracket6SemicolonRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket6SemicolonRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket6SemicolonDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket6SemicolonDispatch); } static CharacterDispatchRoutine escLeftBracket6Routines[] = { @@ -761,51 +761,51 @@ static CharacterDispatch escLeftBracket8Dispatch = { // Handle ESC [ escape sequences // -static char32_t escLeftBracket0Routine(char32_t c) { - return escFailureRoutine(c); +static char32_t escLeftBracket0Routine(int in_fd_, int err_fd_, char32_t c) { + return escFailureRoutine(in_fd_, err_fd_, c); } -static char32_t escLeftBracket1Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket1Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket1Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket1Dispatch); } -static char32_t escLeftBracket2Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket2Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket2Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket2Dispatch); } -static char32_t escLeftBracket3Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket3Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket3Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket3Dispatch); } -static char32_t escLeftBracket4Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket4Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket4Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket4Dispatch); } -static char32_t escLeftBracket5Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket5Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket5Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket5Dispatch); } -static char32_t escLeftBracket6Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket6Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket6Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket6Dispatch); } -static char32_t escLeftBracket7Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket7Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket7Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket7Dispatch); } -static char32_t escLeftBracket8Routine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracket8Routine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracket8Dispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracket8Dispatch); } -static char32_t escLeftBracket9Routine(char32_t c) { - return escFailureRoutine(c); +static char32_t escLeftBracket9Routine(int in_fd_, int err_fd_, char32_t c) { + return escFailureRoutine(in_fd_, err_fd_, c); } // Handle ESC [ escape sequences @@ -837,17 +837,17 @@ static CharacterDispatch escODispatch = {14, "ABCDHFPQRSabcd", escORoutines}; // Initial ESC dispatch -- could be a Meta prefix or the start of an escape // sequence // -static char32_t escLeftBracketRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escLeftBracketRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escLeftBracketDispatch); + return doDispatch(in_fd_, err_fd_, c, escLeftBracketDispatch); } -static char32_t escORoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escORoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escODispatch); + return doDispatch(in_fd_, err_fd_, c, escODispatch); } -static char32_t setMetaRoutine(char32_t c); // need forward reference +static char32_t setMetaRoutine(int in_fd_, int err_fd_, char32_t c); // need forward reference static CharacterDispatchRoutine escRoutines[] = { escLeftBracketRoutine, escORoutine, setMetaRoutine }; @@ -855,10 +855,10 @@ static CharacterDispatch escDispatch = {2, "[O", escRoutines}; // Initial dispatch -- we are not in the middle of anything yet // -static char32_t escRoutine(char32_t c) { - c = read_unicode_character(); +static char32_t escRoutine(int in_fd_, int err_fd_, char32_t c) { + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escDispatch); + return doDispatch(in_fd_, err_fd_, c, escDispatch); } static CharacterDispatchRoutine initialRoutines[] = { escRoutine, deleteCharRoutine, normalKeyRoutine @@ -867,19 +867,19 @@ static CharacterDispatch initialDispatch = {2, "\x1B\x7F", initialRoutines}; // Special handling for the ESC key because it does double duty // -static char32_t setMetaRoutine(char32_t c) { +static char32_t setMetaRoutine(int in_fd_, int err_fd_, char32_t c) { thisKeyMetaCtrl = Replxx::KEY::BASE_META; if (c == 0x1B) { // another ESC, stay in ESC processing mode - c = read_unicode_character(); + c = read_unicode_character(in_fd_); if (c == 0) return 0; - return doDispatch(c, escDispatch); + return doDispatch(in_fd_, err_fd_, c, escDispatch); } - return doDispatch(c, initialDispatch); + return doDispatch(in_fd_, err_fd_, c, initialDispatch); } -char32_t doDispatch(char32_t c) { +char32_t doDispatch(int in_fd_, int err_fd_, char32_t c) { EscapeSequenceProcessing::thisKeyMetaCtrl = 0; // no modifiers yet at initialDispatch - return doDispatch(c, initialDispatch); + return doDispatch(in_fd_, err_fd_, c, initialDispatch); } } // namespace EscapeSequenceProcessing // move these out of global namespace diff --git a/src/escape.hxx b/src/escape.hxx index 6597395..ac41691 100644 --- a/src/escape.hxx +++ b/src/escape.hxx @@ -12,7 +12,7 @@ namespace EscapeSequenceProcessing { // dispatch routines, then eventually returns the final (possibly extended or // special) character. // -typedef char32_t (*CharacterDispatchRoutine)(char32_t); +typedef char32_t (*CharacterDispatchRoutine)(int, int, char32_t); // This structure is used by doDispatch() to hold a list of characters to test // for and @@ -27,7 +27,7 @@ struct CharacterDispatch { CharacterDispatchRoutine* dispatch; // array of routines to call }; -char32_t doDispatch(char32_t c); +char32_t doDispatch(int in_fd_, int err_fd, char32_t c); } diff --git a/src/replxx.cxx b/src/replxx.cxx index 972bebe..c800ad2 100644 --- a/src/replxx.cxx +++ b/src/replxx.cxx @@ -126,8 +126,8 @@ void delete_ReplxxImpl( Replxx::ReplxxImpl* impl_ ) { } } -Replxx::Replxx( void ) - : _impl( new Replxx::ReplxxImpl( nullptr, nullptr, nullptr ), delete_ReplxxImpl ) { +Replxx::Replxx( std::istream & input_stream_, std::ostream & output_stream_, int in_fd_, int out_fd_, int err_fd_ ) + : _impl( new Replxx::ReplxxImpl( input_stream_, output_stream_, in_fd_, out_fd_, err_fd_ ), delete_ReplxxImpl ) { } void Replxx::set_completion_callback( completion_callback_t const& fn ) { @@ -339,10 +339,10 @@ Replxx::Color rgb666( int red_, int green_, int blue_ ) { } -::Replxx* replxx_init() { - typedef ::Replxx* replxx_data_t; - return ( reinterpret_cast( new replxx::Replxx::ReplxxImpl( nullptr, nullptr, nullptr ) ) ); -} +// ::Replxx* replxx_init() { +// typedef ::Replxx* replxx_data_t; +// return ( reinterpret_cast( new replxx::Replxx::ReplxxImpl( nullptr, nullptr, nullptr ) ) ); +// } void replxx_end( ::Replxx* replxx_ ) { delete reinterpret_cast( replxx_ ); @@ -683,7 +683,7 @@ int replxx_history_size( ::Replxx* replxx_ ) { void replxx_debug_dump_print_codes(void) { char quit[4]; - printf( + dprintf(_out_fd, "replxx key codes debugging mode.\n" "Press keys to see scan codes. Type 'quit' at any time to exit.\n"); if (enableRawMode() == -1) return; @@ -702,9 +702,9 @@ void replxx_debug_dump_print_codes(void) { quit[sizeof(quit) - 1] = c; /* Insert current char on the right. */ if (memcmp(quit, "quit", sizeof(quit)) == 0) break; - printf("'%c' %02x (%d) (type quit to exit)\n", isprint(c) ? c : '?', (int)c, + dprintf(_out_fd,"'%c' %02x (%d) (type quit to exit)\n", isprint(c) ? c : '?', (int)c, (int)c); - printf("\r"); /* Go left edge manually, we are in raw mode. */ + dprintf(_out_fd,"\r"); /* Go left edge manually, we are in raw mode. */ fflush(stdout); } disableRawMode(); diff --git a/src/replxx_impl.cxx b/src/replxx_impl.cxx index 318bfeb..b08a133 100644 --- a/src/replxx_impl.cxx +++ b/src/replxx_impl.cxx @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -146,7 +147,7 @@ class IOModeGuard { } -Replxx::ReplxxImpl::ReplxxImpl( FILE*, FILE*, FILE* ) +Replxx::ReplxxImpl::ReplxxImpl( std::istream & in_, std::ostream & out_, int in_fd_, int out_fd_, int err_fd_ ) : _utf8Buffer() , _data() , _pos( 0 ) @@ -175,7 +176,7 @@ Replxx::ReplxxImpl::ReplxxImpl( FILE*, FILE*, FILE* ) , _indentMultiline( true ) , _namedActions() , _keyPressHandlers() - , _terminal() + , _terminal(in_fd_, out_fd_) , _currentThread() , _prompt( _terminal ) , _completionCallback( nullptr ) @@ -200,7 +201,12 @@ Replxx::ReplxxImpl::ReplxxImpl( FILE*, FILE*, FILE* ) , _oldPos( 0 ) , _moveCursor( false ) , _ignoreCase( false ) - , _mutex() { + , _mutex() + , _in(in_) + , _out(out_) + , _in_fd(in_fd_) + , _out_fd(out_fd_) + , _err_fd(err_fd_) { using namespace std::placeholders; _namedActions[action_names::INSERT_CHARACTER] = std::bind( &ReplxxImpl::invoke, this, Replxx::ACTION::INSERT_CHARACTER, _1 ); _namedActions[action_names::NEW_LINE] = std::bind( &ReplxxImpl::invoke, this, Replxx::ACTION::NEW_LINE, _1 ); @@ -608,8 +614,8 @@ void Replxx::ReplxxImpl::set_preload_buffer( std::string const& preloadText ) { char const* Replxx::ReplxxImpl::read_from_stdin( void ) { if ( _preloadedBuffer.empty() ) { - getline( cin, _preloadedBuffer ); - if ( ! cin.good() ) { + getline( _in, _preloadedBuffer ); + if ( ! _in.good() ) { return nullptr; } } @@ -632,17 +638,17 @@ void Replxx::ReplxxImpl::emulate_key_press( char32_t keyCode_ ) { char const* Replxx::ReplxxImpl::input( std::string const& prompt ) { try { errno = 0; - if ( ! tty::in ) { // input not from a terminal, we should work with piped input, i.e. redirected stdin + if ( ! tty::is_a_tty(_in_fd) ) { // input not from a terminal, we should work with piped input, i.e. redirected stdin return ( read_from_stdin() ); } if ( ! _errorMessage.empty() ) { - printf( "%s", _errorMessage.c_str() ); - fflush( stdout ); + dprintf( _out_fd, "%s", _errorMessage.c_str() ); + fdatasync( _out_fd ); _errorMessage.clear(); } if ( isUnsupportedTerm() ) { - fprintf( stdout, "%s", prompt.c_str() ); - fflush( stdout ); + dprintf( _out_fd, "%s", prompt.c_str() ); + fdatasync( _out_fd ); return ( read_from_stdin() ); } std::unique_lock l( _mutex ); @@ -978,7 +984,7 @@ Replxx::ReplxxImpl::paren_info_t Replxx::ReplxxImpl::matching_paren( void ) { int Replxx::ReplxxImpl::virtual_render( char32_t const* buffer_, int len_, int& xPos_, int& yPos_, Prompt const* prompt_ ) { Prompt const& prompt( prompt_ ? *prompt_ : _prompt ); - return ( replxx::virtual_render( buffer_, len_, xPos_, yPos_, prompt.screen_columns(), _indentMultiline ? prompt.indentation() : 0 ) ); + return ( replxx::virtual_render( buffer_, len_, xPos_, yPos_, prompt.screen_columns(), _indentMultiline ? prompt.indentation() : 0 ), _out_fd); } /** @@ -1146,7 +1152,7 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { // if no completions, we are done if ( _completions.empty() ) { - beep(); + beep(_err_fd); return 0; } @@ -1165,7 +1171,7 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { longestCommonPrefix = longest_common_prefix( _completions, ignoreCase ); } if ( _beepOnAmbiguousCompletion && ( completionsCount != 1 ) ) { // beep if ambiguous - beep(); + beep(_err_fd); } // if we can extend the item, extend it and return to main loop @@ -1229,8 +1235,8 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { _pos = _data.length(); refresh_line(); _pos = savePos; - printf( "\nDisplay all %u possibilities? (y or n)", static_cast( _completions.size() ) ); - fflush(stdout); + dprintf(_out_fd, "\nDisplay all %u possibilities? (y or n)", static_cast( _completions.size() ) ); + fdatasync(_out_fd); onNewLine = true; while (c != 'y' && c != 'Y' && c != 'n' && c != 'N' && c != Replxx::KEY::control('C')) { do { @@ -1278,15 +1284,15 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { size_t rowCount = (_completions.size() + columnCount - 1) / columnCount; for (size_t row = 0; row < rowCount; ++row) { if (row == pauseRow) { - printf("\n--More--"); - fflush(stdout); + dprintf(_out_fd, "\n--More--"); + fdatasync(_out_fd); c = 0; bool doBeep = false; while (c != ' ' && c != Replxx::KEY::ENTER && c != 'y' && c != 'Y' && c != 'n' && c != 'N' && c != 'q' && c != 'Q' && c != Replxx::KEY::control('C')) { if (doBeep) { - beep(); + beep(_err_fd); } doBeep = true; do { @@ -1297,18 +1303,18 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { case ' ': case 'y': case 'Y': - printf("\r \r"); + dprintf(_out_fd, "\r \r"); pauseRow += _terminal.get_screen_rows() - 1; break; case Replxx::KEY::ENTER: - printf("\r \r"); + dprintf(_out_fd, "\r \r"); ++pauseRow; break; case 'n': case 'N': case 'q': case 'Q': - printf("\r \r"); + dprintf(_out_fd, "\r \r"); stopList = true; break; case Replxx::KEY::control('C'): @@ -1329,7 +1335,7 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { if ( index < _completions.size() ) { Completion const& c( _completions[index] ); int itemLength = static_cast(c.text().length()); - fflush(stdout); + fdatasync(_out_fd); if ( longestCommonPrefix > 0 ) { static UnicodeString const col( ansi_color( Replxx::Color::BRIGHTMAGENTA ) ); @@ -1353,13 +1359,13 @@ char32_t Replxx::ReplxxImpl::do_complete_line( bool showCompletions_ ) { if ( ((column + 1) * rowCount) + row < _completions.size() ) { for ( int k( itemLength ); k < longestCompletion; ++k ) { - printf( " " ); + dprintf(_out_fd, " " ); } } } } } - fflush(stdout); + fdatasync(_out_fd); } // display the prompt on a new line, then redisplay the input buffer @@ -1474,7 +1480,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::insert_character( char32_t c ) { * don't insert control characters */ if ( ( c >= static_cast( Replxx::KEY::BASE ) ) || ( is_control_code( c ) && ( c != '\n' ) ) ) { - beep(); + beep(_err_fd); return ( Replxx::ACTION_RESULT::CONTINUE ); } if ( ! _overwrite || ( _pos >= _data.length() ) ) { @@ -1684,7 +1690,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::yank( char32_t ) { _killRing.lastAction = KillRing::actionYank; _lastYankSize = restoredText->length(); } else { - beep(); + beep(_err_fd); } return ( Replxx::ACTION_RESULT::CONTINUE ); } @@ -1692,12 +1698,12 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::yank( char32_t ) { // meta-Y, "yank-pop", rotate popped text Replxx::ACTION_RESULT Replxx::ReplxxImpl::yank_cycle( char32_t ) { if ( _killRing.lastAction != KillRing::actionYank ) { - beep(); + beep(_err_fd); return ( Replxx::ACTION_RESULT::CONTINUE ); } UnicodeString* restoredText = _killRing.yankPop(); if ( !restoredText ) { - beep(); + beep(_err_fd); return ( Replxx::ACTION_RESULT::CONTINUE ); } _pos -= _lastYankSize; @@ -2314,7 +2320,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::incremental_history_search( char32_t s _history.restore_pos(); historyLinePosition = _pos; } else { - beep(); + beep(_err_fd); } } break; @@ -2326,7 +2332,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::incremental_history_search( char32_t s dp._searchText.insert( dp._searchText.length(), c ); dp.updateSearchPrompt(); } else { - beep(); + beep(_err_fd); } } } // switch @@ -2375,7 +2381,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::incremental_history_search( char32_t s lineSearchPos = ( dp._direction > 0 ) ? 0 : ( activeHistoryLine.length() - dp._searchText.length() ); } else { historyLinePosition = _pos; - beep(); + beep(_err_fd); break; } } // while @@ -2426,7 +2432,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::bracketed_paste( char32_t ) { static const UnicodeString BRACK_PASTE_SUFF( "\033[201~" ); static const int BRACK_PASTE_SLEN( BRACK_PASTE_SUFF.length() ); UnicodeString buf; - while ( char32_t c = read_unicode_character() ) { + while ( char32_t c = read_unicode_character(_in_fd) ) { if ( ( c == '\r' ) || ( c == KEY::control( 'M' ) ) ) { c = '\n'; } diff --git a/src/replxx_impl.hxx b/src/replxx_impl.hxx index aa7cfae..80f4502 100644 --- a/src/replxx_impl.hxx +++ b/src/replxx_impl.hxx @@ -158,8 +158,14 @@ private: bool _moveCursor; bool _ignoreCase; mutable std::mutex _mutex; + + std::istream & _in; + [[ maybe_unused ]] std::ostream & _out; + int _in_fd = 0; + int _out_fd = 1; + int _err_fd = 2; public: - ReplxxImpl( FILE*, FILE*, FILE* ); + ReplxxImpl( std::istream & in_, std::ostream & out_, int in_fd_, int out_fd_, int err_fd_ ); virtual ~ReplxxImpl( void ); void set_modify_callback( Replxx::modify_callback_t const& fn ); void set_completion_callback( Replxx::completion_callback_t const& fn ); diff --git a/src/terminal.cxx b/src/terminal.cxx index d737edf..d211875 100644 --- a/src/terminal.cxx +++ b/src/terminal.cxx @@ -65,8 +65,11 @@ bool is_a_tty( int fd_ ) { return ( aTTY ); } +/** +The patch to support arbitrary file descriptors made these functions unusable. bool in( is_a_tty( 0 ) ); bool out( is_a_tty( 1 ) ); +*/ } @@ -81,7 +84,7 @@ static void WindowSizeChanged( int ) { #endif -Terminal::Terminal( void ) +Terminal::Terminal(int in_fd_, int out_fd_) #ifdef _WIN32 : _consoleOut( INVALID_HANDLE_VALUE ) , _consoleIn( INVALID_HANDLE_VALUE ) @@ -99,7 +102,9 @@ Terminal::Terminal( void ) , _interrupt() #endif , _rawMode( false ) - , _utf8() { + , _utf8() + , _in_fd(in_fd_) + , _out_fd(out_fd_) { #ifdef _WIN32 _interrupt = CreateEvent( nullptr, true, false, TEXT( "replxx_interrupt_event" ) ); #else @@ -137,7 +142,7 @@ void Terminal::write8( char const* data_, int size_ ) { disable_out(); } #else - int nWritten( write( 1, data_, size_ ) ); + int nWritten( write( _out_fd, data_, size_ ) ); #endif if ( nWritten != size_ ) { throw std::runtime_error( "write failed" ); @@ -153,7 +158,7 @@ int Terminal::get_screen_columns( void ) { cols = inf.dwSize.X; #else struct winsize ws; - cols = ( ioctl( 1, TIOCGWINSZ, &ws ) == -1 ) ? 80 : ws.ws_col; + cols = ( ioctl( _out_fd, TIOCGWINSZ, &ws ) == -1 ) ? 80 : ws.ws_col; #endif // cols is 0 in certain circumstances like inside debugger, which creates // further issues @@ -168,7 +173,7 @@ int Terminal::get_screen_rows( void ) { rows = 1 + inf.srWindow.Bottom - inf.srWindow.Top; #else struct winsize ws; - rows = (ioctl(1, TIOCGWINSZ, &ws) == -1) ? 24 : ws.ws_row; + rows = (ioctl(_out_fd, TIOCGWINSZ, &ws) == -1) ? 24 : ws.ws_row; #endif return (rows > 0) ? rows : 24; } @@ -217,10 +222,10 @@ int Terminal::enable_raw_mode( void ) { GetConsoleMode( _consoleIn, &_origInMode ); #else - if ( ! tty::in ) { + if ( ! tty::is_a_tty(_in_fd) ) { return ( notty() ); } - if ( tcgetattr( 0, &_origTermios ) == -1 ) { + if ( tcgetattr( _in_fd, &_origTermios ) == -1 ) { return ( notty() ); } @@ -263,14 +268,14 @@ int Terminal::reset_raw_mode( void ) { #ifdef _WIN32 SetConsoleMode( _consoleIn, - ( _origInMode & ~( ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT ) ) | ENABLE_QUICK_EDIT_MODE + ( _origInMode & ~( ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT ) ) | ENABLE_QUICK_EDIT_MODE ); SetConsoleCP( 65001 ); enable_out(); return ( 0 ); #else /* put terminal in raw mode after flushing */ - return ( tcsetattr( 0, TCSADRAIN, &_rawModeTermios ) ); + return ( tcsetattr( _in_fd, TCSADRAIN, &_rawModeTermios ) ); #endif } @@ -285,7 +290,7 @@ void Terminal::disable_raw_mode(void) { _consoleIn = INVALID_HANDLE_VALUE; #else _terminal_ = nullptr; - if ( tcsetattr( 0, TCSADRAIN, &_origTermios ) == -1 ) { + if ( tcsetattr( _in_fd, TCSADRAIN, &_origTermios ) == -1 ) { return; } #endif @@ -301,7 +306,7 @@ void Terminal::disable_raw_mode(void) { * * @return char32_t Unicode character */ -char32_t read_unicode_character(void) { +char32_t read_unicode_character(int in_fd_) { static char8_t utf8String[5]; static size_t utf8Count = 0; while (true) { @@ -310,7 +315,7 @@ char32_t read_unicode_character(void) { /* Continue reading if interrupted by signal. */ ssize_t nread; do { - nread = read( STDIN_FILENO, &c, 1 ); + nread = read( in_fd_, &c, 1 ); } while ((nread == -1) && (errno == EINTR)); if (nread <= 0) return 0; @@ -335,9 +340,9 @@ char32_t read_unicode_character(void) { #endif // #ifndef _WIN32 -void beep() { - fprintf(stderr, "\x7"); // ctrl-G == bell/beep - fflush(stderr); +void beep(int fd_) { + dprintf(fd_, "\x7"); // ctrl-G == bell/beep + fdatasync(fd_); } // replxx_read_char -- read a keystroke or keychord from the keyboard, and translate it @@ -488,7 +493,7 @@ char32_t Terminal::read_char( void ) { } #else - c = read_unicode_character(); + c = read_unicode_character(_in_fd); if (c == 0) { return 0; } @@ -502,7 +507,7 @@ char32_t Terminal::read_char( void ) { #ifdef __REPLXX_DEBUG__ if (c == ctrlChar('^')) { // ctrl-^, special debug mode, prints all keys hit, // ctrl-C to get out - printf( + dprintf(_out_fd, "\nEntering keyboard debugging mode (on ctrl-^), press ctrl-C to exit " "this mode\n"); while (true) { @@ -510,7 +515,7 @@ char32_t Terminal::read_char( void ) { int ret = read(0, keys, 10); if (ret <= 0) { - printf("\nret: %d\n", ret); + dprintf(_out_fd,"\nret: %d\n", ret); } for (int i = 0; i < ret; ++i) { char32_t key = static_cast(keys[i]); @@ -538,13 +543,13 @@ char32_t Terminal::read_char( void ) { friendlyTextBuf[2] = 0; friendlyTextPtr = friendlyTextBuf; } - printf("%d x%02X (%s%s) ", key, key, prefixText, friendlyTextPtr); + dprintf(_out_fd,"%d x%02X (%s%s) ", key, key, prefixText, friendlyTextPtr); } - printf("\x1b[1G\n"); // go to first column of new line + dprintf(_out_fd,"\x1b[1G\n"); // go to first column of new line // drop out of this loop on ctrl-C if (keys[0] == ctrlChar('C')) { - printf("Leaving keyboard debugging mode (on ctrl-C)\n"); + dprintf(_out_fd,"Leaving keyboard debugging mode (on ctrl-C)\n"); fflush(stdout); return -2; } @@ -552,7 +557,7 @@ char32_t Terminal::read_char( void ) { } #endif // __REPLXX_DEBUG__ - c = EscapeSequenceProcessing::doDispatch(c); + c = EscapeSequenceProcessing::doDispatch(_in_fd, _err_fd, c); if ( is_control_code( c ) ) { c = Replxx::KEY::control( control_to_human( c ) ); } @@ -633,7 +638,7 @@ Terminal::EVENT_TYPE Terminal::wait_for_input( int long timeout_ ) { int nfds( max( _interrupt[0], _interrupt[1] ) + 1 ); while ( true ) { FD_ZERO( &fdSet ); - FD_SET( 0, &fdSet ); + FD_SET( _in_fd, &fdSet ); FD_SET( _interrupt[0], &fdSet ); timeval tv{ timeout_ / 1000, static_cast( ( timeout_ % 1000 ) * 1000 ) }; int err( select( nfds, &fdSet, nullptr, nullptr, timeout_ > 0 ? &tv : nullptr ) ); @@ -656,7 +661,7 @@ Terminal::EVENT_TYPE Terminal::wait_for_input( int long timeout_ ) { return ( EVENT_TYPE::RESIZE ); } } - if ( FD_ISSET( 0, &fdSet ) ) { + if ( FD_ISSET( _in_fd, &fdSet ) ) { return ( EVENT_TYPE::KEY_PRESS ); } } @@ -682,10 +687,10 @@ void Terminal::clear_screen( CLEAR_SCREEN clearScreen_ ) { #endif if ( clearScreen_ == CLEAR_SCREEN::WHOLE ) { char const clearCode[] = "\033c\033[H\033[2J\033[0m"; - static_cast( write(1, clearCode, sizeof ( clearCode ) - 1) >= 0 ); + static_cast( write(_out_fd, clearCode, sizeof ( clearCode ) - 1) >= 0 ); } else { char const clearCode[] = "\033[J"; - static_cast( write(1, clearCode, sizeof ( clearCode ) - 1) >= 0 ); + static_cast( write(_out_fd, clearCode, sizeof ( clearCode ) - 1) >= 0 ); } return; #ifdef _WIN32 @@ -750,17 +755,17 @@ void Terminal::set_cursor_visible( bool ) {} #ifndef _WIN32 int Terminal::read_verbatim( char32_t* buffer_, int size_ ) { int len( 0 ); - buffer_[len ++] = read_unicode_character(); - int statusFlags( ::fcntl( STDIN_FILENO, F_GETFL, 0 ) ); - ::fcntl( STDIN_FILENO, F_SETFL, statusFlags | O_NONBLOCK ); + buffer_[len ++] = read_unicode_character(_in_fd); + int statusFlags( ::fcntl( _in_fd, F_GETFL, 0 ) ); + ::fcntl( _in_fd, F_SETFL, statusFlags | O_NONBLOCK ); while ( len < size_ ) { - char32_t c( read_unicode_character() ); + char32_t c( read_unicode_character(_in_fd) ); if ( c == 0 ) { break; } buffer_[len ++] = c; } - ::fcntl( STDIN_FILENO, F_SETFL, statusFlags ); + ::fcntl( _in_fd, F_SETFL, statusFlags ); return ( len ); } @@ -778,4 +783,3 @@ int Terminal::install_window_change_handler( void ) { #endif } - diff --git a/src/terminal.hxx b/src/terminal.hxx index 90c3640..2e6ad3d 100644 --- a/src/terminal.hxx +++ b/src/terminal.hxx @@ -43,13 +43,17 @@ private: #endif bool _rawMode; /* for destructor to check if restore is needed */ Utf8String _utf8; + + int _in_fd = 0; + int _out_fd = 1; + int _err_fd = 2; public: enum class CLEAR_SCREEN { WHOLE, TO_END }; public: - Terminal( void ); + explicit Terminal(int in_fd_= 0, int out_fd_ = 1); ~Terminal( void ); void write32( char32_t const*, int ); void write8( char const*, int ); @@ -80,13 +84,17 @@ private: Terminal& operator = ( Terminal&& ) = delete; }; -void beep(); -char32_t read_unicode_character(void); +void beep(int fd_); +char32_t read_unicode_character(int in_fd_); namespace tty { +extern bool is_a_tty( int fd_ ); + +/** extern bool in; extern bool out; +*/ } diff --git a/src/util.cxx b/src/util.cxx index 730a753..c14df2f 100644 --- a/src/util.cxx +++ b/src/util.cxx @@ -13,7 +13,7 @@ namespace replxx { int mk_wcwidth( char32_t ); -int virtual_render( char32_t const* display_, int size_, int& x_, int& y_, int screenColumns_, int promptLen_, char32_t* rendered_, int* renderedSize_ ) { +int virtual_render( char32_t const* display_, int size_, int& x_, int& y_, int screenColumns_, int promptLen_, char32_t* rendered_, int* renderedSize_, int out_fd_) { char32_t* out( rendered_ ); int visibleCount( 0 ); auto render = [&rendered_, &renderedSize_, &out, &visibleCount]( char32_t c_, bool visible_, bool renderAttributes_ = true ) { @@ -35,7 +35,7 @@ int virtual_render( char32_t const* display_, int size_, int& x_, int& y_, int s wrapped = true; } }; - bool const renderAttributes( !!tty::out ); + bool const renderAttributes( !!tty::is_a_tty(out_fd_) ); int pos( 0 ); while ( pos < size_ ) { char32_t c( display_[pos] ); diff --git a/src/util.hxx b/src/util.hxx index e77c641..c58a01d 100644 --- a/src/util.hxx +++ b/src/util.hxx @@ -22,7 +22,7 @@ inline char32_t control_to_human( char32_t key ) { return ( key < 27 ? ( key + 0x40 ) : ( key + 0x18 ) ); } -int virtual_render( char32_t const*, int, int&, int&, int, int, char32_t* = nullptr, int* = nullptr ); +int virtual_render( char32_t const*, int, int&, int&, int, int, char32_t* = nullptr, int* = nullptr, int out_fd = 1); char const* ansi_color( Replxx::Color ); std::string now_ms_str( void ); diff --git a/src/windows.cxx b/src/windows.cxx index 6a0e425..05b9f01 100644 --- a/src/windows.cxx +++ b/src/windows.cxx @@ -99,6 +99,7 @@ T* HandleEsc(HANDLE out_, T* p, T* end) { int win_write( HANDLE out_, bool autoEscape_, char const* str_, int size_ ) { int count( 0 ); + /// FIXME: Replace this variable with function call passing an output descriptor as a parameter. if ( tty::out ) { DWORD nWritten( 0 ); if ( autoEscape_ ) {