From 4517038521487417969d3e2c644f38eb955934c6 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 3 Dec 2020 10:43:20 +0100 Subject: [PATCH] Using smart pointers for global objects --- examples/calculator.cpp | 2 +- examples/event-log.cpp | 10 +- examples/listbox.cpp | 2 +- examples/opti-move.cpp | 11 +- examples/termcap.cpp | 14 +- examples/treeview.cpp | 24 +- src/fapplication.cpp | 132 +++--- src/fbusyindicator.cpp | 3 +- src/fbuttongroup.cpp | 4 +- src/fcallback.cpp | 10 - src/fcolorpalette.cpp | 15 +- src/fdata.cpp | 7 +- src/fdialog.cpp | 4 +- src/ffiledialog.cpp | 21 +- src/fkeyboard.cpp | 32 +- src/flog.cpp | 4 - src/flogger.cpp | 7 +- src/fmenu.cpp | 12 +- src/fmenubar.cpp | 4 +- src/fmouse.cpp | 16 +- src/fobject.cpp | 7 +- src/fstring.cpp | 11 +- src/fstringstream.cpp | 4 +- src/fterm.cpp | 655 +++++++++++------------------ src/ftermbuffer.cpp | 9 +- src/ftermcap.cpp | 19 +- src/ftermcapquirks.cpp | 24 +- src/ftermdebugdata.cpp | 18 +- src/ftermdetection.cpp | 17 +- src/ftermfreebsd.cpp | 50 +-- src/ftermlinux.cpp | 119 +++--- src/ftermopenbsd.cpp | 53 +-- src/ftermxterminal.cpp | 75 +--- src/ftogglebutton.cpp | 4 +- src/fvterm.cpp | 53 +-- src/fwidget.cpp | 6 +- src/fwidgetcolors.cpp | 23 +- src/include/final/emptyfstring.h | 66 +-- src/include/final/fapplication.h | 11 +- src/include/final/fbusyindicator.h | 2 +- src/include/final/fbuttongroup.h | 2 +- src/include/final/fcallback.h | 4 +- src/include/final/fcolorpalette.h | 8 +- src/include/final/fdata.h | 7 +- src/include/final/fdialog.h | 2 +- src/include/final/ffiledialog.h | 4 - src/include/final/fkeyboard.h | 9 - src/include/final/flistview.h | 7 +- src/include/final/flog.h | 2 +- src/include/final/flogger.h | 4 +- src/include/final/fmenu.h | 6 +- src/include/final/fmenubar.h | 2 +- src/include/final/fmessagebox.h | 2 +- src/include/final/fmouse.h | 56 +-- src/include/final/fobject.h | 4 +- src/include/final/fpoint.h | 4 +- src/include/final/frect.h | 4 +- src/include/final/fsize.h | 4 +- src/include/final/fstringstream.h | 4 +- src/include/final/fterm.h | 105 ++--- src/include/final/ftermcap.h | 15 +- src/include/final/ftermcapquirks.h | 8 - src/include/final/ftermdebugdata.h | 10 - src/include/final/ftermdetection.h | 3 - src/include/final/ftermfreebsd.h | 7 - src/include/final/ftermlinux.h | 10 +- src/include/final/ftermopenbsd.h | 8 - src/include/final/ftermxterminal.h | 14 +- src/include/final/ftogglebutton.h | 2 +- src/include/final/fvterm.h | 24 +- src/include/final/fwidgetcolors.h | 12 +- test/conemu.h | 2 +- test/ftermfreebsd-test.cpp | 19 +- test/ftermlinux-test.cpp | 152 ++++--- test/ftermopenbsd-test.cpp | 29 +- 75 files changed, 800 insertions(+), 1315 deletions(-) diff --git a/examples/calculator.cpp b/examples/calculator.cpp index c8912c33..7058f5de 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -122,7 +122,7 @@ class Calc final : public finalcut::FDialog private: // Typedef and Enumeration - typedef std::function keyFunction; // Member function + using keyFunction = std::function; // Member function enum button { diff --git a/examples/event-log.cpp b/examples/event-log.cpp index 2c2aa840..900b3941 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -51,7 +51,7 @@ class EventDialog final : public finalcut::FDialog EventDialog (const EventDialog&) = delete; // Destructor - ~EventDialog() override; + ~EventDialog() noexcept override; // Disable copy assignment operator (=) EventDialog& operator = (const EventDialog&) = delete; @@ -99,8 +99,7 @@ EventDialog::EventDialog (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -EventDialog::~EventDialog() // destructor -{ } +EventDialog::~EventDialog() noexcept = default; // destructor //---------------------------------------------------------------------- finalcut::FString EventDialog::getMouseButtonName (int btn_state) const @@ -245,7 +244,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream EventLog (const EventLog&) = delete; // Destructor - ~EventLog() override; + ~EventLog() noexcept override; // Disable copy assignment operator (=) EventLog& operator = (const EventLog&) = delete; @@ -282,8 +281,7 @@ EventLog::EventLog (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -EventLog::~EventLog() // destructor -{ } +EventLog::~EventLog() noexcept = default; // destructor //---------------------------------------------------------------------- void EventLog::onTimer (finalcut::FTimerEvent*) diff --git a/examples/listbox.cpp b/examples/listbox.cpp index f47a937b..1cfbaf7a 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -50,7 +50,7 @@ void doubleToItem ( FListBoxItem& item , FDataAccess* container , std::size_t index ) { - typedef std::list DblList; + using DblList = std::list; DblList& dbl_list = flistboxhelper::getContainer(container); std::list::iterator iter = dbl_list.begin(); std::advance (iter, index); diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index dfeb007c..8973e09a 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -136,10 +136,10 @@ class DirectLogger final : public finalcut::FLog { public: // Constructor - DirectLogger(); + DirectLogger() = default; // Destructor - ~DirectLogger() override; + ~DirectLogger() noexcept override; void info (const std::string& entry) override { @@ -194,12 +194,7 @@ class DirectLogger final : public finalcut::FLog }; //---------------------------------------------------------------------- -DirectLogger::DirectLogger() // constructor -{ } - -//---------------------------------------------------------------------- -DirectLogger::~DirectLogger() // destructor -{ } +DirectLogger::~DirectLogger() noexcept = default; // destructor //---------------------------------------------------------------------- diff --git a/examples/termcap.cpp b/examples/termcap.cpp index 16554f20..333467ce 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -212,22 +212,22 @@ void tcapString (const std::string& name, const char cap_str[]) void debug (const finalcut::FApplication& TermApp) { const auto& fterm = TermApp.getFTerm(); - auto& debug_data = fterm.getFTermDebugData(); - const finalcut::FString& ab_s = debug_data.getAnswerbackString(); - const finalcut::FString& sec_da = debug_data.getSecDAString(); + const auto& debug_data = fterm.getFTermDebugData(); + const finalcut::FString& ab_s = debug_data->getAnswerbackString(); + const finalcut::FString& sec_da = debug_data->getSecDAString(); std::cout << "\n.------------------- debug -------------------\r\n"; #if defined(__linux__) std::cout << "| Framebuffer bpp: " - << debug_data.getFramebufferBpp() << "\r\n"; + << debug_data->getFramebufferBpp() << "\r\n"; #endif std::cout << "| after init_256colorTerminal(): " - << debug_data.getTermType_256color() << "\r\n"; + << debug_data->getTermType_256color() << "\r\n"; std::cout << "| after parseAnswerbackMsg(): " - << debug_data.getTermType_Answerback() << "\r\n"; + << debug_data->getTermType_Answerback() << "\r\n"; std::cout << "| after parseSecDA(): " - << debug_data.getTermType_SecDA() << "\r\n"; + << debug_data->getTermType_SecDA() << "\r\n"; if ( ! ab_s.isEmpty() ) tcapString ("| The answerback String", ab_s.c_str()); diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 469f265e..340b242c 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -161,12 +161,12 @@ class Treeview final : public finalcut::FDialog struct TreeItem; // forward declaration // Methods - auto initAfrica() -> std::initializer_list; - auto initAsia() -> std::initializer_list; - auto initEurope() -> std::initializer_list; - auto initNorthAmerica() -> std::initializer_list; - auto initSouthAmerica() -> std::initializer_list; - auto initOceania() -> std::initializer_list; + auto initAfrica() -> std::initializer_list const; + auto initAsia() -> std::initializer_list const; + auto initEurope() -> std::initializer_list const; + auto initNorthAmerica() -> std::initializer_list const; + auto initSouthAmerica() -> std::initializer_list const; + auto initOceania() -> std::initializer_list const; void adjustSize() override; // Event handler @@ -275,7 +275,7 @@ Treeview::Treeview (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -auto Treeview::initAfrica() -> std::initializer_list +auto Treeview::initAfrica() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -306,7 +306,7 @@ auto Treeview::initAfrica() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initAsia() -> std::initializer_list +auto Treeview::initAsia() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -334,7 +334,7 @@ auto Treeview::initAsia() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initEurope() -> std::initializer_list +auto Treeview::initEurope() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -362,7 +362,7 @@ auto Treeview::initEurope() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initNorthAmerica() -> std::initializer_list +auto Treeview::initNorthAmerica() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -379,7 +379,7 @@ auto Treeview::initNorthAmerica() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initSouthAmerica() -> std::initializer_list +auto Treeview::initSouthAmerica() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -398,7 +398,7 @@ auto Treeview::initSouthAmerica() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initOceania() -> std::initializer_list +auto Treeview::initOceania() -> std::initializer_list const { static const auto list = std::initializer_list { diff --git a/src/fapplication.cpp b/src/fapplication.cpp index f2d93803..a1397e7a 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -68,8 +68,6 @@ FWidget* FWidget::clicked_widget {nullptr}; // is focused by click FWidget* FWidget::open_menu {nullptr}; // currently open menu FWidget* FWidget::move_size_widget {nullptr}; // move/size by keyboard FWidget* FApplication::keyboard_widget {nullptr}; // has the keyboard focus -FKeyboard* FApplication::keyboard {nullptr}; // keyboard access -FMouseControl* FApplication::mouse {nullptr}; // mouse control int FApplication::loop_level {0}; // event loop level int FApplication::quit_code {EXIT_SUCCESS}; bool FApplication::quit_now {false}; @@ -93,9 +91,9 @@ FApplication::FApplication (const int& _argc, char* _argv[]) if ( internal::var::app_object ) { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage("FApplication: There should be " - "only one application object"); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage("FApplication: There should be " + "only one application object"); FApplication::exit(EXIT_FAILURE); return; } @@ -105,7 +103,7 @@ FApplication::FApplication (const int& _argc, char* _argv[]) if ( ! (_argc && _argv) ) { - typedef char* CString; + using CString = char*; static std::array empty{{CString("")}}; app_argc = 0; app_argv = empty.data(); @@ -350,9 +348,9 @@ void FApplication::setLogFile (const FString& filename) } else { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage ( "Could not open log file \"" - + filename + "\"" ); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage ( "Could not open log file \"" + + filename + "\"" ); exit(EXIT_FAILURE); } } @@ -405,41 +403,32 @@ void FApplication::init() time_last_event.tv_usec = 0; // Initialize keyboard - keyboard = FTerm::getFKeyboard(); - - - if ( keyboard ) - { - auto cmd1 = std::bind(&FApplication::keyPressed, this); - auto cmd2 = std::bind(&FApplication::keyReleased, this); - auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this); - auto cmd4 = std::bind(&FApplication::mouseTracking, this); - FKeyboardCommand key_cmd1 (cmd1); - FKeyboardCommand key_cmd2 (cmd2); - FKeyboardCommand key_cmd3 (cmd3); - FKeyboardCommand key_cmd4 (cmd4); - keyboard->setPressCommand (key_cmd1); - keyboard->setReleaseCommand (key_cmd2); - keyboard->setEscPressedCommand (key_cmd3); - keyboard->setMouseTrackingCommand (key_cmd4); - // Set the keyboard keypress timeout - keyboard->setKeypressTimeout (key_timeout); - } + const auto& keyboard = FTerm::getFKeyboard(); + auto cmd1 = std::bind(&FApplication::keyPressed, this); + auto cmd2 = std::bind(&FApplication::keyReleased, this); + auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this); + auto cmd4 = std::bind(&FApplication::mouseTracking, this); + FKeyboardCommand key_cmd1 (cmd1); + FKeyboardCommand key_cmd2 (cmd2); + FKeyboardCommand key_cmd3 (cmd3); + FKeyboardCommand key_cmd4 (cmd4); + keyboard->setPressCommand (key_cmd1); + keyboard->setReleaseCommand (key_cmd2); + keyboard->setEscPressedCommand (key_cmd3); + keyboard->setMouseTrackingCommand (key_cmd4); + // Set the keyboard keypress timeout + keyboard->setKeypressTimeout (key_timeout); // Initialize mouse control - mouse = FTerm::getFMouseControl(); - - if ( mouse ) - { - using namespace std::placeholders; - auto cmd = std::bind(&FApplication::mouseEvent, this, _1); - FMouseCommand mouse_cmd (cmd); - mouse->setEventCommand (mouse_cmd); - // Set stdin number for a gpm-mouse - mouse->setStdinNo (FTermios::getStdIn()); - // Set the default double click interval - mouse->setDblclickInterval (dblclick_interval); - } + const auto& mouse = FTerm::getFMouseControl(); + using namespace std::placeholders; + auto cmd = std::bind(&FApplication::mouseEvent, this, _1); + FMouseCommand mouse_cmd (cmd); + mouse->setEventCommand (mouse_cmd); + // Set stdin number for a gpm-mouse + mouse->setStdinNo (FTermios::getStdIn()); + // Set the default double click interval + mouse->setDblclickInterval (dblclick_interval); // Initialize logging if ( ! getStartOptions().logfile_stream.is_open() ) @@ -463,10 +452,10 @@ void FApplication::setTerminalEncoding (const FString& enc_str) showParameterUsage(); else { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage ( "Unknown encoding \"" + enc_str - + "\"\n(Valid encodings are utf8, " - + "vt100, pc and ascii)" ); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage ( "Unknown encoding \"" + enc_str + + "\"\n(Valid encodings are utf8, " + + "vt100, pc and ascii)" ); exit(EXIT_FAILURE); } } @@ -665,7 +654,10 @@ inline void FApplication::findKeyboardWidget() const //---------------------------------------------------------------------- inline bool FApplication::isKeyPressed() const { - if ( mouse && mouse->isGpmMouseEnabled() ) + const auto& mouse = FTerm::getFMouseControl(); + const auto& keyboard = FTerm::getFKeyboard(); + + if ( mouse->isGpmMouseEnabled() ) return mouse->getGpmKeyPressed(keyboard->hasUnprocessedInput()); return (keyboard->isKeyPressed() || keyboard->hasPendingInput()); @@ -698,6 +690,8 @@ void FApplication::mouseTracking() const //---------------------------------------------------------------------- inline void FApplication::performKeyboardAction() { + const auto& keyboard = FTerm::getFKeyboard(); + if ( keyboard->getKey() == fc::Fckey_l ) // Ctrl-L (redraw the screen) { redraw(); @@ -715,9 +709,8 @@ inline void FApplication::performKeyboardAction() //---------------------------------------------------------------------- inline void FApplication::performMouseAction() const { - if ( ! mouse ) - return; - + const auto& mouse = FTerm::getFMouseControl(); + const auto& keyboard = FTerm::getFKeyboard(); auto& buffer = keyboard->getKeyBuffer(); switch ( keyboard->getKey() ) @@ -768,6 +761,7 @@ inline void FApplication::sendEscapeKeyPressEvent() const inline bool FApplication::sendKeyDownEvent (FWidget* widget) const { // Send key down event + const auto& keyboard = FTerm::getFKeyboard(); FKeyEvent k_down_ev (fc::KeyDown_Event, keyboard->getKey()); sendEvent (widget, &k_down_ev); return k_down_ev.isAccepted(); @@ -777,6 +771,7 @@ inline bool FApplication::sendKeyDownEvent (FWidget* widget) const inline bool FApplication::sendKeyPressEvent (FWidget* widget) const { // Send key press event + const auto& keyboard = FTerm::getFKeyboard(); FKeyEvent k_press_ev (fc::KeyPress_Event, keyboard->getKey()); sendEvent (widget, &k_press_ev); return k_press_ev.isAccepted(); @@ -786,6 +781,7 @@ inline bool FApplication::sendKeyPressEvent (FWidget* widget) const inline bool FApplication::sendKeyUpEvent (FWidget* widget) const { // Send key up event + const auto& keyboard = FTerm::getFKeyboard(); FKeyEvent k_up_ev (fc::KeyUp_Event, keyboard->getKey()); sendEvent (widget, &k_up_ev); return k_up_ev.isAccepted(); @@ -822,9 +818,12 @@ inline void FApplication::sendKeyboardAccelerator() //---------------------------------------------------------------------- inline bool FApplication::hasDataInQueue() const { - if ( keyboard && keyboard->hasDataInQueue() ) + const auto& keyboard = FTerm::getFKeyboard(); + const auto& mouse = FTerm::getFMouseControl(); + + if ( keyboard->hasDataInQueue() ) return true; - else if ( mouse && mouse->hasDataInQueue() ) + else if ( mouse->hasDataInQueue() ) return true; return false; @@ -833,10 +832,11 @@ inline bool FApplication::hasDataInQueue() const //---------------------------------------------------------------------- void FApplication::queuingKeyboardInput() const { - if ( quit_now || internal::var::exit_loop || ! keyboard ) + if ( quit_now || internal::var::exit_loop ) return; findKeyboardWidget(); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->escapeKeyHandling(); // special case: Esc key keyboard->clearKeyBufferOnTimeout(); @@ -847,10 +847,12 @@ void FApplication::queuingKeyboardInput() const //---------------------------------------------------------------------- void FApplication::queuingMouseInput() const { - if ( quit_now || internal::var::exit_loop - || ! mouse || ! mouse->hasData() ) + const auto& mouse = FTerm::getFMouseControl(); + + if ( quit_now || internal::var::exit_loop || ! mouse->hasData() ) return; + const auto& keyboard = FTerm::getFKeyboard(); struct timeval* time_keypressed = keyboard->getKeyPressedTime(); mouse->processEvent (time_keypressed); keyboard->hasUnprocessedInput() = mouse->hasUnprocessedInput(); @@ -860,24 +862,27 @@ void FApplication::queuingMouseInput() const //---------------------------------------------------------------------- void FApplication::processKeyboardEvent() const { - if ( quit_now || internal::var::exit_loop || ! keyboard ) + if ( quit_now || internal::var::exit_loop ) return; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->processQueuedInput(); } //---------------------------------------------------------------------- void FApplication::processMouseEvent() const { - if ( quit_now || internal::var::exit_loop || ! mouse ) + if ( quit_now || internal::var::exit_loop ) return; - mouse->processQueuedInput(); + FTerm::getFMouseControl()->processQueuedInput(); } //---------------------------------------------------------------------- bool FApplication::processDialogSwitchAccelerator() const { + const auto& keyboard = FTerm::getFKeyboard(); + if ( keyboard->getKey() >= fc::Fmkey_1 && keyboard->getKey() <= fc::Fmkey_9 ) { @@ -914,7 +919,7 @@ bool FApplication::processAccelerator (const FWidget& widget) const for (auto&& item : widget.getAcceleratorList()) { - if ( item.key == keyboard->getKey() ) + if ( item.key == FTerm::getFKeyboard()->getKey() ) { // unset the move/size mode auto move_size = getMoveSizeWidget(); @@ -1244,12 +1249,9 @@ void FApplication::processResizeEvent() const if ( ! FTerm::hasChangedTermSize() ) return; - if ( mouse ) - { - mouse->setMaxWidth (uInt16(getDesktopWidth())); - mouse->setMaxHeight (uInt16(getDesktopHeight())); - } - + const auto& mouse = FTerm::getFMouseControl(); + mouse->setMaxWidth (uInt16(getDesktopWidth())); + mouse->setMaxHeight (uInt16(getDesktopHeight())); FResizeEvent r_ev(fc::Resize_Event); sendEvent(internal::var::app_object, &r_ev); diff --git a/src/fbusyindicator.cpp b/src/fbusyindicator.cpp index 7ffec3c6..db26eaf7 100644 --- a/src/fbusyindicator.cpp +++ b/src/fbusyindicator.cpp @@ -39,8 +39,7 @@ FBusyIndicator::FBusyIndicator (FWidget* parent) } //---------------------------------------------------------------------- -FBusyIndicator::~FBusyIndicator() // destructor -{ } +FBusyIndicator::~FBusyIndicator() noexcept = default; // destructor // public methods of FBusyIndicator diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 9bd22d62..41317b3b 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -374,7 +374,7 @@ void FButtonGroup::drawLabel() else FWidget::setPrintPos (FPoint{0, 1}); - drawText (std::move(label_text), hotkeypos); + drawText (label_text, hotkeypos); setViewportPrint(); } @@ -397,7 +397,7 @@ void FButtonGroup::init() } //---------------------------------------------------------------------- -void FButtonGroup::drawText ( FString&& label_text +void FButtonGroup::drawText ( const FString& label_text , std::size_t hotkeypos ) { const auto& wc = getColorTheme(); diff --git a/src/fcallback.cpp b/src/fcallback.cpp index adc1d367..1f413d69 100644 --- a/src/fcallback.cpp +++ b/src/fcallback.cpp @@ -29,16 +29,6 @@ namespace finalcut // class FCallback //---------------------------------------------------------------------- -// constructors and destructor -//---------------------------------------------------------------------- -FCallback::FCallback() -{ } - -//---------------------------------------------------------------------- -FCallback::~FCallback() // destructor -{ } - - // public methods of FCallback //---------------------------------------------------------------------- void FCallback::delCallback (const FString& cb_signal) diff --git a/src/fcolorpalette.cpp b/src/fcolorpalette.cpp index 9eb8329c..cee215fe 100644 --- a/src/fcolorpalette.cpp +++ b/src/fcolorpalette.cpp @@ -36,8 +36,7 @@ FColorPalette::FColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -FColorPalette::~FColorPalette() // destructor -{ } +FColorPalette::~FColorPalette() noexcept = default; // destructor // protected methods of FColorPalette @@ -79,8 +78,8 @@ default8ColorPalette::default8ColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -default8ColorPalette::~default8ColorPalette() -{ } +default8ColorPalette::~default8ColorPalette() noexcept = default; // destructor + // public methods of default8ColorPalette //---------------------------------------------------------------------- @@ -123,8 +122,8 @@ default16ColorPalette::default16ColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -default16ColorPalette::~default16ColorPalette() -{ } +default16ColorPalette::~default16ColorPalette() noexcept = default; // destructor + // public methods of default16ColorPalette //---------------------------------------------------------------------- @@ -166,8 +165,8 @@ default16DarkColorPalette::default16DarkColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -default16DarkColorPalette::~default16DarkColorPalette() -{ } +default16DarkColorPalette::~default16DarkColorPalette() noexcept = default; // destructor + // public methods of default16DarkColorPalette //---------------------------------------------------------------------- diff --git a/src/fdata.cpp b/src/fdata.cpp index f39345d9..a3778949 100644 --- a/src/fdata.cpp +++ b/src/fdata.cpp @@ -31,12 +31,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FDataAccess::FDataAccess() -{ } - -//---------------------------------------------------------------------- -FDataAccess::~FDataAccess() // destructor -{ } +FDataAccess::~FDataAccess() noexcept = default; // destructor } // namespace finalcut diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 558ed411..de57a594 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -623,7 +623,7 @@ void FDialog::onMouseMove (FMouseEvent* ev) // Mouse event handover to the menu if ( ms.mouse_over_menu ) - passEventToSubMenu (ms, std::move(*ev)); + passEventToSubMenu (ms, *ev); leaveZoomButton(ms); // Check zoom button pressed resizeMouseUpMove(ms); // Resize the dialog @@ -1361,7 +1361,7 @@ inline bool FDialog::isMouseOverMenu (const FPoint& termpos) const //---------------------------------------------------------------------- inline void FDialog::passEventToSubMenu ( const MouseStates& ms - , const FMouseEvent&& ev ) + , const FMouseEvent& ev ) { // Mouse event handover to the dialog menu if ( ! ms.mouse_over_menu diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 0ea6e0de..6b7cf9e7 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -89,9 +89,6 @@ FString fileChooser ( FWidget* parent return ret; } -// static class attributes -FSystem* FFileDialog::fsystem{nullptr}; - //---------------------------------------------------------------------- // class FFileDialog @@ -202,7 +199,9 @@ void FFileDialog::setPath (const FString& dir) return; } - if ( fsystem && fsystem->realpath(dir.c_str(), resolved_path.data()) != nullptr ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->realpath(dir.c_str(), resolved_path.data()) != nullptr ) r_dir.setString(resolved_path.data()); else r_dir.setString(dir); @@ -324,9 +323,6 @@ void FFileDialog::init() int x{}; int y{}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - setGeometry(FPoint{1, 1}, FSize{w, h}, false); const auto& parent_widget = getParentWidget(); @@ -600,9 +596,7 @@ void FFileDialog::followSymLink (const char* const dir, FDirEntry& entry) const std::array symLink{}; struct stat sb{}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); std::strncpy (symLink.data(), dir, symLink.size() - 1); symLink[symLink.size() - 1] = '\0'; std::strncat ( symLink.data() @@ -666,9 +660,6 @@ int FFileDialog::changeDir (const FString& dirname) FString lastdir{directory}; FString newdir{dirname}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - if ( newdir.includes('~') ) newdir = newdir.replace('~', getHomeDir()); @@ -743,9 +734,7 @@ FString FFileDialog::getHomeDir() struct passwd* pwd_ptr{}; std::array buf{}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); const uid_t euid = fsystem->geteuid(); if ( fsystem->getpwuid_r(euid, &pwd, buf.data(), buf.size(), &pwd_ptr) ) diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index 5e8c0319..13a05b8c 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -23,9 +23,7 @@ #include #include -#if defined(__sun) && defined(__SVR4) - #include // need for FIONREAD -#elif defined(__CYGWIN__) +#if defined(__CYGWIN__) #include // need for FD_ZERO, FD_SET, FD_CLR, ... #endif @@ -55,10 +53,6 @@ uInt64 FKeyboard::read_blocking_time_short{5000}; // 5 ms (200 Hz) bool FKeyboard::non_blocking_input_support{true}; struct timeval FKeyboard::time_keypressed{}; -#if defined(__linux__) - FTermLinux* FKeyboard::linux{nullptr}; -#endif - //---------------------------------------------------------------------- // class FKeyboard @@ -77,8 +71,6 @@ FKeyboard::FKeyboard() if ( stdin_status_flags == -1 ) std::abort(); - - term_detection = FTerm::getFTermDetection(); } @@ -136,14 +128,6 @@ bool FKeyboard::setNonBlockingInput (bool enable) return non_blocking_stdin; } -//---------------------------------------------------------------------- -void FKeyboard::init() -{ -#if defined(__linux__) - linux = FTerm::getFTermLinux(); -#endif -} - //---------------------------------------------------------------------- bool& FKeyboard::hasUnprocessedInput() { @@ -465,13 +449,6 @@ FKey FKeyboard::UTF8decode (const char utf8[]) const //---------------------------------------------------------------------- inline ssize_t FKeyboard::readKey() { -#if !defined(__CYGWIN__) - int len{0}; - - if ( ioctl(FTermios::getStdIn(), FIONREAD, &len) < 0 || len == 0 ) - return 0; -#endif - setNonBlockingInput(); const ssize_t bytes = read(FTermios::getStdIn(), &read_character, 1); unsetNonBlockingInput(); @@ -562,8 +539,11 @@ FKey FKeyboard::keyCorrection (const FKey& keycode) const FKey key_correction; #if defined(__linux__) - if ( linux && FTerm::isLinuxTerm() ) - key_correction = linux->modifierKeyCorrection(keycode); + if ( FTerm::isLinuxTerm() ) + { + const auto& linux_console = FTerm::getFTermLinux(); + key_correction = linux_console->modifierKeyCorrection(keycode); + } else key_correction = keycode; #else diff --git a/src/flog.cpp b/src/flog.cpp index c06e1d2c..37567fff 100644 --- a/src/flog.cpp +++ b/src/flog.cpp @@ -30,10 +30,6 @@ namespace finalcut //---------------------------------------------------------------------- // constructors and destructor -//---------------------------------------------------------------------- -FLog::FLog() -{ } - //---------------------------------------------------------------------- FLog::~FLog() // destructor { diff --git a/src/flogger.cpp b/src/flogger.cpp index 6f1bf2a7..216e0b7d 100644 --- a/src/flogger.cpp +++ b/src/flogger.cpp @@ -34,12 +34,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FLogger::FLogger() -{ } - -//---------------------------------------------------------------------- -FLogger::~FLogger() // destructor -{ } +FLogger::~FLogger() noexcept = default; // destructor // private methods of FLogger diff --git a/src/fmenu.cpp b/src/fmenu.cpp index d42b51ec..1bca8375 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -279,19 +279,19 @@ void FMenu::onMouseMove (FMouseEvent* ev) if ( ms.mouse_over_submenu ) { - passEventToSubMenu(std::move(*ev)); // Event handover to sub-menu + passEventToSubMenu(*ev); // Event handover to sub-menu return; } if ( ! ms.mouse_over_menu && ms.mouse_over_supermenu ) { - passEventToSuperMenu(std::move(*ev)); // Event handover to super-menu + passEventToSuperMenu(*ev); // Event handover to super-menu return; } if ( ms.mouse_over_menubar ) { - passEventToMenuBar(std::move(*ev)); // Event handover to the menu bar + passEventToMenuBar(*ev); // Event handover to the menu bar return; } @@ -908,7 +908,7 @@ void FMenu::mouseMoveOverBorder (MouseStates& ms) const } //---------------------------------------------------------------------- -void FMenu::passEventToSubMenu (const FMouseEvent&& ev) +void FMenu::passEventToSubMenu (const FMouseEvent& ev) { // Mouse event handover to sub-menu @@ -931,7 +931,7 @@ void FMenu::passEventToSubMenu (const FMouseEvent&& ev) } //---------------------------------------------------------------------- -void FMenu::passEventToSuperMenu (const FMouseEvent&& ev) +void FMenu::passEventToSuperMenu (const FMouseEvent& ev) { // Mouse event handover to super-menu @@ -955,7 +955,7 @@ void FMenu::passEventToSuperMenu (const FMouseEvent&& ev) } //---------------------------------------------------------------------- -void FMenu::passEventToMenuBar (const FMouseEvent&& ev) const +void FMenu::passEventToMenuBar (const FMouseEvent& ev) const { // Mouse event handover to the menu bar diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 843a6a11..50f899e1 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -209,7 +209,7 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) // Handle menu entries if ( mouse_down ) - mouseMoveOverList(std::move(*ev)); + mouseMoveOverList(*ev); } //---------------------------------------------------------------------- @@ -868,7 +868,7 @@ void FMenuBar::mouseUpOverList (const FMouseEvent* ev) } //---------------------------------------------------------------------- -void FMenuBar::mouseMoveOverList (const FMouseEvent&& ev) +void FMenuBar::mouseMoveOverList (const FMouseEvent& ev) { auto list = getItemList(); diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 6bd4bd6b..f4f13951 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -44,14 +44,10 @@ namespace finalcut // class FMouseData //---------------------------------------------------------------------- -// constructors and destructor +// constructor and destructor //---------------------------------------------------------------------- -FMouseData::FMouseData() -{ } +FMouseData::~FMouseData() noexcept = default; // destructor -//---------------------------------------------------------------------- -FMouseData::~FMouseData() -{ } // public methods of FMouseData //---------------------------------------------------------------------- @@ -182,10 +178,6 @@ FMouse::FMouse() clearButtonState(); } -//---------------------------------------------------------------------- -FMouse::~FMouse() // destructor -{ } - // public methods of FMouse //---------------------------------------------------------------------- @@ -1282,7 +1274,7 @@ void FMouseControl::setMaxHeight (uInt16 y_max) } //---------------------------------------------------------------------- -void FMouseControl::setDblclickInterval (const uInt64 timeout) +void FMouseControl::setDblclickInterval (const uInt64 timeout) const { for (auto&& m : mouse_protocol) if ( m.second ) @@ -1580,7 +1572,7 @@ void FMouseControl::processEvent (struct timeval* time) { mouse_object->processEvent(time); auto& md = static_cast(*mouse_object); - fmousedata_queue.emplace(new FMouseData(std::move(md))); + fmousedata_queue.emplace(make_unique(std::move(md))); } } diff --git a/src/fobject.cpp b/src/fobject.cpp index db0a8943..4fa43513 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -22,7 +22,6 @@ #include -#include "final/emptyfstring.h" #include "final/fevent.h" #include "final/fc.h" #include "final/fobject.h" @@ -32,7 +31,6 @@ namespace finalcut // static class attributes bool FObject::timer_modify_lock; -const FString* fc::emptyFString::empty_string{nullptr}; //---------------------------------------------------------------------- @@ -55,9 +53,6 @@ FObject::~FObject() // destructor { delOwnTimers(); // Delete all timers of this object - if ( ! has_parent && ! fc::emptyFString::isNull() ) - fc::emptyFString::clear(); - // Delete children objects if ( hasChildren() ) { @@ -425,7 +420,7 @@ void FObject::performTimerAction (FObject*, FEvent*) } //---------------------------------------------------------------------- -FObject::FTimerListPtr& FObject::globalTimerList() +auto FObject::globalTimerList() -> const FTimerListUniquePtr& { static const auto& timer_list = make_unique(); return timer_list; diff --git a/src/fstring.cpp b/src/fstring.cpp index 2b3234c3..112092c5 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -76,10 +76,10 @@ FString::FString (const FString& s) // copy constructor //---------------------------------------------------------------------- FString::FString (FString&& s) noexcept // move constructor - : string{std::move(s.string)} + : string{s.string} , length{s.length} , bufsize{s.bufsize} - , c_string{std::move(s.c_string)} + , c_string{s.c_string} { s.string = nullptr; s.length = 0; @@ -185,10 +185,10 @@ FString& FString::operator = (FString&& s) noexcept if ( c_string ) delete[](c_string); - string = std::move(s.string); + string = s.string; length = s.length; bufsize = s.bufsize; - c_string = std::move(s.c_string); + c_string = s.c_string; s.string = nullptr; s.length = 0; @@ -1456,6 +1456,9 @@ inline const wchar_t* FString::_to_wcstring (const char s[]) const auto state = std::mbstate_t(); auto size = std::mbsrtowcs(nullptr, &src, 0, &state) + 1; + if ( size == 0 ) // ...malformed UTF-8 string + return nullptr; + try { dest = new wchar_t[size]; diff --git a/src/fstringstream.cpp b/src/fstringstream.cpp index c019b5d1..a8a4159c 100644 --- a/src/fstringstream.cpp +++ b/src/fstringstream.cpp @@ -54,8 +54,8 @@ FStringStream::FStringStream (FStringStream&& sstream) noexcept } //---------------------------------------------------------------------- -FStringStream::~FStringStream() // destructor -{ } +FStringStream::~FStringStream() noexcept = default; + // public methods of FStringStream //---------------------------------------------------------------------- diff --git a/src/fterm.cpp b/src/fterm.cpp index e54eaf2f..8fe5e285 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -79,32 +79,6 @@ uInt var::object_counter{0}; } // namespace internal -// Static class attributes -FTermData* FTerm::data {nullptr}; -FSystem* FTerm::fsys {nullptr}; -FOptiMove* FTerm::opti_move {nullptr}; -FOptiAttr* FTerm::opti_attr {nullptr}; -FTermDetection* FTerm::term_detection{nullptr}; -FTermXTerminal* FTerm::xterm {nullptr}; -FKeyboard* FTerm::keyboard {nullptr}; -FMouseControl* FTerm::mouse {nullptr}; - -#if defined(UNIT_TEST) - FTermLinux* FTerm::linux {nullptr}; - FTermFreeBSD* FTerm::freebsd {nullptr}; - FTermOpenBSD* FTerm::openbsd {nullptr}; -#elif defined(__linux__) - FTermLinux* FTerm::linux {nullptr}; -#elif defined(__FreeBSD__) || defined(__DragonFly__) - FTermFreeBSD* FTerm::freebsd {nullptr}; -#elif defined(__NetBSD__) || defined(__OpenBSD__) - FTermOpenBSD* FTerm::openbsd {nullptr}; -#endif - -#if DEBUG - FTermDebugData* FTerm::debug_data {nullptr}; -#endif - //---------------------------------------------------------------------- // class FTerm @@ -114,9 +88,6 @@ FMouseControl* FTerm::mouse {nullptr}; //---------------------------------------------------------------------- FTerm::FTerm() { - if ( internal::var::object_counter == 0 ) - allocationValues(); // Allocation of global objects - internal::var::object_counter++; } @@ -129,10 +100,7 @@ FTerm::~FTerm() // destructor internal::var::object_counter--; if ( internal::var::object_counter == 0 ) - { printExitMessage(); - deallocationValues(); // Deallocation of global objects - } } @@ -140,9 +108,7 @@ FTerm::~FTerm() // destructor //---------------------------------------------------------------------- std::size_t FTerm::getLineNumber() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); const auto& term_geometry = data->getTermGeometry(); if ( term_geometry.getHeight() == 0 ) @@ -154,9 +120,7 @@ std::size_t FTerm::getLineNumber() //---------------------------------------------------------------------- std::size_t FTerm::getColumnNumber() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); const auto& term_geometry = data->getTermGeometry(); if ( term_geometry.getWidth() == 0 ) @@ -168,30 +132,35 @@ std::size_t FTerm::getColumnNumber() //---------------------------------------------------------------------- FString FTerm::getKeyName (FKey keynum) { + const auto& keyboard = FTerm::getFKeyboard(); return keyboard->getKeyName (keynum); } //---------------------------------------------------------------------- charSubstitution& FTerm::getCharSubstitutionMap() { + const auto& data = FTerm::getFTermData(); return data->getCharSubstitutionMap(); } //---------------------------------------------------------------------- int FTerm::getTTYFileDescriptor() { - return ( data ) ? data->getTTYFileDescriptor() : 0; + const auto& data = FTerm::getFTermData(); + return data->getTTYFileDescriptor(); } //---------------------------------------------------------------------- const char* FTerm::getTermType() { + const auto& data = FTerm::getFTermData(); return data->getTermType(); } //---------------------------------------------------------------------- const char* FTerm::getTermFileName() { + const auto& data = FTerm::getFTermData(); return data->getTermFileName(); } @@ -208,243 +177,101 @@ int FTerm::getMaxColor() } //---------------------------------------------------------------------- -FTerm::FColorPalettePtr& FTerm::getColorPaletteTheme() +auto FTerm::getColorPaletteTheme() -> std::shared_ptr& { - static auto color_theme = new FColorPalettePtr(); - return *color_theme; + static const auto& color_theme = make_unique>(); + return *color_theme.get(); } //---------------------------------------------------------------------- -FTermData* FTerm::getFTermData() +auto FTerm::getFTermData() -> const std::unique_ptr& { - if ( data == nullptr ) - { - try - { - data = new FTermData; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermData"); - std::abort(); - } - } - + static const auto& data = make_unique(); return data; } //---------------------------------------------------------------------- -FSystem* FTerm::getFSystem() +auto FTerm::getFSystem() -> std::unique_ptr& { - if ( fsys == nullptr ) - { - try - { - fsys = new FSystemImpl; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FSystemImpl"); - std::abort(); - } - } - - return fsys; + static const auto& fsys = make_unique>(make_unique()); + return *fsys.get(); } //---------------------------------------------------------------------- -FOptiMove* FTerm::getFOptiMove() +auto FTerm::getFOptiMove() -> const std::unique_ptr& { - if ( opti_move == nullptr ) - { - try - { - opti_move = new FOptiMove; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FOptiMove"); - std::abort(); - } - } - + static const auto& opti_move = make_unique(); return opti_move; } //---------------------------------------------------------------------- -FOptiAttr* FTerm::getFOptiAttr() +auto FTerm::getFOptiAttr() -> const std::unique_ptr& { - if ( opti_attr == nullptr ) - { - try - { - opti_attr = new FOptiAttr; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FOptiAttr"); - std::abort(); - } - } - + static const auto& opti_attr = make_unique(); return opti_attr; } //---------------------------------------------------------------------- -FTermDetection* FTerm::getFTermDetection() +auto FTerm::getFTermDetection() -> const std::unique_ptr& { - if ( term_detection == nullptr ) - { - try - { - term_detection = new FTermDetection; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermDetection"); - std::abort(); - } - } - + static const auto& term_detection = make_unique(); return term_detection; } //---------------------------------------------------------------------- -FTermXTerminal* FTerm::getFTermXTerminal() +auto FTerm::getFTermXTerminal() -> const std::unique_ptr& { - if ( xterm == nullptr ) - { - try - { - xterm = new FTermXTerminal; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermXTerminal"); - std::abort(); - } - } - + static const auto& xterm = make_unique(); return xterm; } //---------------------------------------------------------------------- -FKeyboard* FTerm::getFKeyboard() +auto FTerm::getFKeyboard() -> const std::unique_ptr& { - if ( keyboard == nullptr ) - { - try - { - keyboard = new FKeyboard; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FKeyboard"); - std::abort(); - } - } - + static const auto& keyboard = make_unique(); return keyboard; } //---------------------------------------------------------------------- -FMouseControl* FTerm::getFMouseControl() +auto FTerm::getFMouseControl() -> const std::unique_ptr& { - if ( mouse == nullptr ) - { - try - { - mouse = new FMouseControl; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FMouseControl"); - std::abort(); - } - } - + static const auto& mouse = make_unique(); return mouse; } -#if defined(__linux__) +#if defined(__linux__) || defined(UNIT_TEST) //---------------------------------------------------------------------- -FTermLinux* FTerm::getFTermLinux() +auto FTerm::getFTermLinux() -> const std::unique_ptr& { - if ( linux == nullptr ) - { - try - { - linux = new FTermLinux; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermLinux"); - std::abort(); - } - } - - return linux; + static const auto& linux_console = make_unique(); + return linux_console; } +#endif -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) //---------------------------------------------------------------------- -FTermFreeBSD* FTerm::getFTermFreeBSD() +auto FTerm::getFTermFreeBSD() -> const std::unique_ptr& { - if ( freebsd == nullptr ) - { - try - { - freebsd = new FTermFreeBSD; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermFreeBSD"); - std::abort(); - } - } - - return freebsd; + static const auto& freebsd_console = make_unique(); + return freebsd_console; } +#endif -#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) //---------------------------------------------------------------------- -FTermOpenBSD* FTerm::getFTermOpenBSD() +auto FTerm::getFTermOpenBSD() -> const std::unique_ptr& { - if ( openbsd == nullptr ) - { - try - { - openbsd = new FTermOpenBSD; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermOpenBSD"); - std::abort(); - } - } - - return openbsd; + static const auto& openbsd_console = make_unique(); + return openbsd_console; } #endif #if DEBUG //---------------------------------------------------------------------- -FTermDebugData& FTerm::getFTermDebugData() +auto FTerm::getFTermDebugData() -> const std::unique_ptr& { - if ( debug_data == nullptr ) - { - try - { - debug_data = new FTermDebugData; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermDebugData"); - std::abort(); - } - } - - return *debug_data; + static const auto& debug_data = make_unique(); + return debug_data; } #endif // DEBUG @@ -457,138 +284,161 @@ bool FTerm::isNormal (const FChar& ch) //---------------------------------------------------------------------- bool FTerm::hasUTF8() { + const auto& data = FTerm::getFTermData(); return data->hasUTF8Console(); } //---------------------------------------------------------------------- bool FTerm::isMonochron() { + const auto& data = FTerm::getFTermData(); return data->isMonochron(); } //---------------------------------------------------------------------- bool FTerm::isAnsiTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isAnsiTerminal(); } //---------------------------------------------------------------------- bool FTerm::isXTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isXTerminal(); } //---------------------------------------------------------------------- bool FTerm::isRxvtTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isRxvtTerminal(); } //---------------------------------------------------------------------- bool FTerm::isUrxvtTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isUrxvtTerminal(); } //---------------------------------------------------------------------- bool FTerm::isKdeTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isKdeTerminal(); } //---------------------------------------------------------------------- bool FTerm::isGnomeTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isGnomeTerminal(); } //---------------------------------------------------------------------- bool FTerm::isPuttyTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isPuttyTerminal(); } //---------------------------------------------------------------------- bool FTerm::isWindowsTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isWindowsTerminal(); } //---------------------------------------------------------------------- bool FTerm::isTeraTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isTeraTerm(); } //---------------------------------------------------------------------- bool FTerm::isCygwinTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isCygwinTerminal(); } //---------------------------------------------------------------------- bool FTerm::isMinttyTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isMinttyTerm(); } //---------------------------------------------------------------------- bool FTerm::isLinuxTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isLinuxTerm(); } //---------------------------------------------------------------------- bool FTerm::isFreeBSDTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isFreeBSDTerm(); } //---------------------------------------------------------------------- bool FTerm::isNetBSDTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isNetBSDTerm(); } //---------------------------------------------------------------------- bool FTerm::isOpenBSDTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isOpenBSDTerm(); } //---------------------------------------------------------------------- bool FTerm::isSunTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isSunTerminal(); } //---------------------------------------------------------------------- bool FTerm::isScreenTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isScreenTerm(); } //---------------------------------------------------------------------- bool FTerm::isTmuxTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isTmuxTerm(); } //---------------------------------------------------------------------- bool FTerm::isKtermTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isKtermTerminal(); } //---------------------------------------------------------------------- bool FTerm::isMltermTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isMltermTerminal(); } //---------------------------------------------------------------------- bool FTerm::isNewFont() { + const auto& data = FTerm::getFTermData(); return data->isNewFont(); } @@ -612,24 +462,28 @@ bool FTerm::isCursorHideable() //---------------------------------------------------------------------- bool FTerm::hasChangedTermSize() { + const auto& data = FTerm::getFTermData(); return data->hasTermResized(); } //---------------------------------------------------------------------- bool FTerm::hasShadowCharacter() { + const auto& data = FTerm::getFTermData(); return data->hasShadowCharacter(); } //---------------------------------------------------------------------- bool FTerm::hasHalfBlockCharacter() { + const auto& data = FTerm::getFTermData(); return data->hasHalfBlockCharacter(); } //---------------------------------------------------------------------- bool FTerm::hasAlternateScreen() { + const auto& data = FTerm::getFTermData(); return data->hasAlternateScreen(); } @@ -652,6 +506,7 @@ bool FTerm::canChangeColorPalette() //---------------------------------------------------------------------- void FTerm::setTermType (const char term_name[]) { + const auto& data = FTerm::getFTermData(); data->setTermType(term_name); } @@ -676,6 +531,7 @@ void FTerm::redefineDefaultColors (bool enable) //---------------------------------------------------------------------- void FTerm::setDblclickInterval (const uInt64 timeout) { + const auto& mouse = FTerm::getFMouseControl(); mouse->setDblclickInterval(timeout); } @@ -690,6 +546,8 @@ void FTerm::useAlternateScreen (bool enable) //---------------------------------------------------------------------- bool FTerm::setUTF8 (bool enable) // UTF-8 (Unicode) { + const auto& data = FTerm::getFTermData(); + if ( data->isUTF8() == enable ) return enable; @@ -699,7 +557,7 @@ bool FTerm::setUTF8 (bool enable) // UTF-8 (Unicode) data->setUTF8(false); #if defined(__linux__) - linux->setUTF8 (enable); + FTerm::getFTermLinux()->setUTF8 (enable); #endif return data->isUTF8(); @@ -708,6 +566,8 @@ bool FTerm::setUTF8 (bool enable) // UTF-8 (Unicode) //---------------------------------------------------------------------- bool FTerm::setVGAFont() { + const auto& data = FTerm::getFTermData(); + if ( data->isVGAFont() ) return data->isVGAFont(); @@ -726,7 +586,8 @@ bool FTerm::setVGAFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - data->setVGAFont(linux->loadVGAFont()); + const auto& linux_console = FTerm::getFTermLinux(); + data->setVGAFont(linux_console->loadVGAFont()); } #endif // defined(__linux__) else @@ -744,6 +605,8 @@ bool FTerm::setVGAFont() //---------------------------------------------------------------------- bool FTerm::setNewFont() { + const auto& data = FTerm::getFTermData(); + if ( isNewFont() ) return true; @@ -760,7 +623,8 @@ bool FTerm::setNewFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - data->setNewFont(linux->loadNewFont()); + const auto& linux_console = FTerm::getFTermLinux(); + data->setNewFont(linux_console->loadNewFont()); } #endif // defined(__linux__) else @@ -779,6 +643,7 @@ bool FTerm::setNewFont() bool FTerm::resetFont() { bool retval{false}; + const auto& data = FTerm::getFTermData(); if ( ! (data->isNewFont() || data->isVGAFont()) ) return false; @@ -807,7 +672,8 @@ bool FTerm::resetFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - retval = linux->loadOldFont(); + const auto& linux_console = FTerm::getFTermLinux(); + retval = linux_console->loadOldFont(); } #endif // defined(__linux__) @@ -823,9 +689,7 @@ bool FTerm::resetFont() //---------------------------------------------------------------------- int FTerm::openConsole() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); int fd = data->getTTYFileDescriptor(); const char* termfilename = data->getTermFileName(); @@ -842,11 +706,12 @@ int FTerm::openConsole() if ( fd >= 0 ) // console is already opened return 0; - if ( ! *termfilename || ! fsys ) + if ( ! *termfilename ) return 0; for (auto&& entry : terminal_devices) { + const auto& fsys = FTerm::getFSystem(); fd = fsys->open(entry, O_RDWR, 0); data->setTTYFileDescriptor(fd); @@ -860,20 +725,15 @@ int FTerm::openConsole() //---------------------------------------------------------------------- int FTerm::closeConsole() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); const int fd = data->getTTYFileDescriptor(); int ret{-1}; if ( fd < 0 ) // console is already closed return 0; - if ( ! fsys ) - getFSystem(); - + const auto& fsys = FTerm::getFSystem(); ret = fsys->close(fd); // close console - data->setTTYFileDescriptor(-1); if ( ret == 0 ) @@ -887,8 +747,13 @@ const char* FTerm::moveCursorString (int xold, int yold, int xnew, int ynew) { // Returns the cursor move string + const auto& data = FTerm::getFTermData(); + if ( data->hasCursorOptimisation() ) + { + const auto& opti_move = FTerm::getFOptiMove(); return opti_move->moveCursor (xold, yold, xnew, ynew); + } else return FTermcap::encodeMotionParameter(TCAP(fc::t_cursor_address), xnew, ynew); } @@ -899,6 +764,7 @@ const char* FTerm::cursorsVisibilityString (bool enable) // Hides or shows the input cursor on the terminal const char* visibility_str{nullptr}; + const auto& data = FTerm::getFTermData(); if ( data->isCursorHidden() == enable ) return nullptr; @@ -926,9 +792,7 @@ void FTerm::detectTermSize() { // Detect the terminal width and height - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); struct winsize win_size{}; auto& term_geometry = data->getTermGeometry(); int ret{}; @@ -936,9 +800,7 @@ void FTerm::detectTermSize() do { - if ( ! fsys ) - getFSystem(); - + const auto& fsys = FTerm::getFSystem(); ret = fsys->ioctl (FTermios::getStdOut(), TIOCGWINSZ, &win_size); } while (errno == EINTR); @@ -958,9 +820,9 @@ void FTerm::detectTermSize() term_geometry.setRect(1, 1, win_size.ws_col, win_size.ws_row); } - if ( opti_move ) - opti_move->setTermSize ( term_geometry.getWidth() - , term_geometry.getHeight() ); + const auto& opti_move = FTerm::getFOptiMove(); + opti_move->setTermSize ( term_geometry.getWidth() + , term_geometry.getHeight() ); } //---------------------------------------------------------------------- @@ -997,7 +859,7 @@ void FTerm::setKDECursor (fc::kdeKonsoleCursorShape style) void FTerm::saveColorMap() { #if defined(__linux__) - linux->saveColorMap(); + FTerm::getFTermLinux()->saveColorMap(); #endif } @@ -1012,7 +874,7 @@ void FTerm::resetColorMap() #if defined(__linux__) else - linux->resetColorMap(); + FTerm::getFTermLinux()->resetColorMap(); #endif if ( op ) @@ -1054,7 +916,7 @@ void FTerm::setPalette (FColor index, int r, int g, int b) #if defined(__linux__) else { - state = linux->setPalette(index, r, g, b); + state = FTerm::getFTermLinux()->setPalette(index, r, g, b); } #endif @@ -1063,27 +925,23 @@ void FTerm::setPalette (FColor index, int r, int g, int b) } //---------------------------------------------------------------------- -#if defined(UNIT_TEST) +#if defined(__linux__) || defined(UNIT_TEST) void FTerm::setBeep (int Hz, int ms) { - linux->setBeep (Hz, ms); - freebsd->setBeep (Hz, ms); - openbsd->setBeep (Hz, ms); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->setBeep (Hz, ms); } -#elif defined(__linux__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) void FTerm::setBeep (int Hz, int ms) { - linux->setBeep (Hz, ms); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setBeep (Hz, ms); } -#elif defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) void FTerm::setBeep (int Hz, int ms) { - freebsd->setBeep (Hz, ms); -} -#elif defined(__NetBSD__) || defined(__OpenBSD__) -void FTerm::setBeep (int Hz, int ms) -{ - openbsd->setBeep (Hz, ms); + const auto& openbsd_console = FTerm::getFTermOpenBSD(); + openbsd_console->setBeep (Hz, ms); } #else void FTerm::setBeep (int, int) @@ -1093,16 +951,19 @@ void FTerm::setBeep (int, int) //---------------------------------------------------------------------- void FTerm::resetBeep() { -#if defined(UNIT_TEST) - linux->resetBeep(); - freebsd->resetBeep(); - openbsd->resetBeep(); -#elif defined(__linux__) - linux->resetBeep(); -#elif defined(__FreeBSD__) || defined(__DragonFly__) - freebsd->resetBeep(); -#elif defined(__NetBSD__) || defined(__OpenBSD__) - openbsd->resetBeep(); +#if defined(__linux__) || defined(UNIT_TEST) + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->resetBeep(); +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->resetBeep(); +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) + const auto& openbsd_console = FTerm::getFTermOpenBSD(); + openbsd_console->resetBeep(); #endif } @@ -1119,6 +980,7 @@ void FTerm::beep() //---------------------------------------------------------------------- void FTerm::setEncoding (fc::encoding enc) { + const auto& data = FTerm::getFTermData(); data->setTermEncoding (enc); assert ( enc == fc::UTF8 @@ -1151,6 +1013,8 @@ void FTerm::setEncoding (fc::encoding enc) if ( isLinuxTerm() ) { + const auto& opti_move = FTerm::getFOptiMove(); + if ( enc == fc::VT100 || enc == fc::PC ) { const char* empty{nullptr}; @@ -1164,12 +1028,14 @@ void FTerm::setEncoding (fc::encoding enc) //---------------------------------------------------------------------- fc::encoding FTerm::getEncoding() { + const auto& data = FTerm::getFTermData(); return data->getTermEncoding(); } //---------------------------------------------------------------------- std::string FTerm::getEncodingString() { + const auto& data = FTerm::getFTermData(); const auto& term_encoding = data->getTermEncoding(); const auto& encoding_list = data->getEncodingList(); const auto& end = encoding_list.end(); @@ -1191,6 +1057,7 @@ bool FTerm::charEncodable (wchar_t c) //---------------------------------------------------------------------- wchar_t FTerm::charEncode (wchar_t c) { + const auto& data = FTerm::getFTermData(); return charEncode (c, data->getTermEncoding()); } @@ -1243,8 +1110,8 @@ bool FTerm::scrollTermReverse() //---------------------------------------------------------------------- FTerm::defaultPutChar& FTerm::putchar() { - static auto fputchar = new defaultPutChar(); - return *fputchar; + static const auto& fputchar = make_unique(&FTerm::putchar_ASCII); + return *fputchar.get(); } //---------------------------------------------------------------------- @@ -1256,8 +1123,7 @@ void FTerm::putstring (const char str[], int affcnt) //---------------------------------------------------------------------- int FTerm::putchar_ASCII (int c) { - if ( ! fsys ) - getFSystem(); + const auto& fsys = FTerm::getFSystem(); if ( fsys->putchar(char(c)) == EOF ) return 0; @@ -1268,8 +1134,7 @@ int FTerm::putchar_ASCII (int c) //---------------------------------------------------------------------- int FTerm::putchar_UTF8 (int c) { - if ( ! fsys ) - getFSystem(); + const auto& fsys = FTerm::getFSystem(); if ( c < 0x80 ) { @@ -1313,9 +1178,11 @@ void FTerm::initScreenSettings() #if defined(__linux__) // Important: Do not use setNewFont() or setVGAFont() after // the console character mapping has been initialized - linux->initCharMap(); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->initCharMap(); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->initCharMap(); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->initCharMap(); #endif // set xterm underline cursor @@ -1328,12 +1195,14 @@ void FTerm::initScreenSettings() //---------------------------------------------------------------------- const char* FTerm::changeAttribute (FChar& term_attr, FChar& next_attr) { + const auto& opti_attr = FTerm::getFOptiAttr(); return opti_attr->changeAttribute (term_attr, next_attr); } //---------------------------------------------------------------------- void FTerm::changeTermSizeFinished() { + const auto& data = FTerm::getFTermData(); data->setTermResized(false); } @@ -1350,18 +1219,16 @@ void FTerm::init_global_values() { // Initialize global values + const auto& data = FTerm::getFTermData(); + // Preset to false data->setNewFont(false); - // Initialize xterm object - getFTermXTerminal()->init(); - if ( ! getStartOptions().terminal_detection ) + { + const auto& term_detection = FTerm::getFTermDetection(); term_detection->setTerminalDetection (false); - -#if DEBUG - debug_data->init(); -#endif + } } //---------------------------------------------------------------------- @@ -1373,6 +1240,7 @@ void FTerm::init_terminal_device_path() if ( ttyname_r(stdout_no, termfilename.data(), termfilename.size()) ) termfilename[0] = '\0'; + const auto& data = FTerm::getFTermData(); data->setTermFileName(termfilename.data()); } @@ -1451,6 +1319,7 @@ void FTerm::init_alt_charset() void FTerm::init_pc_charset() { bool reinit{false}; + const auto& opti_attr = FTerm::getFOptiAttr(); // rxvt does not support pc charset if ( isRxvtTerminal() || isUrxvtTerminal() ) @@ -1458,6 +1327,8 @@ void FTerm::init_pc_charset() if ( isGnomeTerminal() || isLinuxTerm() ) { + const auto& data = FTerm::getFTermData(); + // Fallback if tcap "S2" is not found if ( ! TCAP(fc::t_enter_pc_charset_mode) ) { @@ -1531,6 +1402,7 @@ void FTerm::init_cygwin_charmap() } // General encoding changes + const auto& data = FTerm::getFTermData(); charSubstitution& sub_map = data->getCharSubstitutionMap(); sub_map[L'•'] = L'*'; sub_map[L'●'] = L'*'; @@ -1569,12 +1441,6 @@ void FTerm::init_teraterm_charmap() entry[fc::PC] = entry[fc::ASCII]; } -//---------------------------------------------------------------------- -void FTerm::init_keyboard() -{ - FKeyboard::init(); -} - //---------------------------------------------------------------------- void FTerm::init_termcap() { @@ -1623,6 +1489,7 @@ void FTerm::init_optiMove() FTermcap::eat_nl_glitch }; + const auto& opti_move = FTerm::getFOptiMove(); opti_move->setTermEnvironment(optimove_env); } @@ -1673,12 +1540,15 @@ void FTerm::init_optiAttr() FTermcap::ansi_default_color }; + const auto& opti_attr = FTerm::getFOptiAttr(); opti_attr->setTermEnvironment(optiattr_env); } //---------------------------------------------------------------------- bool FTerm::init_font() { + const auto& data = FTerm::getFTermData(); + if ( getStartOptions().vgafont && ! setVGAFont() ) { data->setExitMessage("VGAfont is not supported by this terminal"); @@ -1699,6 +1569,7 @@ void FTerm::init_locale() { // Init current locale + const auto& data = FTerm::getFTermData(); const char* termtype = data->getTermType(); const char* locale_name = std::setlocale (LC_ALL, ""); std::setlocale (LC_NUMERIC, ""); @@ -1777,6 +1648,7 @@ inline void FTerm::init_encoding_set() { // Define the encoding set + const auto& data = FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF8"] = fc::UTF8; encoding_list["UTF-8"] = fc::UTF8; @@ -1789,10 +1661,9 @@ inline void FTerm::init_encoding_set() void FTerm::init_term_encoding() { const int stdout_no = FTermios::getStdOut(); + const auto& data = FTerm::getFTermData(); const char* termtype = data->getTermType(); - - if ( ! fsys ) - getFSystem(); + const auto& fsys = FTerm::getFSystem(); if ( fsys->isTTY(stdout_no) && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) @@ -1802,6 +1673,7 @@ void FTerm::init_term_encoding() putchar() = &FTerm::putchar_UTF8; // function pointer data->setUTF8(true); setUTF8(true); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->enableUTF8(); } else if ( fsys->isTTY(stdout_no) @@ -1823,6 +1695,8 @@ void FTerm::init_term_encoding() //---------------------------------------------------------------------- void FTerm::init_individual_term_encoding() { + const auto& data = FTerm::getFTermData(); + if ( isNewFont() || (isPuttyTerminal() && ! data->isUTF8()) || (isTeraTerm() && ! data->isUTF8()) ) @@ -1840,6 +1714,7 @@ void FTerm::init_individual_term_encoding() //---------------------------------------------------------------------- void FTerm::init_force_vt100_encoding() { + const auto& data = FTerm::getFTermData(); data->setVT100Console(true); data->setTermEncoding (fc::VT100); putchar() = &FTerm::putchar_ASCII; // function pointer @@ -1851,6 +1726,8 @@ void FTerm::init_utf8_without_alt_charset() // Fall back to ascii for utf-8 terminals that // do not support VT100 line drawings + const auto& data = FTerm::getFTermData(); + if ( FTermcap::no_utf8_acs_chars && data->isUTF8() && data->getTermEncoding() == fc::VT100 ) { @@ -1867,11 +1744,13 @@ void FTerm::init_tab_quirks() // on the terminal and does not move the cursor to the next tab stop // position + const auto& data = FTerm::getFTermData(); const auto& enc = data->getTermEncoding(); if ( enc == fc::VT100 || enc == fc::PC ) { const char* empty{nullptr}; + const auto& opti_move = FTerm::getFOptiMove(); opti_move->set_tabular (empty); } } @@ -1887,6 +1766,7 @@ void FTerm::init_captureFontAndTitle() getFTermXTerminal()->captureFontAndTitle(); const auto& font = getFTermXTerminal()->getFont(); const auto& title = getFTermXTerminal()->getTitle(); + const auto& data = FTerm::getFTermData(); if ( ! font.isEmpty() ) data->setXtermFont(font); @@ -1979,9 +1859,11 @@ void FTerm::setInsertCursorStyle() setKDECursor(fc::UnderlineCursor); #if defined(__linux__) - linux->setCursorStyle (fc::underscore_cursor); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->setCursorStyle (fc::underscore_cursor); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->setCursorStyle (fc::destructive_cursor); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setCursorStyle (fc::destructive_cursor); #endif if ( isUrxvtTerminal() ) @@ -1995,9 +1877,11 @@ void FTerm::setOverwriteCursorStyle() setKDECursor(fc::BlockCursor); #if defined(__linux__) - linux->setCursorStyle (fc::full_block_cursor); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->setCursorStyle (fc::full_block_cursor); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->setCursorStyle (fc::normal_cursor); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setCursorStyle (fc::normal_cursor); #endif if ( isUrxvtTerminal() ) @@ -2023,7 +1907,8 @@ const char* FTerm::enableCursorString() if ( isLinuxTerm() ) { // Restore the last used Linux console cursor style - const char* cstyle = linux->getCursorStyleString(); + const auto& linux_console = FTerm::getFTermLinux(); + const char* cstyle = linux_console->getCursorStyleString(); std::size_t length = std::strlen(enable_str.data()); std::strncat (enable_str.data(), cstyle, SIZE - length - 1); } @@ -2035,7 +1920,8 @@ const char* FTerm::enableCursorString() if ( isFreeBSDTerm() ) { // Restore the last used FreeBSD console cursor style - freebsd->setCursorStyle (freebsd->getCursorStyle()); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setCursorStyle (freebsd_console->getCursorStyle()); } #endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) @@ -2069,7 +1955,7 @@ void FTerm::enableMouse() #if defined(__linux__) if ( isLinuxTerm() && openConsole() == 0 ) { - if ( linux->isLinuxConsole() ) + if ( FTerm::getFTermLinux()->isLinuxConsole() ) gpm_mouse = true; closeConsole(); @@ -2079,7 +1965,9 @@ void FTerm::enableMouse() if ( TCAP(fc::t_key_mouse) && ! isLinuxTerm() ) xterm_mouse = true; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->enableMouseSequences(); + const auto& mouse = FTerm::getFMouseControl(); mouse->setMaxWidth (uInt16(getColumnNumber())); mouse->setMaxHeight (uInt16(getLineNumber())); // Enable the linux general purpose mouse (gpm) server @@ -2094,8 +1982,8 @@ inline void FTerm::disableMouse() { // Disable the terminal mouse support - keyboard->disableMouseSequences(); - mouse->disable(); + FTerm::getFKeyboard()->disableMouseSequences(); + FTerm::getFMouseControl()->disable(); } //---------------------------------------------------------------------- @@ -2200,80 +2088,6 @@ void FTerm::useNormalScreenBuffer() } } -//---------------------------------------------------------------------- -inline void FTerm::allocationValues() const -{ - FStartOptions::getFStartOptions(); - getFTermData(); - getFSystem(); - getFOptiMove(); - getFOptiAttr(); - getFTermDetection(); - getFTermXTerminal(); - getFKeyboard(); - getFMouseControl(); - -#if defined(__linux__) - getFTermLinux(); -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - getFTermFreeBSD(); -#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - getFTermOpenBSD(); -#endif - -#if DEBUG - getFTermDebugData(); -#endif -} - -//---------------------------------------------------------------------- -inline void FTerm::deallocationValues() -{ -#if DEBUG - if ( debug_data ) - delete debug_data; -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - if ( openbsd ) - delete openbsd; -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - if ( freebsd ) - delete freebsd; -#elif defined(__linux__) - if ( linux ) - delete linux; -#endif - - if ( mouse ) - delete mouse; - - if ( keyboard ) - delete keyboard; - - if ( xterm ) - delete xterm; - - if ( term_detection ) - delete term_detection; - - if ( opti_attr ) - delete opti_attr; - - if ( opti_move ) - delete opti_move; - - if ( fsys ) - delete fsys; - - if ( data ) - delete data; - - const defaultPutChar* putchar_ptr = &(putchar()); - delete putchar_ptr; - destroyColorPaletteTheme(); -} - //---------------------------------------------------------------------- void FTerm::init() { @@ -2305,6 +2119,7 @@ void FTerm::init() init_alt_charset(); // Pass the terminal capabilities to the keyboard object + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setTermcapMap (fc::fkey); // Initializes locale information @@ -2313,9 +2128,6 @@ void FTerm::init() // Detect environment and set encoding init_encoding(); - // Initializes keyboard settings - init_keyboard(); - // Enable the terminal mouse support enableMouse(); @@ -2351,7 +2163,9 @@ void FTerm::init() setSignalHandler(); if ( ! getStartOptions().cursor_optimisation ) - data->supportCursorOptimisation(false); + { + FTerm::getFTermData()->supportCursorOptimisation(false); + } // Activate the VGA or the new graphic font // (depending on the initialization values) @@ -2373,6 +2187,8 @@ bool FTerm::init_terminal() const { // Initialize termios FTermios::init(); + const auto& data = FTerm::getFTermData(); + const auto& fsys = FTerm::getFSystem(); // Check if stdin is a tty if ( ! fsys->isTTY(FTermios::getStdIn()) ) @@ -2406,6 +2222,7 @@ bool FTerm::init_terminal() const // Terminal detection FTermDetection::detect(); + const auto& term_detection = FTerm::getFTermDetection(); setTermType (term_detection->getTermType()); return true; } @@ -2414,33 +2231,39 @@ bool FTerm::init_terminal() const void FTerm::initOSspecifics() const { #if defined(__linux__) - linux->init(); // Initialize Linux console + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->init(); // Initialize Linux console #if DEBUG - data->setFramebufferBpp (linux->getFramebufferBpp()); + const auto& data = FTerm::getFTermData(); + data->setFramebufferBpp (linux_console->getFramebufferBpp()); #endif #endif // defined(__linux__) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + if ( getStartOptions().meta_sends_escape ) - freebsd->enableMetaSendsEscape(); + freebsd_console->enableMetaSendsEscape(); else - freebsd->disableMetaSendsEscape(); + freebsd_console->disableMetaSendsEscape(); if ( getStartOptions().change_cursorstyle ) - freebsd->enableChangeCursorStyle(); + freebsd_console->enableChangeCursorStyle(); else - freebsd->disableChangeCursorStyle(); + freebsd_console->disableChangeCursorStyle(); - freebsd->init(); // Initialize BSD console + freebsd_console->init(); // Initialize BSD console #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - if ( getStartOptions().meta_sends_escape ) - openbsd->enableMetaSendsEscape(); - else - openbsd->disableMetaSendsEscape(); + const auto& openbsd_console = FTerm::getFTermOpenBSD(); - openbsd->init(); // Initialize wscons console + if ( getStartOptions().meta_sends_escape ) + openbsd_console->enableMetaSendsEscape(); + else + openbsd_console->disableMetaSendsEscape(); + + openbsd_console->init(); // Initialize wscons console #endif } @@ -2462,13 +2285,14 @@ void FTerm::initBaudRate() const { const int stdout_no = FTermios::getStdOut(); const uInt baud = FTermios::getBaudRate(); - data->setBaudrate(baud); - - if ( ! fsys ) - getFSystem(); + FTerm::getFTermData()->setBaudrate(baud); + const auto& fsys = FTerm::getFSystem(); if ( fsys->isTTY(stdout_no) ) + { + const auto& opti_move = FTerm::getFOptiMove(); opti_move->setBaudRate(int(baud)); + } } //---------------------------------------------------------------------- @@ -2531,6 +2355,7 @@ void FTerm::finish() const disableKeypad(); finish_encoding(); + const auto& data = FTerm::getFTermData(); if ( data->isNewFont() || data->isVGAFont() ) resetFont(); @@ -2540,11 +2365,13 @@ void FTerm::finish() const void FTerm::finishOSspecifics() const { #if defined(__linux__) - linux->finish(); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->finish(); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->finish(); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->finish(); #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - openbsd->finish(); + openbsd_console->finish(); #endif } @@ -2552,22 +2379,16 @@ void FTerm::finishOSspecifics() const void FTerm::finish_encoding() const { #if defined(__linux__) - if ( isLinuxTerm() && data->hasUTF8Console() ) + if ( isLinuxTerm() && FTerm::getFTermData()->hasUTF8Console() ) setUTF8(true); #endif } -//---------------------------------------------------------------------- -void FTerm::destroyColorPaletteTheme() -{ - const FColorPalettePtr* theme = &(getColorPaletteTheme()); - delete theme; -} - //---------------------------------------------------------------------- void FTerm::printExitMessage() { // Print exit message + const auto& data = FTerm::getFTermData(); const auto& exit_message = data->getExitMessage(); if ( ! exit_message.isEmpty() ) @@ -2577,8 +2398,7 @@ void FTerm::printExitMessage() //---------------------------------------------------------------------- void FTerm::terminalSizeChange() { - if ( ! data ) - return; + const auto& data = FTerm::getFTermData(); if ( data->hasTermResized() ) return; @@ -2595,19 +2415,12 @@ void FTerm::processTermination (int signum) std::fflush (stderr); std::fflush (stdout); - - if ( data ) - { - FStringStream msg{}; - msg << "Program stopped: signal " << signum - << " (" << strsignal(signum) << ")"; - data->setExitMessage(msg.str()); - printExitMessage(); - } - - if ( internal::var::init_term_object ) - internal::var::init_term_object->deallocationValues(); - + const auto& data = FTerm::getFTermData(); + FStringStream msg{}; + msg << "Program stopped: signal " << signum + << " (" << strsignal(signum) << ")"; + data->setExitMessage(msg.str()); + printExitMessage(); std::terminate(); } diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index f6cb0c3c..27df36c0 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -66,13 +66,12 @@ int FTermBuffer::write (const FString& string) for (auto&& c : string) { - FChar nc; // next character - nc = FVTerm::getAttribute(); + FChar nc{FVTerm::getAttribute()}; // next character nc.ch[0] = c; nc.attr.byte[2] = 0; nc.attr.byte[3] = 0; getColumnWidth(nc); // add column width - data.emplace_back(std::move(nc)); + data.emplace_back(nc); } return len; @@ -81,12 +80,12 @@ int FTermBuffer::write (const FString& string) //---------------------------------------------------------------------- int FTermBuffer::write (wchar_t ch) { - FChar nc = FVTerm::getAttribute(); // next character + FChar nc{FVTerm::getAttribute()}; // next character nc.ch[0] = ch; getColumnWidth(nc); // add column width nc.attr.bit.no_changes = false; nc.attr.bit.printed = false; - data.emplace_back(std::move(nc)); + data.emplace_back(nc); return 1; } diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index ae2f712e..863a354f 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -38,6 +38,7 @@ namespace finalcut { // static class attributes +bool FTermcap::initialized {false}; bool FTermcap::background_color_erase {false}; bool FTermcap::can_change_color_palette {false}; bool FTermcap::automatic_left_margin {false}; @@ -50,9 +51,6 @@ bool FTermcap::no_utf8_acs_chars {false}; int FTermcap::max_color {1}; int FTermcap::tabstop {8}; int FTermcap::attr_without_color {0}; -FSystem* FTermcap::fsystem {nullptr}; -FTermData* FTermcap::fterm_data {nullptr}; -FTermDetection* FTermcap::term_detection {nullptr}; char FTermcap::string_buf[2048] {}; //---------------------------------------------------------------------- @@ -72,9 +70,6 @@ char FTermcap::string_buf[2048] {}; //---------------------------------------------------------------------- void FTermcap::init() { - fsystem = FTerm::getFSystem(); - fterm_data = FTerm::getFTermData(); - term_detection = FTerm::getFTermDetection(); termcap(); } @@ -82,11 +77,13 @@ void FTermcap::init() //---------------------------------------------------------------------- void FTermcap::termcap() { + const auto& fterm_data = FTerm::getFTermData(); std::vector terminals{}; static constexpr int success = 1; static constexpr int uninitialized = -2; static char term_buffer[BUF_SIZE]{}; int status = uninitialized; + const auto& term_detection = FTerm::getFTermDetection(); const bool color256 = term_detection->canDisplay256Colors(); // Open termcap file @@ -112,6 +109,9 @@ void FTermcap::termcap() // Open the termcap file + load entry for termtype status = tgetent(term_buffer, termtype); + if ( status == success ) + initialized = true; + if ( status == success || ! term_detection->hasTerminalDetection() ) break; @@ -131,6 +131,7 @@ void FTermcap::termcapError (int status) if ( status == no_entry || status == uninitialized ) { + const auto& fterm_data = FTerm::getFTermData(); const char* termtype = fterm_data->getTermType(); std::clog << FLog::Error << "Unknown terminal: \"" << termtype << "\". " @@ -200,6 +201,8 @@ void FTermcap::termcapNumerics() { // Get termcap numerics + const auto& fterm_data = FTerm::getFTermData(); + // Maximum number of colors on screen max_color = std::max(max_color, getNumber("Co")); @@ -252,9 +255,7 @@ void FTermcap::termcapKeys() //---------------------------------------------------------------------- int FTermcap::_tputs (const char* str, int affcnt, fn_putc putc) { - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); return fsystem->tputs (str, affcnt, putc); } diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index 30c49b2f..b240ea56 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -34,11 +34,6 @@ namespace finalcut { -// static class attributes -FTermData* FTermcapQuirks::fterm_data {nullptr}; -FTermDetection* FTermcapQuirks::term_detection {nullptr}; - - //---------------------------------------------------------------------- // class FTermcapQuirks //---------------------------------------------------------------------- @@ -47,9 +42,7 @@ FTermDetection* FTermcapQuirks::term_detection {nullptr}; //---------------------------------------------------------------------- void FTermcapQuirks::terminalFixup() { - fterm_data = FTerm::getFTermData(); - term_detection = FTerm::getFTermDetection(); - const auto& td = term_detection; + const auto& td = FTerm::getFTermDetection(); if ( td->isCygwinTerminal() ) { @@ -231,7 +224,9 @@ void FTermcapQuirks::xterm() void FTermcapQuirks::rxvt() { // Set enter/exit alternative charset mode for rxvt terminal + const auto& fterm_data = FTerm::getFTermData(); const char* termtype = fterm_data->getTermType(); + const auto& term_detection = FTerm::getFTermDetection(); if ( std::strncmp(termtype, "rxvt-16color", 12) == 0 ) { @@ -252,12 +247,13 @@ void FTermcapQuirks::rxvt() //---------------------------------------------------------------------- void FTermcapQuirks::vte() { + const auto& term_detection = FTerm::getFTermDetection(); + // gnome-terminal has NC=16 however, it can use the dim attribute FTermcap::attr_without_color = 0; // set exit underline for gnome terminal - TCAP(fc::t_exit_underline_mode) = \ - CSI "24m"; + TCAP(fc::t_exit_underline_mode) = CSI "24m"; if ( term_detection->getGnomeTerminalID() >= 5300 ) // vte >= 0.53.0 { @@ -266,8 +262,7 @@ void FTermcapQuirks::vte() { // Save the cursor position, enter alternate screen buffer // and save xterm icon and window title on stack - TCAP(fc::t_enter_ca_mode) = \ - CSI "?1049h" CSI "22;0;0t"; + TCAP(fc::t_enter_ca_mode) = CSI "?1049h" CSI "22;0;0t"; } if ( TCAP(fc::t_exit_ca_mode) @@ -275,8 +270,7 @@ void FTermcapQuirks::vte() { // Use normal screen buffer, restore the cursor position // and restore xterm icon and window title from stack - TCAP(fc::t_exit_ca_mode) = \ - CSI "?1049l" CSI "23;0;0t"; + TCAP(fc::t_exit_ca_mode) = CSI "?1049l" CSI "23;0;0t"; } } } @@ -457,6 +451,8 @@ void FTermcapQuirks::sunConsole() //---------------------------------------------------------------------- void FTermcapQuirks::screen() { + const auto& term_detection = FTerm::getFTermDetection(); + // Fallback if "Ic" is not found if ( ! TCAP(fc::t_initialize_color) ) { diff --git a/src/ftermdebugdata.cpp b/src/ftermdebugdata.cpp index 8ea81d19..b1c468cc 100644 --- a/src/ftermdebugdata.cpp +++ b/src/ftermdebugdata.cpp @@ -30,49 +30,44 @@ namespace finalcut { #if DEBUG -// static class attributes -FTermData* FTermDebugData::data {nullptr}; -FTermDetection* FTermDebugData::term_detection {nullptr}; //---------------------------------------------------------------------- // class FTermDebugData //---------------------------------------------------------------------- // public methods of FTermDebugData -//---------------------------------------------------------------------- -void FTermDebugData::init() -{ - data = FTerm::getFTermData(); - term_detection = FTerm::getFTermDetection(); -} - //---------------------------------------------------------------------- const FString& FTermDebugData::getAnswerbackString() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getAnswerbackString(); } //---------------------------------------------------------------------- const FString& FTermDebugData::getSecDAString() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getSecDAString(); } //---------------------------------------------------------------------- const char* FTermDebugData::getTermType_256color() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getTermType_256color(); } //---------------------------------------------------------------------- const char* FTermDebugData::getTermType_Answerback() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getTermType_Answerback(); } //---------------------------------------------------------------------- const char* FTermDebugData::getTermType_SecDA() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getTermType_SecDA(); } @@ -80,7 +75,8 @@ const char* FTermDebugData::getTermType_SecDA() #if defined(__linux__) int FTermDebugData::getFramebufferBpp() { - return data->getFramebufferBpp(); + const auto& fterm_data = FTerm::getFTermData(); + return fterm_data->getFramebufferBpp(); } #endif // defined(__linux__) diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index 7044e19b..f153f11f 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -54,9 +54,6 @@ namespace finalcut FTermDetection::FTerminalType FTermDetection::terminal_type{}; FTermDetection::colorEnv FTermDetection::color_env{}; FTermDetection::secondaryDA FTermDetection::secondary_da{}; -FTermData* FTermDetection::fterm_data{nullptr}; -FSystem* FTermDetection::fsystem{nullptr}; -FKeyboard* FTermDetection::keyboard{nullptr}; char FTermDetection::termtype[256]{}; char FTermDetection::ttytypename[256]{}; bool FTermDetection::decscusr_support{}; @@ -133,9 +130,6 @@ void FTermDetection::setTtyTypeFileName (const char ttytype_filename[]) //---------------------------------------------------------------------- void FTermDetection::detect() { - fterm_data = FTerm::getFTermData(); - fsystem = FTerm::getFSystem(); - keyboard = FTerm::getFKeyboard(); deallocation(); // Set the variable 'termtype' to the predefined type of the terminal @@ -165,6 +159,7 @@ void FTermDetection::getSystemTermType() { // Import the untrusted environment variable TERM const auto& term_env = std::getenv("TERM"); + const auto& fterm_data = FTerm::getFTermData(); const auto& termfilename = fterm_data->getTermFileName(); if ( term_env ) @@ -203,6 +198,7 @@ bool FTermDetection::getTTYtype() // vt100 ttys0 // Get term basename + const auto& fterm_data = FTerm::getFTermData(); const char* termfilename = fterm_data->getTermFileName(); const char* term_basename = std::strrchr(termfilename, '/'); @@ -213,9 +209,7 @@ bool FTermDetection::getTTYtype() std::FILE* fp{}; std::array str{}; - - if ( ! fsystem ) - return false; + const auto& fsystem = FTerm::getFSystem(); if ( (fp = fsystem->fopen(ttytypename, "r")) == nullptr ) return false; @@ -260,6 +254,7 @@ bool FTermDetection::getTTYSFileEntry() // Analyse /etc/ttys and get the term name // get term basename + const auto& fterm_data = FTerm::getFTermData(); const char* termfilename = fterm_data->getTermFileName(); const char* term_basename = std::strrchr(termfilename, '/'); @@ -364,6 +359,7 @@ void FTermDetection::detectTerminal() if ( terminal_detection ) { FTermios::setCaptureSendCharacters(); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); // Initialize 256 colors terminals @@ -408,6 +404,7 @@ void FTermDetection::detectTerminal() } #if defined(__CYGWIN__) + const auto& fterm_data = FTerm::getFTermData(); const auto& termfilename = fterm_data->getTermFileName(); // Fixes problem with mouse input @@ -541,6 +538,7 @@ const char* FTermDetection::determineMaxColor (const char current_termtype[]) // Determine xterm maximum number of colors via OSC 4 const char* new_termtype = current_termtype; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); if ( ! color256 @@ -632,6 +630,7 @@ FString FTermDetection::getXTermColorName (FColor color) const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[]) { const char* new_termtype = current_termtype; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); // send ENQ and read the answerback message const auto& ans = getAnswerbackMsg(); diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index ee6a08cc..595cc62c 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -30,28 +30,15 @@ #include "final/ftypes.h" #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) -#define initCheck(ret_value) \ - if ( ! isInitialized() ) \ - { \ - if ( ! FApplication::isQuit() ) \ - warnNotInitialized(); \ - \ - return ret_value; \ - } -#endif namespace finalcut { // static class attributes -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - uInt FTermFreeBSD::bsd_alt_keymap{0}; - FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style{fc::normal_cursor}; - bool FTermFreeBSD::change_cursorstyle{true}; - bool FTermFreeBSD::meta_sends_escape{true}; - FSystem* FTermFreeBSD::fsystem{nullptr}; - FTermData* FTermFreeBSD::fterm_data{nullptr}; -#endif +uInt FTermFreeBSD::bsd_alt_keymap{0}; +FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style{fc::normal_cursor}; +bool FTermFreeBSD::change_cursorstyle{true}; +bool FTermFreeBSD::meta_sends_escape{true}; //---------------------------------------------------------------------- @@ -60,7 +47,6 @@ namespace finalcut // public methods of FTermFreeBSD //---------------------------------------------------------------------- -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) FTermFreeBSD::CursorStyle FTermFreeBSD::getCursorStyle() { return cursor_style; @@ -71,15 +57,11 @@ bool FTermFreeBSD::setCursorStyle (CursorStyle style) { // Set cursor style in a BSD console - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - - initCheck(false); - - if ( ! fsystem || ! isFreeBSDConsole() || ! change_cursorstyle ) + if ( ! isFreeBSDConsole() || ! change_cursorstyle ) return false; cursor_style = style; + const auto& fterm_data = FTerm::getFTermData(); if ( fterm_data->isCursorHidden() ) return false; @@ -93,11 +75,9 @@ bool FTermFreeBSD::isFreeBSDConsole() // Check if it's a FreeBSD console keymap_t keymap{}; + const auto& fsystem = FTerm::getFSystem(); - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - - if ( fsystem && fsystem->ioctl(0, GIO_KEYMAP, &keymap) == 0 ) + if ( fsystem->ioctl(0, GIO_KEYMAP, &keymap) == 0 ) return true; else return false; @@ -141,9 +121,6 @@ void FTermFreeBSD::init() { // Initialize BSD console - fsystem = FTerm::getFSystem(); - fterm_data = FTerm::getFTermData(); - if ( ! isFreeBSDConsole() ) return; @@ -210,7 +187,7 @@ bool FTermFreeBSD::saveFreeBSDAltKey() static constexpr int left_alt = 0x38; int ret{-1}; keymap_t keymap{}; - initCheck(false); + const auto& fsystem = FTerm::getFSystem(); ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); if ( ret < 0 ) @@ -229,7 +206,7 @@ bool FTermFreeBSD::setFreeBSDAltKey (uInt key) static constexpr int left_alt = 0x38; int ret{-1}; keymap_t keymap{}; - initCheck(false); + const auto& fsystem = FTerm::getFSystem(); ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); if ( ret < 0 ) @@ -239,7 +216,7 @@ bool FTermFreeBSD::setFreeBSDAltKey (uInt key) keymap.key[left_alt].map[0] = int(key); if ( (keymap.n_keys > 0) - && fsystem && (fsystem->ioctl(0, PIO_KEYMAP, &keymap) < 0) ) + && (fsystem->ioctl(0, PIO_KEYMAP, &keymap) < 0) ) return false; else return true; @@ -264,13 +241,14 @@ bool FTermFreeBSD::resetFreeBSDAlt2Meta() //---------------------------------------------------------------------- bool FTermFreeBSD::setFreeBSDCursorStyle (CursorStyle style) { - initCheck(false); + const auto& fsystem = FTerm::getFSystem(); if ( fsystem->ioctl(0, CONS_CURSORTYPE, &style) == 0 ) return true; else return false; } -#endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) } // namespace finalcut + +#endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 8667260d..27fbd1e1 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -35,11 +35,12 @@ #include "final/ftypes.h" #if defined(__linux__) - #include // need keyboard modifiers - #include "../fonts/newfont.h" - #include "../fonts/unicodemap.h" - #include "../fonts/vgafont.h" -#endif + +#include // need keyboard modifiers +#include "../fonts/newfont.h" +#include "../fonts/unicodemap.h" +#include "../fonts/vgafont.h" + namespace finalcut { @@ -52,18 +53,15 @@ namespace finalcut //---------------------------------------------------------------------- FTermLinux::~FTermLinux() // destructor { -#if defined(__linux__) if ( screen_font.data ) delete[] screen_font.data; if ( screen_unicode_map.entries ) delete[] screen_unicode_map.entries; -#endif // defined(__linux__) } // public methods of FTermLinux //---------------------------------------------------------------------- -#if defined(__linux__) fc::linuxConsoleCursorStyle FTermLinux::getCursorStyle() const { // Get the current set cursor style @@ -87,8 +85,7 @@ bool FTermLinux::setCursorStyle (fc::linuxConsoleCursorStyle style) { // Set cursor style in linux console - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); + const auto& fterm_data = FTerm::getFTermData(); if ( ! FTerm::isLinuxTerm() ) return false; @@ -137,11 +134,9 @@ bool FTermLinux::isLinuxConsole() { // Check if it's a Linux console - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - char arg{0}; const int fd_tty = FTerm::getTTYFileDescriptor(); + const auto& fsystem = FTerm::getFSystem(); // Get keyboard type an compare return ( fsystem->isTTY(fd_tty) @@ -154,14 +149,8 @@ void FTermLinux::init() { // Initialize Linux console - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - - fsystem = FTerm::getFSystem(); - term_detection = FTerm::getFTermDetection(); + const auto& fterm_data = FTerm::getFTermData(); + const auto& term_detection = FTerm::getFTermDetection(); screen_unicode_map.entries = nullptr; screen_font.data = nullptr; fterm_data->supportShadowCharacter (true); @@ -292,9 +281,7 @@ bool FTermLinux::loadVGAFont() if ( vga_font ) { - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - + const auto& fterm_data = FTerm::getFTermData(); fterm_data->supportShadowCharacter (true); fterm_data->supportHalfBlockCharacter (true); } @@ -342,9 +329,7 @@ bool FTermLinux::loadNewFont() if ( new_font ) { - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - + const auto& fterm_data = FTerm::getFTermData(); fterm_data->supportShadowCharacter (true); fterm_data->supportHalfBlockCharacter (true); } @@ -458,9 +443,6 @@ FKey FTermLinux::modifierKeyCorrection (const FKey& key_id) { // Get the current modifier key state - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - const ModifierKey& m = getModifierKey(); if ( ! (m.shift || m.ctrl || m.alt) ) @@ -508,9 +490,7 @@ int FTermLinux::getFramebuffer_bpp() const char* fb = "/dev/fb/0"; struct fb_var_screeninfo fb_var{}; struct fb_fix_screeninfo fb_fix{}; - - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); if ( (fd = fsystem->open(fb, O_RDWR)) < 0 ) { @@ -569,8 +549,8 @@ bool FTermLinux::getScreenFont() } // Font operation - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); if ( ret != 0 ) { @@ -600,8 +580,8 @@ bool FTermLinux::getUnicodeMap() screen_unicode_map.entries = nullptr; // Get count - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); if ( ret != 0 ) { @@ -621,8 +601,7 @@ bool FTermLinux::getUnicodeMap() } // Get unicode-to-font mapping from kernel - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); + ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); if ( ret != 0 ) return false; @@ -641,8 +620,10 @@ FTermLinux::ModifierKey& FTermLinux::getModifierKey() // Fill bit field with 0 std::memset (&mod_key, 0x00, sizeof(mod_key)); + const auto& fsystem = FTerm::getFSystem(); + // TIOCLINUX, subcode = 6 (TIOCL_GETSHIFTSTATE) - if ( fsystem && fsystem->ioctl(0, TIOCLINUX, &subcode) >= 0 ) + if ( fsystem->ioctl(0, TIOCLINUX, &subcode) >= 0 ) { if ( subcode & (1 << KG_SHIFT) ) mod_key.shift = true; @@ -705,8 +686,8 @@ int FTermLinux::setScreenFont ( const uChar fontdata[], uInt count } // Font operation - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); if ( ret != 0 && errno != ENOSYS && errno != EINVAL ) { @@ -742,15 +723,14 @@ int FTermLinux::setUnicodeMap (struct unimapdesc* unimap) do { // Clear the unicode-to-font table - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, PIO_UNIMAPCLR, &advice); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, PIO_UNIMAPCLR, &advice); if ( ret != 0 ) return -1; // Put the new unicode-to-font mapping in kernel - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, PIO_UNIMAP, unimap); + ret = fsystem->ioctl (fd_tty, PIO_UNIMAP, unimap); if ( ret != 0 ) advice.advised_hashlevel++; @@ -775,8 +755,7 @@ inline uInt16 FTermLinux::getInputStatusRegisterOne() { // Gets the VGA input-status-register-1 - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); // Miscellaneous output (read port) static constexpr uInt16 misc_read = 0x3cc; @@ -792,8 +771,7 @@ uChar FTermLinux::readAttributeController (uChar index) { // Reads a byte from the attribute controller from a given index - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); // Attribute controller (write port) static constexpr uInt16 attrib_cntlr_write = 0x3c0; @@ -819,8 +797,7 @@ void FTermLinux::writeAttributeController (uChar index, uChar data) { // Writes a byte from the attribute controller from a given index - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); // Attribute controller (write port) static constexpr uInt16 attrib_cntlr_write = 0x3c0; @@ -859,8 +836,7 @@ int FTermLinux::setBlinkAsIntensity (bool enable) // Uses blink-bit as background intensity. // That permits 16 colors for background - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); const int fd_tty = FTerm::getTTYFileDescriptor(); @@ -899,9 +875,7 @@ bool FTermLinux::has9BitCharacters() // 0xc0...0xdf - copying the eighth pixel into the ninth pixel // The rest - the ninth pixel has the background color - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); const int fd_tty = FTerm::getTTYFileDescriptor(); if ( fsystem->getuid() != 0 ) // Direct hardware access requires root privileges @@ -926,7 +900,9 @@ bool FTermLinux::has9BitCharacters() //---------------------------------------------------------------------- void FTermLinux::getVGAPalette() { - if ( fsystem && fsystem->ioctl(0, GIO_CMAP, &cmap) != 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, GIO_CMAP, &cmap) != 0 ) setVGADefaultPalette(); // Fallback, if GIO_CMAP does not work } @@ -967,7 +943,9 @@ bool FTermLinux::setVGAPalette (FColor index, int r, int g, int b) cmap.color[index].blue = uChar(b); } - if ( fsystem && fsystem->ioctl(0, PIO_CMAP, &cmap) == 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, PIO_CMAP, &cmap) == 0 ) return true; else return false; @@ -978,7 +956,9 @@ bool FTermLinux::saveVGAPalette() { // Save the current vga color map - if ( fsystem && fsystem->ioctl(0, GIO_CMAP, &saved_color_map) == 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, GIO_CMAP, &saved_color_map) == 0 ) has_saved_palette = true; else has_saved_palette = false; @@ -991,16 +971,18 @@ bool FTermLinux::resetVGAPalette() { // Reset the vga color map + const auto& fsystem = FTerm::getFSystem(); + if ( has_saved_palette ) { - if ( fsystem && fsystem->ioctl (0, PIO_CMAP, &saved_color_map) ) + if ( fsystem->ioctl (0, PIO_CMAP, &saved_color_map) ) return false; } else { setVGADefaultPalette(); - if ( fsystem && fsystem->ioctl(0, PIO_CMAP, &cmap) != 0 ) + if ( fsystem->ioctl(0, PIO_CMAP, &cmap) != 0 ) return false; } @@ -1291,13 +1273,11 @@ FKey FTermLinux::shiftCtrlAltKeyCorrection (const FKey& key_id) const //---------------------------------------------------------------------- inline void FTermLinux::initSpecialCharacter() { + const auto& fterm_data = FTerm::getFTermData(); const wchar_t c1 = fc::UpperHalfBlock; const wchar_t c2 = fc::LowerHalfBlock; const wchar_t c3 = fc::FullBlock; - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - if ( FTerm::charEncode(c1, fc::PC) == FTerm::charEncode(c1, fc::ASCII) || FTerm::charEncode(c2, fc::PC) == FTerm::charEncode(c2, fc::ASCII) || FTerm::charEncode(c3, fc::PC) == FTerm::charEncode(c3, fc::ASCII) ) @@ -1334,10 +1314,7 @@ void FTermLinux::characterFallback ( wchar_t ucs , std::vector fallback ) { constexpr sInt16 NOT_FOUND = -1; - - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - + const auto& fterm_data = FTerm::getFTermData(); charSubstitution& sub_map = fterm_data->getCharSubstitutionMap(); if ( fallback.size() < 2 || ucs != fallback[0] ) @@ -1355,6 +1332,6 @@ void FTermLinux::characterFallback ( wchar_t ucs } } -#endif // defined(__linux__) - } // namespace finalcut + +#endif // defined(__linux__) diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 0b2fda5d..d10ed9f6 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -27,25 +27,13 @@ #include "final/ftermopenbsd.h" #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) -#define initCheck(ret_value) \ - if ( ! isInitialized() ) \ - { \ - if ( ! FApplication::isQuit() ) \ - warnNotInitialized(); \ - \ - return ret_value; \ - } -#endif namespace finalcut { // static class attributes -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - kbd_t FTermOpenBSD::bsd_keyboard_encoding{0}; - bool FTermOpenBSD::meta_sends_escape{true}; - FSystem* FTermOpenBSD::fsystem{nullptr}; -#endif +kbd_t FTermOpenBSD::bsd_keyboard_encoding{0}; +bool FTermOpenBSD::meta_sends_escape{true}; //---------------------------------------------------------------------- @@ -54,18 +42,14 @@ namespace finalcut // public methods of FTermOpenBSD //---------------------------------------------------------------------- -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) bool FTermOpenBSD::isBSDConsole() { // Check if it's a NetBSD/OpenBSD workstation console static kbd_t kbdencoding{}; + const auto& fsystem = FTerm::getFSystem(); - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 ) + if ( fsystem->ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 ) return true; else return false; @@ -76,8 +60,6 @@ void FTermOpenBSD::init() { // Initialize BSD workstation console - fsystem = FTerm::getFSystem(); - if ( ! isBSDConsole() ) return; @@ -94,8 +76,6 @@ void FTermOpenBSD::init() //---------------------------------------------------------------------- void FTermOpenBSD::finish() { - initCheck(); - if ( ! isBSDConsole() ) return; @@ -106,8 +86,6 @@ void FTermOpenBSD::finish() //---------------------------------------------------------------------- bool FTermOpenBSD::setBeep (int Hz, int ms) { - initCheck(false); - if ( ! isBSDConsole() ) return false; @@ -124,8 +102,9 @@ bool FTermOpenBSD::setBeep (int Hz, int ms) bell.pitch = uInt(Hz); bell.period = uInt(ms); bell.volume = 50; // 50% volume + const auto& fsystem = FTerm::getFSystem(); - if ( fsystem && fsystem->ioctl(0, WSKBDIO_SETBELL, &bell) < 0 ) + if ( fsystem->ioctl(0, WSKBDIO_SETBELL, &bell) < 0 ) return false; else return true; @@ -134,19 +113,17 @@ bool FTermOpenBSD::setBeep (int Hz, int ms) //---------------------------------------------------------------------- bool FTermOpenBSD::resetBeep() { - initCheck(false); wskbd_bell_data default_bell; + const auto& fsystem = FTerm::getFSystem(); // Gets the default setting for the bell - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_GETDEFAULTBELL, &default_bell) < 0 ) + if ( fsystem->ioctl(0, WSKBDIO_GETDEFAULTBELL, &default_bell) < 0 ) return false; default_bell.which = WSKBD_BELL_DOALL; // Sets the bell settings - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_SETBELL, &default_bell) < 0 ) + if ( fsystem->ioctl(0, WSKBDIO_SETBELL, &default_bell) < 0 ) return false; else return true; @@ -170,8 +147,8 @@ bool FTermOpenBSD::saveBSDConsoleEncoding() static kbd_t k_encoding{}; int ret{-1}; - if ( fsystem ) - ret = fsystem->ioctl (0, WSKBDIO_GETENCODING, &k_encoding); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (0, WSKBDIO_GETENCODING, &k_encoding); if ( ret < 0 ) return false; @@ -184,8 +161,9 @@ bool FTermOpenBSD::saveBSDConsoleEncoding() //---------------------------------------------------------------------- bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding) { - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) return false; else return true; @@ -204,6 +182,7 @@ bool FTermOpenBSD::resetBSDConsoleEncoding() { return setBSDConsoleEncoding (bsd_keyboard_encoding); } -#endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) } // namespace finalcut + +#endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 54d67158..3899fcad 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -39,38 +39,17 @@ #include "final/ftermxterminal.h" #include "final/fsize.h" -#define initCheck(ret_value) \ - if ( ! isInitialized() ) \ - { \ - if ( ! FApplication::isQuit() ) \ - warnNotInitialized(); \ - \ - return ret_value; \ - } - namespace finalcut { // static class attributes bool FTermXTerminal::mouse_support{false}; -FSystem* FTermXTerminal::fsystem{nullptr}; -FKeyboard* FTermXTerminal::keyboard{nullptr}; //---------------------------------------------------------------------- // class FTermXTerminal //---------------------------------------------------------------------- -// constructors and destructor -//---------------------------------------------------------------------- -FTermXTerminal::FTermXTerminal() -{ - // Get FSystem object - fsystem = FTerm::getFSystem(); - keyboard = FTerm::getFKeyboard(); -} - - // public methods of FTermXTerminal //---------------------------------------------------------------------- void FTermXTerminal::setCursorStyle (fc::xtermCursorStyle style) @@ -185,12 +164,6 @@ void FTermXTerminal::metaSendsESC (bool enable) disableXTermMetaSendsESC(); } -//---------------------------------------------------------------------- -void FTermXTerminal::init() -{ - term_detection = FTerm::getFTermDetection(); -} - //---------------------------------------------------------------------- void FTermXTerminal::setDefaults() { @@ -268,7 +241,7 @@ void FTermXTerminal::resetHighlightBackground() //---------------------------------------------------------------------- void FTermXTerminal::resetDefaults() { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isPuttyTerminal() ) return; @@ -301,13 +274,14 @@ void FTermXTerminal::resetTitle() //---------------------------------------------------------------------- void FTermXTerminal::captureFontAndTitle() { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( ( term_detection->isXTerminal() || term_detection->isUrxvtTerminal() ) && ! term_detection->isRxvtTerminal() ) { FTermios::setCaptureSendCharacters(); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); xterm_font = captureXTermFont(); xterm_title = captureXTermTitle(); @@ -338,7 +312,7 @@ void FTermXTerminal::setXTermCursorStyle() return; #endif - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isGnomeTerminal() && ! term_detection->hasSetCursorStyleSupport() ) @@ -362,7 +336,7 @@ void FTermXTerminal::setXTermCursorStyle() void FTermXTerminal::setXTermTitle() { // Set the xterm title - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -387,7 +361,7 @@ void FTermXTerminal::setXTermTitle() //---------------------------------------------------------------------- void FTermXTerminal::setXTermSize() const { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() ) { @@ -403,7 +377,7 @@ void FTermXTerminal::setXTermFont() { // Change the XTerm font (needs the allowFontOps resource) - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -421,7 +395,7 @@ void FTermXTerminal::setXTermForeground() { // Set the XTerm text foreground color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -441,7 +415,7 @@ void FTermXTerminal::setXTermBackground() { // Set the XTerm text background color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -461,7 +435,7 @@ void FTermXTerminal::setXTermCursorColor() { // Set the text cursor color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -481,7 +455,7 @@ void FTermXTerminal::setXTermMouseForeground() { // Set the mouse foreground color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -500,7 +474,7 @@ void FTermXTerminal::setXTermMouseBackground() { // Set the mouse background color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -518,7 +492,7 @@ void FTermXTerminal::setXTermHighlightBackground() { // Set the highlight background color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -538,7 +512,7 @@ void FTermXTerminal::setXTerm8ColorDefaults() // Redefinition of the XTerm default colors // for the final cut 8 color theme - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isPuttyTerminal() ) return; @@ -560,7 +534,7 @@ void FTermXTerminal::setXTerm16ColorDefaults() // Redefinition of the XTerm default colors // for the final cut 16 color theme - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isPuttyTerminal() ) return; @@ -582,7 +556,7 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor() setMouseBackground("rgb:ffff/ffff/ffff"); // white setMouseForeground ("rgb:0000/0000/0000"); // black - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( ! term_detection->isGnomeTerminal() ) setCursorColor("rgb:ffff/ffff/ffff"); // white @@ -591,7 +565,7 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor() //---------------------------------------------------------------------- inline bool FTermXTerminal::canSetXTermBackground() const { - initCheck(false); + const auto& term_detection = FTerm::getFTermDetection(); if ( xterm_default_colors && ! (term_detection->isMinttyTerm() @@ -608,7 +582,7 @@ void FTermXTerminal::resetXTermColorMap() const { // Reset the entire color table - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isMinttyTerm() ) { @@ -710,7 +684,7 @@ void FTermXTerminal::resetXTermHighlightBackground() const //---------------------------------------------------------------------- bool FTermXTerminal::canResetColor() const { - initCheck(false); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) @@ -731,7 +705,7 @@ bool FTermXTerminal::canResetColor() const //---------------------------------------------------------------------- void FTermXTerminal::oscPrefix() const { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isTmuxTerm() ) { @@ -748,7 +722,7 @@ void FTermXTerminal::oscPrefix() const //---------------------------------------------------------------------- void FTermXTerminal::oscPostfix() const { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isScreenTerm() || term_detection->isTmuxTerm() ) @@ -761,7 +735,7 @@ void FTermXTerminal::oscPostfix() const //---------------------------------------------------------------------- FString FTermXTerminal::captureXTermFont() const { - initCheck(FString{}); + const auto& term_detection = FTerm::getFTermDetection(); if ( ! term_detection->isXTerminal() && ! term_detection->isScreenTerm() @@ -823,7 +797,7 @@ FString FTermXTerminal::captureXTermFont() const //---------------------------------------------------------------------- FString FTermXTerminal::captureXTermTitle() const { - initCheck(FString{}); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isKdeTerminal() ) return FString{}; @@ -887,9 +861,6 @@ void FTermXTerminal::enableXTermMouse() if ( mouse_support ) return; // The mouse is already activated - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - FTerm::putstring (CSI "?1001s" // save old highlight mouse tracking CSI "?1000;" // enable x11 mouse tracking "1002;" // enable cell motion mouse tracking diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 3d9d56c6..8d997ec0 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -402,7 +402,7 @@ void FToggleButton::drawLabel() FString label_text{}; auto hotkeypos = finalcut::getHotkeyPos(txt, label_text); print() << FPoint{1 + int(label_offset_pos), 1}; - drawText (std::move(label_text), hotkeypos); + drawText (label_text, hotkeypos); } //---------------------------------------------------------------------- @@ -485,7 +485,7 @@ void FToggleButton::init() } //---------------------------------------------------------------------- -void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos) +void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos) { if ( FTerm::isMonochron() ) setReverse(true); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index e7eddb2a..a1bafe16 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -68,12 +68,10 @@ struct timeval FVTerm::last_term_size_check{}; std::vector* FVTerm::output_buffer{nullptr}; FPoint* FVTerm::term_pos{nullptr}; const FVTerm* FVTerm::init_object{nullptr}; -FSystem* FVTerm::fsystem{nullptr}; FTerm* FVTerm::fterm{nullptr}; FVTerm::FTermArea* FVTerm::vterm{nullptr}; FVTerm::FTermArea* FVTerm::vdesktop{nullptr}; FVTerm::FTermArea* FVTerm::active_area{nullptr}; -FMouseControl* FVTerm::mouse{nullptr}; FChar FVTerm::term_attribute{}; FChar FVTerm::next_attribute{}; FChar FVTerm::s_ch{}; @@ -276,6 +274,7 @@ bool FVTerm::updateTerminal() const // Check if terminal updates were stopped, application is stopping, // VTerm has no changes, or the drawing is not completed if ( no_terminal_updates || FApplication::isQuit() + || ! isFlushTimeout() || ! (hasPendingUpdates(vterm) && draw_completed) ) { return false; @@ -308,7 +307,7 @@ void FVTerm::addPreprocessingHandler ( const FVTerm* instance { FVTermPreprocessing obj{ instance, function }; delPreprocessingHandler (instance); - print_area->preproc_list.push_back(obj); + print_area->preproc_list.emplace_back(std::move(obj)); } } @@ -325,8 +324,8 @@ void FVTerm::delPreprocessingHandler (const FVTerm* instance) while ( iter != print_area->preproc_list.end() ) { - if ( iter->instance == instance ) - iter = print_area->preproc_list.erase(iter); + if ( iter->instance.get() == instance ) + iter = std::move(print_area->preproc_list.erase(iter)); else ++iter; } @@ -590,6 +589,7 @@ void FVTerm::flush() output_buffer->clear(); std::fflush(stdout); + const auto& mouse = FTerm::getFMouseControl(); mouse->drawPointer(); FObject::getCurrentTime (&time_last_flush); } @@ -1278,15 +1278,12 @@ void FVTerm::initTerminal() if ( fterm ) fterm->initTerminal(); - // Get the global FMouseControl object - mouse = FTerm::getFMouseControl(); - // Hide the input cursor cursor_hideable = FTerm::isCursorHideable(); hideCursor(); // Initialize character lengths - init_characterLengths(FTerm::getFOptiMove()); + init_characterLengths(); } @@ -1812,7 +1809,6 @@ void FVTerm::init() init_object = this; vterm = nullptr; vdesktop = nullptr; - fsystem = FTerm::getFSystem(); try { @@ -1863,24 +1859,29 @@ void FVTerm::init() } //---------------------------------------------------------------------- -void FVTerm::init_characterLengths (const FOptiMove* optimove) +void FVTerm::init_characterLengths() { - if ( optimove ) - { - cursor_address_length = optimove->getCursorAddressLength(); - erase_char_length = optimove->getEraseCharsLength(); - repeat_char_length = optimove->getRepeatCharLength(); - clr_bol_length = optimove->getClrBolLength(); - clr_eol_length = optimove->getClrEolLength(); - } - else - { + const auto& opti_move = FTerm::getFOptiMove(); + cursor_address_length = opti_move->getCursorAddressLength(); + erase_char_length = opti_move->getEraseCharsLength(); + repeat_char_length = opti_move->getRepeatCharLength(); + clr_bol_length = opti_move->getClrBolLength(); + clr_eol_length = opti_move->getClrEolLength(); + + if ( cursor_address_length == 0 ) cursor_address_length = INT_MAX; - erase_char_length = INT_MAX; - repeat_char_length = INT_MAX; - clr_bol_length = INT_MAX; - clr_eol_length = INT_MAX; - } + + if ( erase_char_length == 0 ) + erase_char_length = INT_MAX; + + if ( repeat_char_length == 0 ) + repeat_char_length = INT_MAX; + + if ( clr_bol_length == 0 ) + clr_bol_length = INT_MAX; + + if ( clr_eol_length == 0 ) + clr_eol_length = INT_MAX; } //---------------------------------------------------------------------- diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 82751c01..4317d63b 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -85,9 +85,9 @@ FWidget::FWidget (FWidget* parent) { if ( internal::var::root_widget ) { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage("FWidget: No parent defined! " - "There should be only one root object"); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage("FWidget: No parent defined! " + "There should be only one root object"); FApplication::exit(EXIT_FAILURE); return; } diff --git a/src/fwidgetcolors.cpp b/src/fwidgetcolors.cpp index 53c75a12..8a55417a 100644 --- a/src/fwidgetcolors.cpp +++ b/src/fwidgetcolors.cpp @@ -33,12 +33,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FWidgetColors::FWidgetColors() -{ } - -//---------------------------------------------------------------------- -FWidgetColors::~FWidgetColors() -{ } +FWidgetColors::~FWidgetColors() noexcept = default; //---------------------------------------------------------------------- @@ -53,8 +48,8 @@ default8ColorTheme::default8ColorTheme() } //---------------------------------------------------------------------- -default8ColorTheme::~default8ColorTheme() -{ } +default8ColorTheme::~default8ColorTheme() noexcept = default; + // public methods of default8ColorTheme //---------------------------------------------------------------------- @@ -161,8 +156,8 @@ default16ColorTheme::default16ColorTheme() } //---------------------------------------------------------------------- -default16ColorTheme::~default16ColorTheme() -{ } +default16ColorTheme::~default16ColorTheme() noexcept = default; + // public methods of default16ColorTheme //---------------------------------------------------------------------- @@ -271,8 +266,8 @@ default8ColorDarkTheme::default8ColorDarkTheme() } //---------------------------------------------------------------------- -default8ColorDarkTheme::~default8ColorDarkTheme() -{ } +default8ColorDarkTheme::~default8ColorDarkTheme() noexcept = default; + // public methods of default8ColorDarkTheme //---------------------------------------------------------------------- @@ -379,8 +374,8 @@ default16ColorDarkTheme::default16ColorDarkTheme() } //---------------------------------------------------------------------- -default16ColorDarkTheme::~default16ColorDarkTheme() -{ } +default16ColorDarkTheme::~default16ColorDarkTheme() noexcept = default; + // public methods of default16ColorDarkTheme //---------------------------------------------------------------------- diff --git a/src/include/final/emptyfstring.h b/src/include/final/emptyfstring.h index c6ab6f97..33bf5007 100644 --- a/src/include/final/emptyfstring.h +++ b/src/include/final/emptyfstring.h @@ -52,62 +52,28 @@ namespace fc class emptyFString final { -public: - // Constructors - emptyFString() = delete; + public: + // Constructors + emptyFString() = delete; - // Disable copy constructor - emptyFString (const emptyFString&) = delete; + // Disable copy constructor + emptyFString (const emptyFString&) = delete; - // Disable copy assignment operator (=) - emptyFString& operator = (const emptyFString&) = delete; + // Disable copy assignment operator (=) + emptyFString& operator = (const emptyFString&) = delete; - static FString getClassName(); - static bool isNull(); - static const FString& get(); - static void clear(); + static FString getClassName() + { + return "emptyFString"; + } -private: - // Data member - static const FString* empty_string; + static const FString& get() + { + static const auto& empty_string = make_unique(""); + return *empty_string.get(); + } }; -// emptyFString inline functions -//---------------------------------------------------------------------- -inline FString emptyFString::getClassName() -{ return "emptyFString"; } - -//---------------------------------------------------------------------- -inline bool emptyFString::isNull() -{ - return ( empty_string ) ? false : true; -} - -//---------------------------------------------------------------------- -inline const FString& emptyFString::get() -{ - if ( ! empty_string ) - { - try - { - empty_string = new FString(""); - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FString"); - } - } - - return *empty_string; -} - -//---------------------------------------------------------------------- -inline void emptyFString::clear() -{ - delete empty_string; - empty_string = nullptr; -} - } // namespace fc } // namespace finalcut diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 79ba0bc5..733a7ade 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -86,7 +86,6 @@ class FStartOptions; class FTimerEvent; class FWheelEvent; class FMouseControl; -class FKeyboard; class FPoint; class FObject; @@ -98,7 +97,7 @@ class FApplication : public FWidget { public: // Typedef - typedef std::shared_ptr FLogPtr; + using FLogPtr = std::shared_ptr; // Constructor FApplication (const int&, char*[]); @@ -164,9 +163,9 @@ class FApplication : public FWidget #endif // Typedefs - typedef std::pair EventPair; - typedef std::deque FEventQueue; - typedef std::unordered_map> CmdMap; + using EventPair = std::pair; + using FEventQueue = std::deque; + using CmdMap = std::unordered_map>; // Methods void init(); @@ -244,8 +243,6 @@ class FApplication : public FWidget static int loop_level; static int quit_code; static bool quit_now; - static FMouseControl* mouse; - static FKeyboard* keyboard; static FWidget* keyboard_widget; }; diff --git a/src/include/final/fbusyindicator.h b/src/include/final/fbusyindicator.h index 00babea3..6cc9843a 100644 --- a/src/include/final/fbusyindicator.h +++ b/src/include/final/fbusyindicator.h @@ -76,7 +76,7 @@ class FBusyIndicator : public FToolTip FBusyIndicator (const FBusyIndicator&) = delete; // Destructor - ~FBusyIndicator() override; + ~FBusyIndicator() noexcept override; // Disable copy assignment operator (=) FBusyIndicator& operator = (const FBusyIndicator&) = delete; diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index a6731a6b..d2c59f0c 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -126,7 +126,7 @@ class FButtonGroup : public FScrollView // Methods void init(); - void drawText (FString&&, std::size_t); + void drawText (const FString&, std::size_t); bool directFocusCheckedRadioButton (FToggleButton*) const; bool directFocusRadioButton() const; void directFocus(); diff --git a/src/include/final/fcallback.h b/src/include/final/fcallback.h index 32de081b..a493a13b 100644 --- a/src/include/final/fcallback.h +++ b/src/include/final/fcallback.h @@ -135,13 +135,13 @@ class FCallback , std::nullptr_t >; // Constructors - FCallback(); + FCallback() = default; // Disable copy constructor FCallback (const FCallback&) = delete; // Destructor - ~FCallback(); + ~FCallback() noexcept = default; // Disable copy assignment operator (=) FCallback& operator = (const FCallback&) = delete; diff --git a/src/include/final/fcolorpalette.h b/src/include/final/fcolorpalette.h index ed22b4f1..63387705 100644 --- a/src/include/final/fcolorpalette.h +++ b/src/include/final/fcolorpalette.h @@ -56,7 +56,7 @@ class FColorPalette explicit FColorPalette (const FSetPalette&); // Destructor - virtual ~FColorPalette(); + virtual ~FColorPalette() noexcept; // Accessor virtual FString getClassName() const; @@ -104,7 +104,7 @@ class default8ColorPalette final : public FColorPalette explicit default8ColorPalette (const FSetPalette&); // Destructor - ~default8ColorPalette() override; + ~default8ColorPalette() noexcept override; // Accessor FString getClassName() const override; @@ -144,7 +144,7 @@ class default16ColorPalette final : public FColorPalette explicit default16ColorPalette (const FSetPalette&); // Destructor - ~default16ColorPalette() override; + ~default16ColorPalette() noexcept override; // Accessor FString getClassName() const override; @@ -183,7 +183,7 @@ class default16DarkColorPalette final : public FColorPalette explicit default16DarkColorPalette (const FSetPalette&); // Destructor - ~default16DarkColorPalette() override; + ~default16DarkColorPalette() noexcept override; // Accessor FString getClassName() const override; diff --git a/src/include/final/fdata.h b/src/include/final/fdata.h index 9b47169d..15d8a823 100644 --- a/src/include/final/fdata.h +++ b/src/include/final/fdata.h @@ -118,10 +118,10 @@ class FDataAccess { public: // Constructor - FDataAccess(); + FDataAccess() = default; // Destructor - virtual ~FDataAccess(); + virtual ~FDataAccess() noexcept; // Accessors virtual FString getClassName() const @@ -166,8 +166,7 @@ class FData : public FDataAccess { } // Destructor - ~FData() override - { } + ~FData() noexcept override = default; FData (const FData& d) // Copy constructor : value{d.value} diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index fd4ea073..4916ac44 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -195,7 +195,7 @@ class FDialog : public FWindow void pressZoomButton (const MouseStates&); bool isMouseOverMenu (const FPoint&) const; void passEventToSubMenu ( const MouseStates& - , const FMouseEvent&& ); + , const FMouseEvent& ); void moveSizeKey (FKeyEvent*); void raiseActivateDialog(); void lowerActivateDialog(); diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index 04e366e6..aa6acda5 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -80,9 +80,6 @@ namespace finalcut { -// class forward declaration -class FSystem; - //---------------------------------------------------------------------- // class FFileDialog //---------------------------------------------------------------------- @@ -214,7 +211,6 @@ class FFileDialog : public FDialog void cb_processShowHidden(); // Data members - static FSystem* fsystem; DIR* directory_stream{nullptr}; DirEntries dir_entries{}; FString directory{}; diff --git a/src/include/final/fkeyboard.h b/src/include/final/fkeyboard.h index 7ac7b1b5..bf86002d 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -52,8 +52,6 @@ namespace finalcut // class forward declaration class FApplication; class FString; -class FTermDetection; -class FTermLinux; //---------------------------------------------------------------------- // class FKeyboardCommand @@ -137,7 +135,6 @@ class FKeyboard final bool hasDataInQueue() const; // Methods - static void init(); bool& hasUnprocessedInput(); bool isKeyPressed (uInt64 = read_blocking_time); void clearKeyBuffer(); @@ -182,12 +179,6 @@ class FKeyboard final FKeyboardCommand escape_key_cmd{}; FKeyboardCommand mouse_tracking_cmd{}; -#if defined(__linux__) - #undef linux - static FTermLinux* linux; -#endif - - FTermDetection* term_detection{nullptr}; static timeval time_keypressed; static uInt64 read_blocking_time; static uInt64 read_blocking_time_short; diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index fe164f88..7db08aa4 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -221,8 +221,13 @@ class FListViewIterator // Constructor FListViewIterator () = default; FListViewIterator (iterator); - + FListViewIterator (const FListViewIterator&) = default; + FListViewIterator (FListViewIterator&& ) + noexcept (std::is_nothrow_move_constructible::value) + = default; // Overloaded operators + FListViewIterator& operator = (const FListViewIterator&) = default; + FListViewIterator& operator = (FListViewIterator&&) noexcept = default; FListViewIterator& operator ++ (); // prefix FListViewIterator operator ++ (int); // postfix FListViewIterator& operator -- (); // prefix diff --git a/src/include/final/flog.h b/src/include/final/flog.h index e5d46e0d..61cab79f 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -75,7 +75,7 @@ class FLog : public std::stringbuf }; // Constructor - FLog(); + FLog() = default; // Destructor ~FLog() override; diff --git a/src/include/final/flogger.h b/src/include/final/flogger.h index d5caff76..cb722877 100644 --- a/src/include/final/flogger.h +++ b/src/include/final/flogger.h @@ -66,10 +66,10 @@ class FLogger : public FLog { public: // Constructor - FLogger(); + FLogger() = default; // Destructor - ~FLogger() override; + ~FLogger() noexcept override; // Methods FString getClassName() const override; diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index ceeeda0e..81bd4cb1 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -192,9 +192,9 @@ class FMenu : public FWindow, public FMenuList void mouseMoveDeselection (FMenuItem*, MouseStates&); void mouseUpOverBorder(); void mouseMoveOverBorder (MouseStates&) const; - void passEventToSubMenu (const FMouseEvent&&); - void passEventToSuperMenu (const FMouseEvent&&); - void passEventToMenuBar (const FMouseEvent&&) const; + void passEventToSubMenu (const FMouseEvent&); + void passEventToSuperMenu (const FMouseEvent&); + void passEventToMenuBar (const FMouseEvent&) const; bool containsMenuStructure (const FPoint&); bool containsMenuStructure (int, int); FMenu* superMenuAt (const FPoint&); diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 348b5eb0..828fa3c3 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -138,7 +138,7 @@ class FMenuBar : public FWindow, public FMenuList void selectMenuItem (FMenuItem*); void mouseDownOverList (const FMouseEvent*); void mouseUpOverList (const FMouseEvent*); - void mouseMoveOverList (const FMouseEvent&&); + void mouseMoveOverList (const FMouseEvent&); void passEventToMenu (const FMouseEvent&&) const; void leaveMenuBar(); diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index d24b2e51..10e6d814 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -99,7 +99,7 @@ class FMessageBox : public FDialog , ButtonType, ButtonType, ButtonType , FWidget* = nullptr ); // Destructor - virtual ~FMessageBox() noexcept override; + ~FMessageBox() noexcept override; // copy assignment operator (=) FMessageBox& operator = (const FMessageBox&); diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index a4b6c00a..b0616c7d 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -90,25 +90,19 @@ namespace finalcut class FMouseData { public: + // Constructor + FMouseData() = default; + + // Copy constructor + FMouseData (const FMouseData&) = default; + + // Destructor + virtual ~FMouseData() noexcept; + // Accessors virtual FString getClassName() const; const FPoint& getPos() const; - // Constructor - FMouseData(); - - // Default copy constructor - FMouseData (const FMouseData&) = default; - // Default move constructor - FMouseData (FMouseData&&) = default; - // Default copy assignment operator (=) - FMouseData& operator = (const FMouseData&) = default; - // Default move assignment operator (=) - FMouseData& operator = (FMouseData&&) = default; - - // Destructor - virtual ~FMouseData(); - // Inquiries bool isLeftButtonPressed() const; bool isLeftButtonReleased() const; @@ -185,9 +179,6 @@ class FMouse : public FMouseData // Constructor FMouse(); - // Destructor - ~FMouse() override; - // Accessors FString getClassName() const override; void clearEvent(); @@ -256,9 +247,6 @@ class FMouseGPM final : public FMouse // Constructor FMouseGPM(); - // Destructor - ~FMouseGPM() override = default; - // Accessors FString getClassName() const override; @@ -321,12 +309,6 @@ inline bool FMouseGPM::isGpmMouseEnabled() const class FMouseX11 final : public FMouse { public: - // Constructor - FMouseX11() = default; - - // Destructor - ~FMouseX11() override = default; - // Accessors FString getClassName() const override; @@ -380,12 +362,6 @@ class FMouseX11 final : public FMouse class FMouseSGR final : public FMouse { public: - // Constructor - FMouseSGR() = default; - - // Destructor - ~FMouseSGR() override = default; - // Accessors FString getClassName() const override; @@ -439,12 +415,6 @@ class FMouseSGR final : public FMouse class FMouseUrxvt final : public FMouse { public: - // Constructor - FMouseUrxvt() = default; - - // Destructor - ~FMouseUrxvt() override = default; - // Accessors FString getClassName() const override; @@ -527,15 +497,9 @@ class FMouseControl // Constructor FMouseControl(); - // Disable copy constructor - FMouseControl (const FMouseControl&) = delete; - // Destructor virtual ~FMouseControl(); - // Disable copy assignment operator (=) - FMouseControl& operator = (const FMouseControl&) = delete; - // Accessors virtual FString getClassName() const; const FPoint& getPos(); @@ -545,7 +509,7 @@ class FMouseControl void setStdinNo (int); void setMaxWidth (uInt16); void setMaxHeight (uInt16); - void setDblclickInterval (const uInt64); + void setDblclickInterval (const uInt64) const; void setEventCommand (const FMouseCommand&); void useGpmMouse (bool = true); void useXtermMouse (bool = true); diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index bff7cb6b..dec492d8 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -152,7 +152,7 @@ class FObject // Using-declaration using FTimerList = std::vector; - using FTimerListPtr = const std::unique_ptr; + using FTimerListUniquePtr = std::unique_ptr; // Accessor FTimerList* getTimerList() const; @@ -170,7 +170,7 @@ class FObject private: // Method virtual void performTimerAction (FObject*, FEvent*); - static FTimerListPtr& globalTimerList(); + static auto globalTimerList() -> const FTimerListUniquePtr&; // Data members FObject* parent_obj{nullptr}; diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index b4019623..c4b4d417 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -59,7 +59,7 @@ class FPoint FPoint& operator -= (const FPoint&); // Accessors - FString getClassName(); + FString getClassName() const; int getX() const; int getY() const; void setX (int); @@ -102,7 +102,7 @@ inline FPoint::FPoint (int x, int y) { } //---------------------------------------------------------------------- -inline FString FPoint::getClassName() +inline FString FPoint::getClassName() const { return "FPoint"; } //---------------------------------------------------------------------- diff --git a/src/include/final/frect.h b/src/include/final/frect.h index ec588e33..5bf1d2a6 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -65,7 +65,7 @@ class FRect FRect (const FPoint&, const FPoint&); // Accessors - FString getClassName(); + FString getClassName() const; int getX1() const; int getY1() const; int getX2() const; @@ -147,7 +147,7 @@ inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) { } //---------------------------------------------------------------------- -inline FString FRect::getClassName() +inline FString FRect::getClassName() const { return "FRect"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h index 90c94f4f..3a9d2cfb 100644 --- a/src/include/final/fsize.h +++ b/src/include/final/fsize.h @@ -64,7 +64,7 @@ class FSize FSize& operator -= (const FSize&); // Accessors - FString getClassName(); + FString getClassName() const; std::size_t getWidth() const; std::size_t getHeight() const; std::size_t getArea() const; @@ -111,7 +111,7 @@ inline FSize::FSize (std::size_t w, std::size_t h) { } //---------------------------------------------------------------------- -inline FString FSize::getClassName() +inline FString FSize::getClassName() const { return "FSize"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h index 2904ce7e..dfd994a6 100644 --- a/src/include/final/fstringstream.h +++ b/src/include/final/fstringstream.h @@ -72,13 +72,13 @@ class FStringStream : public std::wiostream FStringStream (FStringStream&&) noexcept; // Destructor - ~FStringStream(); + ~FStringStream() noexcept; // Disable copy assignment operator (=) FStringStream& operator = (const FStringStream&) = delete; // Move assignment operator (=) - FStringStream& operator = (FStringStream&& sstream) noexcept; + FStringStream& operator = (FStringStream&&) noexcept; virtual FString getClassName() const; void swap (FStringStream&) noexcept; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 7abd7cf6..cf1379a1 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -142,15 +142,15 @@ class FTermDebugData; class FTermDetection; class FTermXTerminal; -#if defined(UNIT_TEST) +#if defined(__linux__) || defined(UNIT_TEST) class FTermLinux; +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) class FTermFreeBSD; - class FTermOpenBSD; -#elif defined(__linux__) - class FTermLinux; -#elif defined(__FreeBSD__) || defined(__DragonFly__) - class FTermFreeBSD; -#elif defined(__NetBSD__) || defined(__OpenBSD__) +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) class FTermOpenBSD; #endif @@ -163,7 +163,6 @@ class FTerm final public: // Using-declarations using defaultPutChar = std::function; - using FColorPalettePtr = std::shared_ptr; using FSetPalette = FColorPalette::FSetPalette; // Constructor @@ -183,36 +182,36 @@ class FTerm final static std::size_t getLineNumber(); static std::size_t getColumnNumber(); static FString getKeyName (FKey); + charSubstitution& getCharSubstitutionMap(); static int getTTYFileDescriptor(); static const char* getTermType(); static const char* getTermFileName(); static int getTabstop(); static int getMaxColor(); - static FColorPalettePtr& getColorPaletteTheme(); - charSubstitution& getCharSubstitutionMap(); - static FTermData* getFTermData(); - static FSystem* getFSystem(); - static FOptiMove* getFOptiMove(); - static FOptiAttr* getFOptiAttr(); - static FTermDetection* getFTermDetection(); - static FTermXTerminal* getFTermXTerminal(); - static FKeyboard* getFKeyboard(); - static FMouseControl* getFMouseControl(); + static auto getColorPaletteTheme() -> std::shared_ptr&; + static auto getFTermData() -> const std::unique_ptr&; + static auto getFSystem() -> std::unique_ptr&; + static auto getFOptiMove() -> const std::unique_ptr&; + static auto getFOptiAttr() -> const std::unique_ptr&; + static auto getFTermDetection() -> const std::unique_ptr&; + static auto getFTermXTerminal() -> const std::unique_ptr&; + static auto getFKeyboard() -> const std::unique_ptr&; + static auto getFMouseControl() -> const std::unique_ptr&; -#if defined(UNIT_TEST) - static FTermLinux* getFTermLinux(); - static FTermFreeBSD* getFTermFreeBSD(); - static FTermOpenBSD* getFTermOpenBSD(); -#elif defined(__linux__) - static FTermLinux* getFTermLinux(); -#elif defined(__FreeBSD__) || defined(__DragonFly__) - static FTermFreeBSD* getFTermFreeBSD(); -#elif defined(__NetBSD__) || defined(__OpenBSD__) - static FTermOpenBSD* getFTermOpenBSD(); +#if defined(__linux__) || defined(UNIT_TEST) + static auto getFTermLinux() -> const std::unique_ptr&; +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + static auto getFTermFreeBSD() -> const std::unique_ptr&; +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) + static auto getFTermOpenBSD() -> const std::unique_ptr&; #endif #if DEBUG - static FTermDebugData& getFTermDebugData(); + static auto getFTermDebugData() -> const std::unique_ptr&; #endif // Inquiries @@ -252,7 +251,7 @@ class FTerm final static bool canChangeColorPalette(); // Mutators - static void setFSystem (FSystem*); + static void setFSystem (std::unique_ptr&&); static void setTermType (const char[]); static void setInsertCursor (bool); static void setInsertCursor(); @@ -319,7 +318,6 @@ class FTerm final static void init_cygwin_charmap(); static void init_teraterm_charmap(); static void init_fixed_max_color(); - static void init_keyboard(); static void init_termcap(); static void init_quirks(); static void init_optiMove(); @@ -351,8 +349,6 @@ class FTerm final static void enableAlternateCharset(); static void useAlternateScreenBuffer(); static void useNormalScreenBuffer(); - void allocationValues() const; - void deallocationValues(); void init(); bool init_terminal() const; void initOSspecifics() const; @@ -361,41 +357,12 @@ class FTerm final void finish() const; void finishOSspecifics() const; void finish_encoding() const; - void destroyColorPaletteTheme(); static void printExitMessage(); static void terminalSizeChange(); [[noreturn]] static void processTermination (int); static void setSignalHandler(); static void resetSignalHandler(); static void signal_handler (int); - - // Data members - static FTermData* data; - static FSystem* fsys; - static FOptiMove* opti_move; - static FOptiAttr* opti_attr; - static FTermDetection* term_detection; - static FTermXTerminal* xterm; - static FKeyboard* keyboard; - static FMouseControl* mouse; - -#if defined(UNIT_TEST) - #undef linux - static FTermLinux* linux; - static FTermFreeBSD* freebsd; - static FTermOpenBSD* openbsd; -#elif defined(__linux__) - #undef linux - static FTermLinux* linux; -#elif defined(__FreeBSD__) || defined(__DragonFly__) - static FTermFreeBSD* freebsd; -#elif defined(__NetBSD__) || defined(__OpenBSD__) - static FTermOpenBSD* openbsd; -#endif - -#if DEBUG - static FTermDebugData* debug_data; -#endif }; @@ -424,8 +391,10 @@ inline FString FTerm::getClassName() { return "FTerm"; } //---------------------------------------------------------------------- -inline void FTerm::setFSystem (FSystem* fsystem) -{ fsys = fsystem; } +inline void FTerm::setFSystem (std::unique_ptr&& fsystem) +{ + getFSystem().swap(fsystem); +} //---------------------------------------------------------------------- inline void FTerm::setInsertCursor() @@ -460,15 +429,11 @@ inline void FTerm::putstringf (const char format[], Args&&... args) if ( size == -1 ) return; - if ( ! fsys ) - getFSystem(); // Trying to set fsys - const auto count = std::size_t(size); std::vector buf(count); std::snprintf (&buf[0], count, format, std::forward(args)...); - - if ( fsys ) - fsys->tputs (&buf[0], 1, FTerm::putchar_ASCII); + const auto& fsys = FTerm::getFSystem(); + fsys->tputs (&buf[0], 1, FTerm::putchar_ASCII); } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index a4ca6d45..dc30ec31 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -60,17 +60,14 @@ #include #include +#include "final/ftermcap.h" + // FTermcap string macro #define TCAP(...) FTermcap::strings[__VA_ARGS__].string namespace finalcut { -// class forward declaration -class FSystem; -class FTermData; -class FTermDetection; - //---------------------------------------------------------------------- // class FTermcap //---------------------------------------------------------------------- @@ -148,10 +145,8 @@ class FTermcap final static int _tputs (const char*, int, fn_putc); // Data member - static FSystem* fsystem; - static FTermData* fterm_data; - static FTermDetection* term_detection; - static char string_buf[BUF_SIZE]; + static char string_buf[BUF_SIZE]; + static bool initialized; }; @@ -206,7 +201,7 @@ int FTermcap::paddingPrint (const CharT& str, int affcnt, fn_putc putc) //---------------------------------------------------------------------- inline bool FTermcap::isInitialized() { - return bool(fsystem && fterm_data && term_detection); + return initialized; } } // namespace finalcut diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index 384918d5..6f27999c 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -38,10 +38,6 @@ namespace finalcut { -// class forward declaration -class FTermData; -class FTermDetection; - //---------------------------------------------------------------------- // class FTermcapsQuirks //---------------------------------------------------------------------- @@ -77,10 +73,6 @@ class FTermcapQuirks final static void screen(); static void general(); static void ecma48(); - - // Data members - static FTermData* fterm_data; - static FTermDetection* term_detection; }; // FTermcapQuirks inline functions diff --git a/src/include/final/ftermdebugdata.h b/src/include/final/ftermdebugdata.h index 1d76e9da..392d2087 100644 --- a/src/include/final/ftermdebugdata.h +++ b/src/include/final/ftermdebugdata.h @@ -40,8 +40,6 @@ namespace finalcut // class forward declaration class FTerm; -class FTermData; -class FTermDetection; #if DEBUG //---------------------------------------------------------------------- @@ -72,14 +70,6 @@ class FTermDebugData final #if defined(__linux__) int getFramebufferBpp(); #endif - - // Methods - static void init(); - - private: - // Data members - static FTermData* data; - static FTermDetection* term_detection; }; #endif // DEBUG diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index 6935372e..aa2268df 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -207,9 +207,6 @@ class FTermDetection final static int gnome_terminal_id; static const FString* answer_back; static const FString* sec_da; - static FTermData* fterm_data; - static FSystem* fsystem; - static FKeyboard* keyboard; static FTerminalType terminal_type; static colorEnv color_env; static secondaryDA secondary_da; diff --git a/src/include/final/ftermfreebsd.h b/src/include/final/ftermfreebsd.h index 23214c59..27893b08 100644 --- a/src/include/final/ftermfreebsd.h +++ b/src/include/final/ftermfreebsd.h @@ -69,7 +69,6 @@ namespace finalcut { // class forward declaration -class FSystem; class FTermData; //---------------------------------------------------------------------- @@ -123,15 +122,12 @@ class FTermFreeBSD final static bool setFreeBSDAlt2Meta(); static bool resetFreeBSDAlt2Meta(); static bool setFreeBSDCursorStyle (CursorStyle); - static bool isInitialized(); // Data members static uInt bsd_alt_keymap; static CursorStyle cursor_style; static bool change_cursorstyle; static bool meta_sends_escape; - static FSystem* fsystem; - static FTermData* fterm_data; }; @@ -157,9 +153,6 @@ inline void FTermFreeBSD::enableMetaSendsEscape() inline void FTermFreeBSD::disableMetaSendsEscape() { meta_sends_escape = false; } -//---------------------------------------------------------------------- -inline bool FTermFreeBSD::isInitialized() -{ return bool(fsystem && fterm_data); } #endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) } // namespace finalcut diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 989b8028..efaa0e32 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -65,11 +65,6 @@ namespace finalcut { -// class forward declaration -class FSystem; -class FTermData; -class FTermDetection; - //---------------------------------------------------------------------- // class FTermLinux //---------------------------------------------------------------------- @@ -148,7 +143,7 @@ class FTermLinux final int getFramebuffer_bpp(); bool getScreenFont(); bool getUnicodeMap (); - ModifierKey& getModifierKey(); + ModifierKey& getModifierKey(); // Mutators int setScreenFont ( const uChar[], uInt, uInt, uInt @@ -187,9 +182,6 @@ class FTermLinux final bool vga_font{}; bool new_font{}; bool has_saved_palette{}; - FTermData* fterm_data{nullptr}; - FSystem* fsystem{nullptr}; - FTermDetection* term_detection{nullptr}; CursorStyle linux_console_cursor_style{}; console_font_op screen_font{}; unimapdesc screen_unicode_map{}; diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index 86590cca..43dabe28 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -64,9 +64,6 @@ namespace finalcut { -// class forward declaration -class FSystem; - //---------------------------------------------------------------------- // class FTermOpenBSD //---------------------------------------------------------------------- @@ -110,12 +107,10 @@ class FTermOpenBSD final static bool setBSDConsoleEncoding (kbd_t); static bool setBSDConsoleMetaEsc(); static bool resetBSDConsoleEncoding(); - static bool isInitialized(); // Data members static kbd_t bsd_keyboard_encoding; static bool meta_sends_escape; - static FSystem* fsystem; #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) }; @@ -134,9 +129,6 @@ inline void FTermOpenBSD::enableMetaSendsEscape() inline void FTermOpenBSD::disableMetaSendsEscape() { meta_sends_escape = false; } -//---------------------------------------------------------------------- -inline bool FTermOpenBSD::isInitialized() -{ return bool(fsystem); } #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) } // namespace finalcut diff --git a/src/include/final/ftermxterminal.h b/src/include/final/ftermxterminal.h index 2f53c910..f209d1b5 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -40,9 +40,6 @@ namespace finalcut // class forward declaration class FString; -class FSystem; -class FKeyboard; -class FTermDetection; //---------------------------------------------------------------------- // class FTermXTerminal @@ -52,7 +49,7 @@ class FTermXTerminal final { public: // Constructors - FTermXTerminal(); + FTermXTerminal() = default; // Disable copy constructor FTermXTerminal (const FTermXTerminal&) = delete; @@ -97,7 +94,6 @@ class FTermXTerminal final bool hasTitle() const; // Methods - void init(); void setDefaults(); void resetColorMap() const; void resetForeground(); @@ -134,7 +130,6 @@ class FTermXTerminal final void resetXTermMouseForeground() const; void resetXTermMouseBackground() const; void resetXTermHighlightBackground() const; - bool isInitialized() const; bool canResetColor() const; void oscPrefix() const; void oscPostfix() const; @@ -160,9 +155,6 @@ class FTermXTerminal final FString mouse_foreground_color{}; FString mouse_background_color{}; FString highlight_background_color{}; - static FSystem* fsystem; - static FKeyboard* keyboard; - FTermDetection* term_detection{nullptr}; fc::xtermCursorStyle cursor_style{fc::unknown_cursor_style}; }; @@ -228,10 +220,6 @@ inline void FTermXTerminal::setMouseSupport() inline void FTermXTerminal::unsetMouseSupport() { setMouseSupport (false); } -//---------------------------------------------------------------------- -inline bool FTermXTerminal::isInitialized() const -{ return bool(fsystem && term_detection); } - } // namespace finalcut #endif // FTERMXTERMINAL_H diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 0780e32f..35e35565 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -148,7 +148,7 @@ class FToggleButton : public FWidget // Methods void init(); - void drawText (FString&&, std::size_t); + void drawText (const FString&, std::size_t); void correctSize (FSize&) const; // Data members diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index be265c79..6270a1fc 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -68,12 +68,10 @@ namespace finalcut // class forward declaration class FColorPair; -class FMouseControl; class FPoint; class FRect; class FSize; class FString; -class FSystem; class FTerm; class FTermBuffer; class FTermDebugData; @@ -370,7 +368,7 @@ class FVTerm static FChar getCoveredCharacter (const FPoint&, const FTermArea*); static FChar getOverlappedCharacter (const FPoint&, const FTermArea*); void init(); - static void init_characterLengths (const FOptiMove*); + static void init_characterLengths(); void finish(); static void putAreaLine (const FChar&, FChar&, std::size_t); static void putAreaCharacter ( const FPoint&, const FTermArea* @@ -426,7 +424,6 @@ class FVTerm FTermArea* child_print_area{nullptr}; // print area for children FTermArea* vwin{nullptr}; // virtual window static const FVTerm* init_object; // Global FVTerm object - static FSystem* fsystem; static FTerm* fterm; static FTermArea* vterm; // virtual terminal static FTermArea* vdesktop; // virtual desktop @@ -437,7 +434,6 @@ class FVTerm static FChar s_ch; // shadow character static FChar i_ch; // inherit background character static FPoint* term_pos; // terminal cursor position - static FMouseControl* mouse; static timeval time_last_flush; static timeval last_term_size_check; static bool draw_completed; @@ -492,6 +488,11 @@ struct FVTerm::FTermArea // define virtual terminal character properties bool visible{false}; }; +struct D +{ + void operator () (const FVTerm*) const + { } +}; //---------------------------------------------------------------------- // struct FVTerm::FVTermPreprocessing @@ -500,16 +501,19 @@ struct FVTerm::FTermArea // define virtual terminal character properties struct FVTerm::FVTermPreprocessing { // Constructor - FVTermPreprocessing() = default; - FVTermPreprocessing (const FVTerm* i, const FPreprocessingFunction& f) - : instance(i) + : instance(std::unique_ptr(i)) , function(f) { } + FVTermPreprocessing (const FVTermPreprocessing&) = delete; + FVTermPreprocessing (FVTermPreprocessing&&) = default; + FVTermPreprocessing& operator = (const FVTermPreprocessing&) = delete; + FVTermPreprocessing& operator = (FVTermPreprocessing&&) noexcept = default; + // Data members - const FVTerm* instance{nullptr}; - FPreprocessingFunction function{nullptr}; + std::unique_ptr instance{}; + FPreprocessingFunction function{}; }; diff --git a/src/include/final/fwidgetcolors.h b/src/include/final/fwidgetcolors.h index 38fbed1a..60a279cf 100644 --- a/src/include/final/fwidgetcolors.h +++ b/src/include/final/fwidgetcolors.h @@ -48,10 +48,10 @@ class FWidgetColors { public: // Constructor - FWidgetColors(); + FWidgetColors() = default; // Destructor - virtual ~FWidgetColors(); + virtual ~FWidgetColors() noexcept; // Method virtual FString getClassName() const; @@ -176,7 +176,7 @@ class default8ColorTheme final : public FWidgetColors default8ColorTheme(); // Destructor - ~default8ColorTheme() override; + ~default8ColorTheme() noexcept override; // Method FString getClassName() const override; @@ -213,7 +213,7 @@ class default16ColorTheme final : public FWidgetColors default16ColorTheme(); // Destructor - ~default16ColorTheme() override; + ~default16ColorTheme() noexcept override; // Method FString getClassName() const override; @@ -250,7 +250,7 @@ class default8ColorDarkTheme final : public FWidgetColors default8ColorDarkTheme(); // Destructor - ~default8ColorDarkTheme() override; + ~default8ColorDarkTheme() noexcept override; // Method FString getClassName() const override; @@ -287,7 +287,7 @@ class default16ColorDarkTheme final : public FWidgetColors default16ColorDarkTheme(); // Destructor - ~default16ColorDarkTheme() override; + ~default16ColorDarkTheme() noexcept override; // Method FString getClassName() const override; diff --git a/test/conemu.h b/test/conemu.h index 25529b1d..109b2bc4 100644 --- a/test/conemu.h +++ b/test/conemu.h @@ -531,7 +531,7 @@ inline pid_t ConEmu::forkConEmu() #ifdef TIOCSWINSZ // Set slave tty window size - struct winsize size; + struct winsize size{}; size.ws_row = 25; size.ws_col = 80; diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index dc0582df..640a2894 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -573,7 +573,6 @@ struct keymap_t& FSystemTest::getTerminalKeymap() return terminal_keymap; } - } // namespace test @@ -624,11 +623,10 @@ void ftermfreebsdTest::freebsdConsoleTest() setenv ("COLUMNS", "80", 1); setenv ("LINES", "25", 1); - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTermDetection* term_detection{}; - finalcut::FTerm::setFSystem(fsys); + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -655,10 +653,9 @@ void ftermfreebsdTest::freebsdConsoleTest() data->setVGAFont (false); data->setMonochron (false); data->setTermResized (false); - // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); term_detection->setTerminalDetection(true); pid_t pid = forkConEmu(); @@ -666,7 +663,8 @@ void ftermfreebsdTest::freebsdConsoleTest() { static constexpr int left_alt = 0x38; finalcut::FTermFreeBSD freebsd; - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); struct keymap_t& keymap = fsystest->getTerminalKeymap(); setenv ("TERM", "xterm", 1); @@ -760,7 +758,7 @@ void ftermfreebsdTest::freebsdConsoleTest() #if DEBUG const finalcut::FString& sec_da = \ - finalcut::FTerm::getFTermDebugData().getSecDAString(); + finalcut::FTerm::getFTermDebugData()->getSecDAString(); CPPUNIT_ASSERT ( sec_da == "\033[>0;10;0c" ); #endif @@ -773,6 +771,7 @@ void ftermfreebsdTest::freebsdConsoleTest() data->setCursorHidden (false); freebsd.setCursorStyle (finalcut::fc::normal_cursor); + CPPUNIT_ASSERT ( fsystest->getCursorType() == finalcut::fc::normal_cursor ); freebsd.setCursorStyle (finalcut::fc::blink_cursor); @@ -812,8 +811,6 @@ void ftermfreebsdTest::freebsdConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- diff --git a/test/ftermlinux-test.cpp b/test/ftermlinux-test.cpp index 36afea72..de4a49ba 100644 --- a/test/ftermlinux-test.cpp +++ b/test/ftermlinux-test.cpp @@ -994,10 +994,16 @@ FSystemTest::FSystemTest() // constructor FSystemTest::~FSystemTest() // destructor { if ( terminal_font.data ) + { delete[] terminal_font.data; + terminal_font.data = nullptr; + } if ( terminal_unicode_map.entries ) + { delete[] terminal_unicode_map.entries; + terminal_unicode_map.entries = nullptr; + } } @@ -1091,19 +1097,25 @@ int FSystemTest::ioctl (int fd, uLong request, ...) constexpr std::size_t font_data_size = 4 * 32 * 512; struct console_font_op* fn = static_cast(argp); - // Set Default - if ( terminal_font.data && terminal_font.data[219 * 32] == 0 ) - { - terminal_font.width = 8; - terminal_font.height = 16; - terminal_font.charcount = 256; - - if ( fn->data ) - std::memcpy (terminal_font.data, &vga8x16, sizeof(vga8x16)); - } - if ( fn->op == KD_FONT_OP_GET ) { + // If data is empty + if ( ! terminal_font.data ) + { + terminal_font.data = new uChar[font_data_size]{ }; + } + + // Set Default + if ( terminal_font.data[219 * 32] == 0 ) + { + terminal_font.width = 8; + terminal_font.height = 16; + terminal_font.charcount = 256; + + if ( fn->data ) + std::memcpy (terminal_font.data, &vga8x16, sizeof(vga8x16)); + } + fn->flags = terminal_font.flags; fn->width = terminal_font.width; fn->height = terminal_font.height; @@ -1117,11 +1129,17 @@ int FSystemTest::ioctl (int fd, uLong request, ...) if ( fn->op == KD_FONT_OP_SET ) { - terminal_font.flags = fn->flags; - terminal_font.width = fn->width; - terminal_font.height = fn->height; - terminal_font.charcount = fn->charcount; - auto size = fn->width / 8 * fn->height * fn->charcount; + terminal_font.flags = fn->flags; + terminal_font.width = fn->width; + terminal_font.height = fn->height; + terminal_font.charcount = fn->charcount; + constexpr int fix_height = 32; // This value is identical for all fonts + auto size = fn->width / 8 * fix_height * fn->charcount; + + if ( ! terminal_font.data ) // If data is empty on a second run + { + terminal_font.data = new uChar[font_data_size]{ }; + } if ( fn->data && terminal_font.data ) std::memcpy (terminal_font.data, fn->data, size); @@ -1194,7 +1212,7 @@ int FSystemTest::ioctl (int fd, uLong request, ...) std::size_t pairs_size = pairs * sizeof(unipair); // Sets the default unicode map of the terminal on the first call - if ( terminal_unicode_map.entries == 0 ) + if ( ! terminal_unicode_map.entries ) { terminal_unicode_map.entry_ct = pairs; terminal_unicode_map.entries = new unipair[pairs](); @@ -1222,8 +1240,30 @@ int FSystemTest::ioctl (int fd, uLong request, ...) { req_string = "PIO_UNIMAP"; unimapdesc* umap = static_cast(argp); - std::memcpy (&terminal_unicode_map, umap, sizeof(*umap)); - ret_val = 0; + std::size_t pairs = umap->entry_ct; + std::size_t pairs_size = pairs * sizeof(unipair); + terminal_unicode_map.entry_ct = umap->entry_ct; + + if ( terminal_unicode_map.entries ) + { + delete[] terminal_unicode_map.entries; + terminal_unicode_map.entries = nullptr; + } + + terminal_unicode_map.entries = new unipair[pairs](); + + if ( umap->entries && terminal_unicode_map.entries ) + { + std::memcpy (terminal_unicode_map.entries, umap->entries, pairs_size); + errno = 0; + ret_val = 0; + } + else + { + errno = ENOMEM; + ret_val = 0; + } + break; } @@ -1519,11 +1559,10 @@ void FTermLinuxTest::classNameTest() //---------------------------------------------------------------------- void FTermLinuxTest::linuxConsoleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -1555,7 +1594,7 @@ void FTermLinuxTest::linuxConsoleTest() data->setMonochron (false); data->setTermResized (false); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; // setupterm is needed for tputs in ncurses >= 6.1 @@ -1590,7 +1629,8 @@ void FTermLinuxTest::linuxConsoleTest() CPPUNIT_ASSERT ( data->hasHalfBlockCharacter() ); CPPUNIT_ASSERT ( linux.getFramebufferBpp() == 32 ); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); std::string& characters = fsystest->getCharacters(); linux.setUTF8 (false); CPPUNIT_ASSERT ( characters == ESC "%@" ); @@ -1636,18 +1676,15 @@ void FTermLinuxTest::linuxConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::linuxCursorStyleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -1681,7 +1718,7 @@ void FTermLinuxTest::linuxCursorStyleTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; pid_t pid = forkConEmu(); @@ -1704,7 +1741,8 @@ void FTermLinuxTest::linuxCursorStyleTest() term_detection->detect(); linux.init(); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); std::string& characters = fsystest->getCharacters(); characters.clear(); linux.setCursorStyle (finalcut::fc::default_cursor); @@ -1827,18 +1865,15 @@ void FTermLinuxTest::linuxCursorStyleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::linuxColorPaletteTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -1872,7 +1907,7 @@ void FTermLinuxTest::linuxColorPaletteTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; term_detection->setLinuxTerm(true); @@ -1895,7 +1930,8 @@ void FTermLinuxTest::linuxColorPaletteTest() term_detection->detect(); linux.init(); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); CPPUNIT_ASSERT ( linux.resetColorMap() == true ); CPPUNIT_ASSERT ( linux.saveColorMap() == true ); @@ -2104,18 +2140,15 @@ void FTermLinuxTest::linuxColorPaletteTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::linuxFontTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -2149,7 +2182,7 @@ void FTermLinuxTest::linuxFontTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; pid_t pid = forkConEmu(); @@ -2171,18 +2204,19 @@ void FTermLinuxTest::linuxFontTest() term_detection->detect(); linux.init(); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); console_font_op& font = fsystest->getConsoleFont(); CPPUNIT_ASSERT ( font.op == KD_FONT_OP_GET ); CPPUNIT_ASSERT ( ! linux.isVGAFontUsed() ); CPPUNIT_ASSERT ( ! linux.isNewFontUsed() ); - linux.loadVGAFont(); - /* CPPUNIT_ASSERT ( data->hasShadowCharacter() ); + CPPUNIT_ASSERT ( data->hasShadowCharacter() ); CPPUNIT_ASSERT ( data->hasHalfBlockCharacter() ); CPPUNIT_ASSERT ( font.op == KD_FONT_OP_SET ); CPPUNIT_ASSERT ( linux.isVGAFontUsed() ); CPPUNIT_ASSERT ( ! linux.isNewFontUsed() ); + CPPUNIT_ASSERT ( font.data ); // Full block character test for (std::size_t i = 0; i < 16 ; i++) @@ -2235,7 +2269,7 @@ void FTermLinuxTest::linuxFontTest() CPPUNIT_ASSERT ( font.data[249 * 32 + 13] == 0x00 ); CPPUNIT_ASSERT ( font.data[249 * 32 + 14] == 0x00 ); CPPUNIT_ASSERT ( font.data[249 * 32 + 15] == 0x00 ); -*/ + linux.finish(); closeConEmuStdStreams(); @@ -2249,19 +2283,20 @@ void FTermLinuxTest::linuxFontTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::modifierKeyTest() { + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); + + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); + test::FSystemTest::ShiftState& mod_key = fsystest->getShiftState(); + finalcut::FTermLinux linux{}; FKey keycode{}; FKey mod_keycode{}; - finalcut::FTermLinux linux{}; - finalcut::FSystem* fsys(new test::FSystemTest()); - test::FSystemTest* fsystest = static_cast(fsys); - test::FSystemTest::ShiftState& mod_key = fsystest->getShiftState(); // Up key keycode = finalcut::fc::Fkey_up; @@ -2721,7 +2756,6 @@ void FTermLinuxTest::modifierKeyTest() mod_key.shift = 1; mod_keycode = linux.modifierKeyCorrection(keycode); CPPUNIT_ASSERT ( mod_keycode == finalcut::fc::Fkey_space ); - delete fsys; } // Put the test suite in the registry diff --git a/test/ftermopenbsd-test.cpp b/test/ftermopenbsd-test.cpp index 1936f2ba..9201aaba 100644 --- a/test/ftermopenbsd-test.cpp +++ b/test/ftermopenbsd-test.cpp @@ -345,11 +345,10 @@ void ftermopenbsdTest::classNameTest() //---------------------------------------------------------------------- void ftermopenbsdTest::netbsdConsoleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -379,7 +378,7 @@ void ftermopenbsdTest::netbsdConsoleTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); term_detection->setTerminalDetection(true); pid_t pid = forkConEmu(); @@ -407,7 +406,7 @@ void ftermopenbsdTest::netbsdConsoleTest() #if DEBUG const finalcut::FString& sec_da = \ - finalcut::FTerm::getFTermDebugData().getSecDAString(); + finalcut::FTerm::getFTermDebugData()->getSecDAString(); CPPUNIT_ASSERT ( sec_da == "\033[>24;20;0c" ); #endif @@ -445,18 +444,15 @@ void ftermopenbsdTest::netbsdConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void ftermopenbsdTest::openbsdConsoleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -486,7 +482,7 @@ void ftermopenbsdTest::openbsdConsoleTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); term_detection->setTerminalDetection(true); pid_t pid = forkConEmu(); @@ -507,7 +503,8 @@ void ftermopenbsdTest::openbsdConsoleTest() unsetenv("KONSOLE_DCOP"); unsetenv("TMUX"); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); wskbd_bell_data& speaker = fsystest->getBell(); openbsd.disableMetaSendsEscape(); openbsd.init(); @@ -516,7 +513,7 @@ void ftermopenbsdTest::openbsdConsoleTest() #if DEBUG const finalcut::FString& sec_da = \ - finalcut::FTerm::getFTermDebugData().getSecDAString(); + finalcut::FTerm::getFTermDebugData()->getSecDAString(); CPPUNIT_ASSERT ( sec_da == "\033[>24;20;0c" ); #endif @@ -583,8 +580,6 @@ void ftermopenbsdTest::openbsdConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; }