From 8732f505c5202b9e938c0d44f12397c5244fae5f Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 23 Oct 2023 00:11:46 +0200 Subject: [PATCH] Reorganize the data structure of FOptiAttr --- ChangeLog | 3 + configure.ac | 8 +- final/fapplication.cpp | 2 +- final/fapplication.h | 2 +- final/fconfig.h | 111 ++++++-- final/fobject.h | 4 +- final/menu/fdialoglistmenu.cpp | 8 +- final/menu/fdialoglistmenu.h | 7 +- final/menu/fmenu.cpp | 16 +- final/menu/fmenu.h | 6 +- final/output/tty/foptiattr.cpp | 398 ++++++++++++++-------------- final/output/tty/foptiattr.h | 162 ++++++----- final/output/tty/fterm.h | 13 +- final/output/tty/ftermcapquirks.cpp | 61 ++--- final/output/tty/ftermdetection.cpp | 9 +- final/util/fdata.h | 19 +- final/util/flog.h | 4 +- test/foptiattr-test.cpp | 23 +- test/fstringstream-test.cpp | 4 +- test/ftermfreebsd-test.cpp | 5 +- test/ftermlinux-test.cpp | 6 +- test/ftermopenbsd-test.cpp | 4 +- test/fwidget-test.cpp | 2 +- 23 files changed, 476 insertions(+), 401 deletions(-) diff --git a/ChangeLog b/ChangeLog index 46742b95..e22edc8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2023-10-23 Markus Gans + * Reorganize the data structure of FOptiAttr + 2023-10-14 Markus Gans * Switch to a readers-writer lock for the timer list diff --git a/configure.ac b/configure.ac index ec2b06ee..fdb87577 100644 --- a/configure.ac +++ b/configure.ac @@ -43,9 +43,10 @@ AC_CHECK_HEADERS( \ # Checks for library functions. AC_CHECK_FUNCS( \ - getuid \ geteuid \ getttynam \ + getuid \ + pthread_rwlock_wrlock \ select \ sigaction \ strdup \ @@ -54,15 +55,16 @@ AC_CHECK_FUNCS( \ timer_settime \ vsnprintf \ wcwidth ) - # Checks for 'tgetent' AC_SEARCH_LIBS([tgetent], [terminfo mytinfo termlib termcap tinfo ncurses curses]) # Checks for 'tparm' AC_SEARCH_LIBS([tparm], [terminfo mytinfo termlib termcap tinfo ncurses curses]) # Checks for 'timer_create' AC_SEARCH_LIBS([timer_create], [rt]) -# Checks for 'timer_create' +# Checks for 'timer_settime' AC_SEARCH_LIBS([timer_settime], [rt]) +# Checks for 'pthread_rwlock_wrlock' +AC_SEARCH_LIBS([pthread_rwlock_wrlock], [pthread]) AC_SUBST([FINAL_LIBS]) AC_SUBST([TERMCAP_LIB]) diff --git a/final/fapplication.cpp b/final/fapplication.cpp index 97c549a0..fc4964b6 100644 --- a/final/fapplication.cpp +++ b/final/fapplication.cpp @@ -677,7 +677,7 @@ inline void FApplication::findKeyboardWidget() const } //---------------------------------------------------------------------- -inline auto FApplication::isKeyPressed(uInt64 ms) const -> bool +inline auto FApplication::isKeyPressed (uInt64 ms) const -> bool { static auto& mouse = FMouseControl::getInstance(); static auto& keyboard = FKeyboard::getInstance(); diff --git a/final/fapplication.h b/final/fapplication.h index 970fd219..38e04533 100644 --- a/final/fapplication.h +++ b/final/fapplication.h @@ -178,7 +178,7 @@ class FApplication : public FWidget static void showParameterUsage(); void destroyLog(); void findKeyboardWidget() const; - auto isKeyPressed(uInt64 = 0U) const -> bool; + auto isKeyPressed (uInt64 = 0U) const -> bool; void keyPressed(); void keyReleased() const; void escapeKeyPressed() const; diff --git a/final/fconfig.h b/final/fconfig.h index 97f2776b..5433779b 100644 --- a/final/fconfig.h +++ b/final/fconfig.h @@ -1,6 +1,6 @@ #ifndef _FINAL_FCONFIG_H #define _FINAL_FCONFIG_H 1 - + /* final/fconfig.h. Generated automatically at end of configure. */ /* config.h. Generated from config.h.in by configure. */ /* config.h.in. Generated from configure.ac by autoheader. */ @@ -70,9 +70,12 @@ /* Define to 1 if you have the header file. */ /* #undef HAVE_MAP */ -/* Define to 1 if you have the header file. */ -#ifndef F_HAVE_MEMORY_H -#define F_HAVE_MEMORY_H 1 +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MINIX_CONFIG_H */ + +/* Define to 1 if you have the `pthread_rwlock_wrlock' function. */ +#ifndef F_HAVE_PTHREAD_RWLOCK_WRLOCK +#define F_HAVE_PTHREAD_RWLOCK_WRLOCK 1 #endif /* Define to 1 if you have the header file. */ @@ -93,6 +96,11 @@ #define F_HAVE_STDINT_H 1 #endif +/* Define to 1 if you have the header file. */ +#ifndef F_HAVE_STDIO_H +#define F_HAVE_STDIO_H 1 +#endif + /* Define to 1 if you have the header file. */ #ifndef F_HAVE_STDLIB_H #define F_HAVE_STDLIB_H 1 @@ -181,6 +189,11 @@ #define F_HAVE_VSNPRINTF 1 #endif +/* Define to 1 if you have the header file. */ +#ifndef F_HAVE_WCHAR_H +#define F_HAVE_WCHAR_H 1 +#endif + /* Define to 1 if you have the `wcwidth' function. */ #ifndef F_HAVE_WCWIDTH #define F_HAVE_WCWIDTH 1 @@ -226,7 +239,9 @@ #define F_PACKAGE_VERSION "0.9.0" #endif -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #ifndef F_STDC_HEADERS #define F_STDC_HEADERS 1 #endif @@ -235,21 +250,87 @@ #ifndef _ALL_SOURCE # define _ALL_SOURCE 1 #endif +/* Enable general extensions on macOS. */ +#ifndef _DARWIN_C_SOURCE +# define _DARWIN_C_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif /* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif -/* Enable threading extensions on Solaris. */ +/* Enable X/Open compliant socket functions that do not require linking + with -lxnet on HP-UX 11.11. */ +#ifndef _HPUX_ALT_XOPEN_SOCKET_API +# define _HPUX_ALT_XOPEN_SOCKET_API 1 +#endif +/* Identify the host operating system as Minix. + This macro does not affect the system headers' behavior. + A future release of Autoconf may stop defining this macro. */ +#ifndef _MINIX +/* # undef _MINIX */ +#endif +/* Enable general extensions on NetBSD. + Enable NetBSD compatibility extensions on Minix. */ +#ifndef _NETBSD_SOURCE +# define _NETBSD_SOURCE 1 +#endif +/* Enable OpenBSD compatibility extensions on NetBSD. + Oddly enough, this does nothing on OpenBSD. */ +#ifndef _OPENBSD_SOURCE +# define _OPENBSD_SOURCE 1 +#endif +/* Define to 1 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_SOURCE +/* # undef _POSIX_SOURCE */ +#endif +/* Define to 2 if needed for POSIX-compatible behavior. */ +#ifndef _POSIX_1_SOURCE +/* # undef _POSIX_1_SOURCE */ +#endif +/* Enable POSIX-compatible threading on Solaris. */ #ifndef _POSIX_PTHREAD_SEMANTICS # define _POSIX_PTHREAD_SEMANTICS 1 #endif +/* Enable extensions specified by ISO/IEC TS 18661-5:2014. */ +#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ +# define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-1:2014. */ +#ifndef __STDC_WANT_IEC_60559_BFP_EXT__ +# define __STDC_WANT_IEC_60559_BFP_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-2:2015. */ +#ifndef __STDC_WANT_IEC_60559_DFP_EXT__ +# define __STDC_WANT_IEC_60559_DFP_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */ +#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__ +# define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TS 18661-3:2015. */ +#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ +# define __STDC_WANT_IEC_60559_TYPES_EXT__ 1 +#endif +/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */ +#ifndef __STDC_WANT_LIB_EXT2__ +# define __STDC_WANT_LIB_EXT2__ 1 +#endif +/* Enable extensions specified by ISO/IEC 24747:2009. */ +#ifndef __STDC_WANT_MATH_SPEC_FUNCS__ +# define __STDC_WANT_MATH_SPEC_FUNCS__ 1 +#endif /* Enable extensions on HP NonStop. */ #ifndef _TANDEM_SOURCE # define _TANDEM_SOURCE 1 #endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 +/* Enable X/Open extensions. Define to 500 only if necessary + to make mbstate_t available. */ +#ifndef _XOPEN_SOURCE +/* # undef _XOPEN_SOURCE */ #endif @@ -257,16 +338,6 @@ #ifndef F_VERSION #define F_VERSION "0.9.0" #endif - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - + /* once: _FINAL_FCONFIG_H */ #endif diff --git a/final/fobject.h b/final/fobject.h index bc1745ae..fa7f5eb9 100644 --- a/final/fobject.h +++ b/final/fobject.h @@ -286,8 +286,8 @@ inline auto FObject::isInstanceOf (const FString& classname) const -> bool { return classname == getClassName(); } //---------------------------------------------------------------------- -inline void FObject::setWidgetProperty (bool property) -{ widget_object = property; } +inline void FObject::setWidgetProperty (bool is_widget) +{ widget_object = is_widget; } } // namespace finalcut diff --git a/final/menu/fdialoglistmenu.cpp b/final/menu/fdialoglistmenu.cpp index af066259..c1591513 100644 --- a/final/menu/fdialoglistmenu.cpp +++ b/final/menu/fdialoglistmenu.cpp @@ -78,7 +78,7 @@ void FDialogListMenu::init() "last-dialog-closed", this, &FDialogListMenu::cb_switchState, - false + Enable::No ); fapp->addCallback @@ -86,19 +86,19 @@ void FDialogListMenu::init() "first-dialog-opened", this, &FDialogListMenu::cb_switchState, - true + Enable::Yes ); } //---------------------------------------------------------------------- -void FDialogListMenu::cb_switchState (bool enable) +void FDialogListMenu::cb_switchState (Enable enable) { auto m_item = getItem(); if ( ! m_item ) return; - m_item->setFlags().feature.active = enable; + m_item->setFlags().feature.active = enable == Enable::Yes ? true : false; auto super = m_item->getSuperMenu(); if ( ! super ) diff --git a/final/menu/fdialoglistmenu.h b/final/menu/fdialoglistmenu.h index 2c1f754f..0d91fa0e 100644 --- a/final/menu/fdialoglistmenu.h +++ b/final/menu/fdialoglistmenu.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2016-2022 Markus Gans * +* Copyright 2016-2023 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -81,11 +81,14 @@ class FDialogListMenu : public FMenu auto getClassName() const -> FString override; private: + // Enumeration + enum class Enable { No, Yes }; + // Method void init(); // Callback method - void cb_switchState (bool); + void cb_switchState (Enable); }; diff --git a/final/menu/fmenu.cpp b/final/menu/fmenu.cpp index 8e38f693..aed8acf0 100644 --- a/final/menu/fmenu.cpp +++ b/final/menu/fmenu.cpp @@ -206,7 +206,7 @@ void FMenu::onMouseDown (FMouseEvent* ev) redraw(); // Open the sub menu to be opened - openSubMenu (shown_sub_menu); + openSubMenu (shown_sub_menu, SelectItem::No); } //---------------------------------------------------------------------- @@ -287,7 +287,7 @@ void FMenu::onMouseMove (FMouseEvent* ev) if ( shown_sub_menu ) { closeOpenedSubMenu(); - openSubMenu (shown_sub_menu); + openSubMenu (shown_sub_menu, SelectItem::No); } else if ( ms.hide_sub_menu ) { @@ -550,14 +550,14 @@ auto FMenu::adjustX (int x_pos) const -> int } //---------------------------------------------------------------------- -void FMenu::openSubMenu (FMenu* sub_menu, bool select) +void FMenu::openSubMenu (FMenu* sub_menu, SelectItem select) { // open sub menu if ( ! sub_menu || sub_menu->isShown() ) return; - if ( select ) + if ( select == SelectItem::Yes ) { sub_menu->selectFirstItem(); @@ -728,7 +728,7 @@ auto FMenu::mouseUpOverList (const FPoint& mouse_pos) -> bool auto sub_menu = sel_item->getMenu(); if ( ! sub_menu->isShown() ) - openSubMenu (sub_menu, SELECT_ITEM); + openSubMenu (sub_menu, SelectItem::Yes); else if ( opened_sub_menu ) { opened_sub_menu->selectFirstItem(); @@ -953,7 +953,7 @@ auto FMenu::hotkeyMenu (FKeyEvent* ev) -> bool auto try_to_open_submenu = [this] (const auto& sub_menu) { if ( ! sub_menu->isShown() ) - openSubMenu (sub_menu, SELECT_ITEM); + openSubMenu (sub_menu, SelectItem::Yes); sub_menu->redraw(); }; @@ -1331,7 +1331,7 @@ inline void FMenu::selectNextMenu (FKeyEvent* ev) auto sub_menu = getSelectedItem()->getMenu(); if ( ! sub_menu->isShown() ) - openSubMenu (sub_menu, SELECT_ITEM); + openSubMenu (sub_menu, SelectItem::Yes); else keypressMenuBar(ev); // select next menu } @@ -1348,7 +1348,7 @@ inline void FMenu::acceptSelection() auto sel_item = getSelectedItem(); if ( sel_item->hasMenu() ) - openSubMenu (sel_item->getMenu(), SELECT_ITEM); + openSubMenu (sel_item->getMenu(), SelectItem::Yes); else { unselectItem(); diff --git a/final/menu/fmenu.h b/final/menu/fmenu.h index e6f1e22c..e8b17526 100644 --- a/final/menu/fmenu.h +++ b/final/menu/fmenu.h @@ -139,6 +139,9 @@ class FMenu : public FWindow void cb_menuitemToggled (const FMenuItem*) const; private: + // Enumeration + enum class SelectItem { No, Yes }; + struct MouseStates { uChar focus_changed : 1; @@ -159,7 +162,6 @@ class FMenu : public FWindow // Constants static constexpr auto NOT_SET = static_cast(-1); - static constexpr bool SELECT_ITEM = true; // Accessors auto getSuperMenu() const -> FWidget*; @@ -185,7 +187,7 @@ class FMenu : public FWindow void calculateDimensions(); void adjustItems() const; auto adjustX(int) const -> int; - void openSubMenu (FMenu*, bool = false); + void openSubMenu (FMenu*, SelectItem); void closeOpenedSubMenu(); void hideSubMenus(); void hideSuperMenus() const; diff --git a/final/output/tty/foptiattr.cpp b/final/output/tty/foptiattr.cpp index 3cc50c91..528eeb22 100644 --- a/final/output/tty/foptiattr.cpp +++ b/final/output/tty/foptiattr.cpp @@ -83,45 +83,45 @@ void FOptiAttr::setTermEnvironment (const TermEnv& term_env) // Set all required termcap values at once // and initialize the FOptiAttr environment - set_enter_bold_mode (term_env.t_enter_bold_mode); - set_exit_bold_mode (term_env.t_exit_bold_mode); - set_enter_dim_mode (term_env.t_enter_dim_mode); - set_exit_dim_mode (term_env.t_exit_dim_mode); - set_enter_italics_mode (term_env.t_enter_italics_mode); - set_exit_italics_mode (term_env.t_exit_italics_mode); - set_enter_underline_mode (term_env.t_enter_underline_mode); - set_exit_underline_mode (term_env.t_exit_underline_mode); - set_enter_blink_mode (term_env.t_enter_blink_mode); - set_exit_blink_mode (term_env.t_exit_blink_mode); - set_enter_reverse_mode (term_env.t_enter_reverse_mode); - set_exit_reverse_mode (term_env.t_exit_reverse_mode); - set_enter_standout_mode (term_env.t_enter_standout_mode); - set_exit_standout_mode (term_env.t_exit_standout_mode); - set_enter_secure_mode (term_env.t_enter_secure_mode); - set_exit_secure_mode (term_env.t_exit_secure_mode); - set_enter_protected_mode (term_env.t_enter_protected_mode); - set_exit_protected_mode (term_env.t_exit_protected_mode); - set_enter_crossed_out_mode (term_env.t_enter_crossed_out_mode); - set_exit_crossed_out_mode (term_env.t_exit_crossed_out_mode); - set_enter_dbl_underline_mode (term_env.t_enter_dbl_underline_mode); - set_exit_dbl_underline_mode (term_env.t_exit_dbl_underline_mode); - set_set_attributes (term_env.t_set_attributes); - set_exit_attribute_mode (term_env.t_exit_attribute_mode); - set_enter_alt_charset_mode (term_env.t_enter_alt_charset_mode); - set_exit_alt_charset_mode (term_env.t_exit_alt_charset_mode); - set_enter_pc_charset_mode (term_env.t_enter_pc_charset_mode); - set_exit_pc_charset_mode (term_env.t_exit_pc_charset_mode); - set_a_foreground_color (term_env.t_set_a_foreground); - set_a_background_color (term_env.t_set_a_background); - set_foreground_color (term_env.t_set_foreground); - set_background_color (term_env.t_set_background); - set_term_color_pair (term_env.t_set_color_pair); - set_orig_pair (term_env.t_orig_pair); - set_orig_orig_colors (term_env.t_orig_colors); - - max_color = term_env.max_color; - attr_without_color = term_env.attr_without_color; - ansi_default_color = term_env.ansi_default_color; + set_enter_bold_mode (term_env.t_set_bold.on); + set_exit_bold_mode (term_env.t_set_bold.off); + set_enter_dim_mode (term_env.t_set_dim.on); + set_exit_dim_mode (term_env.t_set_dim.off); + set_enter_italics_mode (term_env.t_set_italics.on); + set_exit_italics_mode (term_env.t_set_italics.off); + set_enter_underline_mode (term_env.t_set_underline.on); + set_exit_underline_mode (term_env.t_set_underline.off); + set_enter_blink_mode (term_env.t_set_blink.on); + set_exit_blink_mode (term_env.t_set_blink.off); + set_enter_reverse_mode (term_env.t_set_reverse.on); + set_exit_reverse_mode (term_env.t_set_reverse.off); + set_enter_standout_mode (term_env.t_set_standout.on); + set_exit_standout_mode (term_env.t_set_standout.off); + set_enter_secure_mode (term_env.t_set_secure.on); + set_exit_secure_mode (term_env.t_set_secure.off); + set_enter_protected_mode (term_env.t_set_protected.on); + set_exit_protected_mode (term_env.t_set_protected.off); + set_enter_crossed_out_mode (term_env.t_set_crossed_out.on); + set_exit_crossed_out_mode (term_env.t_set_crossed_out.off); + set_enter_dbl_underline_mode (term_env.t_set_dbl_underline.on); + set_exit_dbl_underline_mode (term_env.t_set_dbl_underline.off); + set_set_attributes (term_env.t_set_attributes.on); + set_exit_attribute_mode (term_env.t_set_attributes.off); + set_enter_alt_charset_mode (term_env.t_set_alt_charset.on); + set_exit_alt_charset_mode (term_env.t_set_alt_charset.off); + set_enter_pc_charset_mode (term_env.t_set_pc_charset.on); + set_exit_pc_charset_mode (term_env.t_set_pc_charset.off); + set_a_foreground_color (term_env.t_set_color.a_foreground); + set_a_background_color (term_env.t_set_color.a_background); + set_foreground_color (term_env.t_set_color.foreground); + set_background_color (term_env.t_set_color.background); + set_term_color_pair (term_env.t_set_color.color_pair); + set_orig_pair (term_env.t_set_color.orig_pair); + set_orig_colors (term_env.t_set_color.orig_colors); + + F_color.max_color = term_env.t_set_color.max_color; + F_color.attr_without_color = term_env.t_set_color.attr_without_color; + F_color.ansi_default_color = term_env.t_set_color.ansi_default_color; initialize(); } @@ -131,8 +131,8 @@ void FOptiAttr::set_enter_bold_mode (const char cap[]) { if ( cap ) { - F_enter_bold_mode.cap = cap; - F_enter_bold_mode.caused_reset = false; + F_bold.on.cap = cap; + F_bold.on.caused_reset = false; } } @@ -141,8 +141,8 @@ void FOptiAttr::set_exit_bold_mode (const char cap[]) { if ( cap ) { - F_exit_bold_mode.cap = cap; - F_exit_bold_mode.caused_reset = false; + F_bold.off.cap = cap; + F_bold.off.caused_reset = false; } } @@ -151,8 +151,8 @@ void FOptiAttr::set_enter_dim_mode (const char cap[]) { if ( cap ) { - F_enter_dim_mode.cap = cap; - F_enter_dim_mode.caused_reset = false; + F_dim.on.cap = cap; + F_dim.on.caused_reset = false; } } @@ -161,8 +161,8 @@ void FOptiAttr::set_exit_dim_mode (const char cap[]) { if ( cap ) { - F_exit_dim_mode.cap = cap; - F_exit_dim_mode.caused_reset = false; + F_dim.off.cap = cap; + F_dim.off.caused_reset = false; } } @@ -171,8 +171,8 @@ void FOptiAttr::set_enter_italics_mode (const char cap[]) { if ( cap ) { - F_enter_italics_mode.cap = cap; - F_enter_italics_mode.caused_reset = false; + F_italics.on.cap = cap; + F_italics.on.caused_reset = false; } } @@ -181,8 +181,8 @@ void FOptiAttr::set_exit_italics_mode (const char cap[]) { if ( cap ) { - F_exit_italics_mode.cap = cap; - F_exit_italics_mode.caused_reset = false; + F_italics.off.cap = cap; + F_italics.off.caused_reset = false; } } @@ -191,8 +191,8 @@ void FOptiAttr::set_enter_underline_mode (const char cap[]) { if ( cap ) { - F_enter_underline_mode.cap = cap; - F_enter_underline_mode.caused_reset = false; + F_underline.on.cap = cap; + F_underline.on.caused_reset = false; } } @@ -201,8 +201,8 @@ void FOptiAttr::set_exit_underline_mode (const char cap[]) { if ( cap ) { - F_exit_underline_mode.cap = cap; - F_exit_underline_mode.caused_reset = false; + F_underline.off.cap = cap; + F_underline.off.caused_reset = false; } } @@ -211,8 +211,8 @@ void FOptiAttr::set_enter_blink_mode (const char cap[]) { if ( cap ) { - F_enter_blink_mode.cap = cap; - F_enter_blink_mode.caused_reset = false; + F_blink.on.cap = cap; + F_blink.on.caused_reset = false; } } @@ -221,8 +221,8 @@ void FOptiAttr::set_exit_blink_mode (const char cap[]) { if ( cap ) { - F_exit_blink_mode.cap = cap; - F_exit_blink_mode.caused_reset = false; + F_blink.off.cap = cap; + F_blink.off.caused_reset = false; } } @@ -231,8 +231,8 @@ void FOptiAttr::set_enter_reverse_mode (const char cap[]) { if ( cap ) { - F_enter_reverse_mode.cap = cap; - F_enter_reverse_mode.caused_reset = false; + F_reverse.on.cap = cap; + F_reverse.on.caused_reset = false; } } @@ -241,8 +241,8 @@ void FOptiAttr::set_exit_reverse_mode (const char cap[]) { if ( cap ) { - F_exit_reverse_mode.cap = cap; - F_exit_reverse_mode.caused_reset = false; + F_reverse.off.cap = cap; + F_reverse.off.caused_reset = false; } } @@ -251,8 +251,8 @@ void FOptiAttr::set_enter_secure_mode (const char cap[]) { if ( cap ) { - F_enter_secure_mode.cap = cap; - F_enter_secure_mode.caused_reset = false; + F_secure.on.cap = cap; + F_secure.on.caused_reset = false; } } @@ -261,8 +261,8 @@ void FOptiAttr::set_exit_secure_mode (const char cap[]) { if ( cap ) { - F_exit_secure_mode.cap = cap; - F_exit_secure_mode.caused_reset = false; + F_secure.off.cap = cap; + F_secure.off.caused_reset = false; } } @@ -271,8 +271,8 @@ void FOptiAttr::set_enter_protected_mode (const char cap[]) { if ( cap ) { - F_enter_protected_mode.cap = cap; - F_enter_protected_mode.caused_reset = false; + F_protected.on.cap = cap; + F_protected.on.caused_reset = false; } } @@ -281,8 +281,8 @@ void FOptiAttr::set_exit_protected_mode (const char cap[]) { if ( cap ) { - F_exit_protected_mode.cap = cap; - F_exit_protected_mode.caused_reset = false; + F_protected.off.cap = cap; + F_protected.off.caused_reset = false; } } @@ -291,8 +291,8 @@ void FOptiAttr::set_enter_crossed_out_mode (const char cap[]) { if ( cap ) { - F_enter_crossed_out_mode.cap = cap; - F_enter_crossed_out_mode.caused_reset = false; + F_crossed_out.on.cap = cap; + F_crossed_out.on.caused_reset = false; } } @@ -301,8 +301,8 @@ void FOptiAttr::set_exit_crossed_out_mode (const char cap[]) { if ( cap ) { - F_exit_crossed_out_mode.cap = cap; - F_exit_crossed_out_mode.caused_reset = false; + F_crossed_out.off.cap = cap; + F_crossed_out.off.caused_reset = false; } } @@ -311,8 +311,8 @@ void FOptiAttr::set_enter_dbl_underline_mode (const char cap[]) { if ( cap ) { - F_enter_dbl_underline_mode.cap = cap; - F_enter_dbl_underline_mode.caused_reset = false; + F_dbl_underline.on.cap = cap; + F_dbl_underline.on.caused_reset = false; } } @@ -321,8 +321,8 @@ void FOptiAttr::set_exit_dbl_underline_mode (const char cap[]) { if ( cap ) { - F_exit_dbl_underline_mode.cap = cap; - F_exit_dbl_underline_mode.caused_reset = false; + F_dbl_underline.off.cap = cap; + F_dbl_underline.off.caused_reset = false; } } @@ -331,8 +331,8 @@ void FOptiAttr::set_enter_standout_mode (const char cap[]) { if ( cap ) { - F_enter_standout_mode.cap = cap; - F_enter_standout_mode.caused_reset = false; + F_standout.on.cap = cap; + F_standout.on.caused_reset = false; } } @@ -341,8 +341,8 @@ void FOptiAttr::set_exit_standout_mode (const char cap[]) { if ( cap ) { - F_exit_standout_mode.cap = cap; - F_exit_standout_mode.caused_reset = false; + F_standout.off.cap = cap; + F_standout.off.caused_reset = false; } } @@ -351,8 +351,8 @@ void FOptiAttr::set_set_attributes (const char cap[]) { if ( cap ) { - F_set_attributes.cap = cap; - F_set_attributes.caused_reset = true; + F_attributes.on.cap = cap; + F_attributes.on.caused_reset = true; } } @@ -361,8 +361,8 @@ void FOptiAttr::set_exit_attribute_mode (const char cap[]) { if ( cap ) { - F_exit_attribute_mode.cap = cap; - F_exit_attribute_mode.caused_reset = true; + F_attributes.off.cap = cap; + F_attributes.off.caused_reset = true; } } @@ -371,8 +371,8 @@ void FOptiAttr::set_enter_alt_charset_mode (const char cap[]) { if ( cap ) { - F_enter_alt_charset_mode.cap = cap; - F_enter_alt_charset_mode.caused_reset = false; + F_alt_charset.on.cap = cap; + F_alt_charset.on.caused_reset = false; } } @@ -381,8 +381,8 @@ void FOptiAttr::set_exit_alt_charset_mode (const char cap[]) { if ( cap ) { - F_exit_alt_charset_mode.cap = cap; - F_exit_alt_charset_mode.caused_reset = false; + F_alt_charset.off.cap = cap; + F_alt_charset.off.caused_reset = false; } } @@ -391,8 +391,8 @@ void FOptiAttr::set_enter_pc_charset_mode (const char cap[]) { if ( cap ) { - F_enter_pc_charset_mode.cap = cap; - F_enter_pc_charset_mode.caused_reset = false; + F_pc_charset.on.cap = cap; + F_pc_charset.on.caused_reset = false; } } @@ -401,8 +401,8 @@ void FOptiAttr::set_exit_pc_charset_mode (const char cap[]) { if ( cap ) { - F_exit_pc_charset_mode.cap = cap; - F_exit_pc_charset_mode.caused_reset = false; + F_pc_charset.off.cap = cap; + F_pc_charset.off.caused_reset = false; } } @@ -411,8 +411,8 @@ void FOptiAttr::set_a_foreground_color (const char cap[]) { if ( cap ) { - F_set_a_foreground.cap = cap; - F_set_a_foreground.caused_reset = false; + F_color.a_foreground.cap = cap; + F_color.a_foreground.caused_reset = false; } } @@ -421,8 +421,8 @@ void FOptiAttr::set_a_background_color (const char cap[]) { if ( cap ) { - F_set_a_background.cap = cap; - F_set_a_background.caused_reset = false; + F_color.a_background.cap = cap; + F_color.a_background.caused_reset = false; } } @@ -431,8 +431,8 @@ void FOptiAttr::set_foreground_color (const char cap[]) { if ( cap ) { - F_set_foreground.cap = cap; - F_set_foreground.caused_reset = false; + F_color.foreground.cap = cap; + F_color.foreground.caused_reset = false; } } @@ -441,8 +441,8 @@ void FOptiAttr::set_background_color (const char cap[]) { if ( cap ) { - F_set_background.cap = cap; - F_set_background.caused_reset = false; + F_color.background.cap = cap; + F_color.background.caused_reset = false; } } @@ -451,8 +451,8 @@ void FOptiAttr::set_term_color_pair (const char cap[]) { if ( cap ) { - F_set_color_pair.cap = cap; - F_set_color_pair.caused_reset = false; + F_color.color_pair.cap = cap; + F_color.color_pair.caused_reset = false; } } @@ -461,18 +461,18 @@ void FOptiAttr::set_orig_pair (const char cap[]) { if ( cap ) { - F_orig_pair.cap = cap; - F_orig_pair.caused_reset = false; + F_color.orig_pair.cap = cap; + F_color.orig_pair.caused_reset = false; } } //---------------------------------------------------------------------- -void FOptiAttr::set_orig_orig_colors (const char cap[]) +void FOptiAttr::set_orig_colors (const char cap[]) { if ( cap ) { - F_orig_colors.cap = cap; - F_orig_colors.caused_reset = false; + F_color.orig_colors.cap = cap; + F_color.orig_colors.caused_reset = false; } } @@ -485,42 +485,42 @@ auto FOptiAttr::isNormal (const FChar& ch) -> bool //---------------------------------------------------------------------- void FOptiAttr::initialize() { - monochron = max_color < 8; + F_color.monochron = F_color.max_color < 8; - if ( caused_reset_attributes(F_exit_bold_mode.cap) ) - F_exit_bold_mode.caused_reset = true; + if ( caused_reset_attributes(F_bold.off.cap) ) + F_bold.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_dim_mode.cap) ) - F_exit_dim_mode.caused_reset = true; + if ( caused_reset_attributes(F_dim.off.cap) ) + F_dim.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_italics_mode.cap) ) - F_exit_italics_mode.caused_reset = true; + if ( caused_reset_attributes(F_italics.off.cap) ) + F_italics.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_blink_mode.cap) ) - F_exit_blink_mode.caused_reset = true; + if ( caused_reset_attributes(F_blink.off.cap) ) + F_blink.off.caused_reset = true; - if ( caused_reset_attributes ( F_exit_underline_mode.cap + if ( caused_reset_attributes ( F_underline.off.cap , all_tests & ~same_like_ue) ) - F_exit_underline_mode.caused_reset = true; + F_underline.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_reverse_mode.cap) ) - F_exit_reverse_mode.caused_reset = true; + if ( caused_reset_attributes(F_reverse.off.cap) ) + F_reverse.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_secure_mode.cap) ) - F_exit_secure_mode.caused_reset = true; + if ( caused_reset_attributes(F_secure.off.cap) ) + F_secure.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_protected_mode.cap) ) - F_exit_protected_mode.caused_reset = true; + if ( caused_reset_attributes(F_protected.off.cap) ) + F_protected.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_crossed_out_mode.cap) ) - F_exit_crossed_out_mode.caused_reset = true; + if ( caused_reset_attributes(F_crossed_out.off.cap) ) + F_crossed_out.off.caused_reset = true; - if ( caused_reset_attributes(F_exit_dbl_underline_mode.cap) ) - F_exit_dbl_underline_mode.caused_reset = true; + if ( caused_reset_attributes(F_dbl_underline.off.cap) ) + F_dbl_underline.off.caused_reset = true; - if ( caused_reset_attributes ( F_exit_standout_mode.cap + if ( caused_reset_attributes ( F_standout.off.cap , all_tests & ~same_like_se) ) - F_exit_standout_mode.caused_reset = true; + F_standout.off.caused_reset = true; if ( hasCharsetEquivalence() ) alt_equal_pc_charset = true; @@ -579,7 +579,7 @@ auto FOptiAttr::changeAttribute (FChar& term, FChar& next) -> std::string detectSwitchOff (term, next); // Simulate invisible characters - if ( ! F_enter_secure_mode.cap && next.attr.bit.invisible ) + if ( ! F_secure.on.cap && next.attr.bit.invisible ) next.encoded_char[0] = ' '; // Look for no changes @@ -590,7 +590,7 @@ auto FOptiAttr::changeAttribute (FChar& term, FChar& next) -> std::string { deactivateAttributes (term, next); } - else if ( F_set_attributes.cap + else if ( F_attributes.on.cap && (! term.attr.bit.pc_charset || alt_equal_pc_charset) ) { changeAttributeSGR (term, next); @@ -614,7 +614,7 @@ auto FOptiAttr::changeAttribute (FChar& term, FChar& next) -> std::string inline auto FOptiAttr::setTermBold (FChar& term) -> bool { term.attr.bit.bold = true; - return append_sequence(F_enter_bold_mode.cap); + return append_sequence(F_bold.on.cap); } //---------------------------------------------------------------------- @@ -622,7 +622,7 @@ inline auto FOptiAttr::unsetTermBold (FChar& term) -> bool { // Back to normal intensity (turns off bold + dim) - if ( F_exit_bold_mode.caused_reset ) + if ( F_bold.off.caused_reset ) reset(term); else { @@ -630,14 +630,14 @@ inline auto FOptiAttr::unsetTermBold (FChar& term) -> bool term.attr.bit.dim = false; } - return append_sequence(F_exit_bold_mode.cap); + return append_sequence(F_bold.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermDim (FChar& term) -> bool { term.attr.bit.dim = true; - return append_sequence(F_enter_dim_mode.cap); + return append_sequence(F_dim.on.cap); } //---------------------------------------------------------------------- @@ -645,7 +645,7 @@ inline auto FOptiAttr::unsetTermDim (FChar& term) -> bool { // Back to normal intensity (turns off bold + dim) - if ( F_exit_dim_mode.caused_reset ) + if ( F_dim.off.caused_reset ) reset(term); else { @@ -653,32 +653,32 @@ inline auto FOptiAttr::unsetTermDim (FChar& term) -> bool term.attr.bit.dim = false; } - return append_sequence(F_exit_dim_mode.cap); + return append_sequence(F_dim.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermItalic (FChar& term) -> bool { term.attr.bit.italic = true; - return append_sequence(F_enter_italics_mode.cap); + return append_sequence(F_italics.on.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermItalic (FChar& term) -> bool { - if ( F_exit_italics_mode.caused_reset ) + if ( F_italics.off.caused_reset ) reset(term); else term.attr.bit.italic = false; - return append_sequence(F_exit_italics_mode.cap); + return append_sequence(F_italics.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermUnderline (FChar& term) -> bool { term.attr.bit.underline = true; - return append_sequence(F_enter_underline_mode.cap); + return append_sequence(F_underline.on.cap); } //---------------------------------------------------------------------- @@ -686,7 +686,7 @@ inline auto FOptiAttr::unsetTermUnderline (FChar& term) -> bool { // Turns off every underlining - if ( F_exit_underline_mode.caused_reset ) + if ( F_underline.off.caused_reset ) reset(term); else { @@ -694,43 +694,43 @@ inline auto FOptiAttr::unsetTermUnderline (FChar& term) -> bool term.attr.bit.dbl_underline = false; } - return append_sequence(F_exit_underline_mode.cap); + return append_sequence(F_underline.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermBlink (FChar& term) -> bool { term.attr.bit.blink = true; - return append_sequence(F_enter_blink_mode.cap); + return append_sequence(F_blink.on.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermBlink (FChar& term) -> bool { - if ( F_exit_blink_mode.caused_reset ) + if ( F_blink.off.caused_reset ) reset(term); else term.attr.bit.blink = false; - return append_sequence(F_exit_blink_mode.cap); + return append_sequence(F_blink.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermReverse (FChar& term) -> bool { term.attr.bit.reverse = true; - return ( ! fake_reverse && append_sequence(F_enter_reverse_mode.cap) ); + return ( ! fake_reverse && append_sequence(F_reverse.on.cap) ); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermReverse (FChar& term) -> bool { - if ( F_exit_reverse_mode.caused_reset ) + if ( F_reverse.off.caused_reset ) reset(term); else term.attr.bit.reverse = false; - return ( ! fake_reverse && append_sequence(F_exit_reverse_mode.cap) ); + return ( ! fake_reverse && append_sequence(F_reverse.off.cap) ); } //---------------------------------------------------------------------- @@ -738,79 +738,79 @@ inline auto FOptiAttr::setTermStandout (FChar& term) -> bool { term.attr.bit.standout = true; - return ( ! fake_reverse && append_sequence(F_enter_standout_mode.cap) ); + return ( ! fake_reverse && append_sequence(F_standout.on.cap) ); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermStandout (FChar& term) -> bool { - if ( F_exit_standout_mode.caused_reset ) + if ( F_standout.off.caused_reset ) reset(term); else term.attr.bit.standout = false; - return ( ! fake_reverse && append_sequence(F_exit_standout_mode.cap) ); + return ( ! fake_reverse && append_sequence(F_standout.off.cap) ); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermInvisible (FChar& term) -> bool { term.attr.bit.invisible = true; - return append_sequence(F_enter_secure_mode.cap); + return append_sequence(F_secure.on.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermInvisible (FChar& term) -> bool { - if ( F_exit_secure_mode.caused_reset ) + if ( F_secure.off.caused_reset ) reset(term); else term.attr.bit.invisible = false; - return append_sequence(F_exit_secure_mode.cap); + return append_sequence(F_secure.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermProtected (FChar& term) -> bool { term.attr.bit.protect = true; - return append_sequence(F_enter_protected_mode.cap); + return append_sequence(F_protected.on.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermProtected (FChar& term) -> bool { - if ( F_exit_protected_mode.caused_reset ) + if ( F_protected.off.caused_reset ) reset(term); else term.attr.bit.protect = false; - return append_sequence(F_exit_protected_mode.cap); + return append_sequence(F_protected.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermCrossedOut (FChar& term) -> bool { term.attr.bit.crossed_out = true; - return append_sequence(F_enter_crossed_out_mode.cap); + return append_sequence(F_crossed_out.on.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::unsetTermCrossedOut (FChar& term) -> bool { - if ( F_exit_crossed_out_mode.caused_reset ) + if ( F_crossed_out.off.caused_reset ) reset(term); else term.attr.bit.crossed_out = false; - return append_sequence(F_exit_crossed_out_mode.cap); + return append_sequence(F_crossed_out.off.cap); } //---------------------------------------------------------------------- inline auto FOptiAttr::setTermDoubleUnderline (FChar& term) -> bool { term.attr.bit.dbl_underline = true; - return append_sequence(F_enter_dbl_underline_mode.cap); + return append_sequence(F_dbl_underline.on.cap); } //---------------------------------------------------------------------- @@ -818,7 +818,7 @@ inline auto FOptiAttr::unsetTermDoubleUnderline (FChar& term) -> bool { // Turns off every underlining - if ( F_exit_dbl_underline_mode.caused_reset ) + if ( F_dbl_underline.off.caused_reset ) reset(term); else { @@ -826,15 +826,15 @@ inline auto FOptiAttr::unsetTermDoubleUnderline (FChar& term) -> bool term.attr.bit.dbl_underline = false; } - return append_sequence(F_exit_dbl_underline_mode.cap); + return append_sequence(F_dbl_underline.off.cap); } //---------------------------------------------------------------------- auto FOptiAttr::setTermAttributes (FChar& term, const TCapAttributes& attr) -> bool { - if ( F_set_attributes.cap ) + if ( F_attributes.on.cap ) { - const auto sgr = FTermcap::encodeParameter ( F_set_attributes.cap + const auto sgr = FTermcap::encodeParameter ( F_attributes.on.cap , attr.p1 && ! fake_reverse , attr.p2 , attr.p3 && ! fake_reverse @@ -869,7 +869,7 @@ auto FOptiAttr::setTermAttributes (FChar& term, const TCapAttributes& attr) -> b inline auto FOptiAttr::unsetTermAttributes (FChar& term) -> bool { reset(term); - return append_sequence(F_exit_attribute_mode.cap); + return append_sequence(F_attributes.off.cap); } //---------------------------------------------------------------------- @@ -880,7 +880,7 @@ inline auto FOptiAttr::setTermAltCharset (FChar& term) -> bool if ( alt_equal_pc_charset && term.attr.bit.pc_charset ) return false; - return append_sequence(F_enter_alt_charset_mode.cap); + return append_sequence(F_alt_charset.on.cap); } //---------------------------------------------------------------------- @@ -891,7 +891,7 @@ inline auto FOptiAttr::unsetTermAltCharset (FChar& term) -> bool if ( alt_equal_pc_charset && term.attr.bit.pc_charset ) return false; - return append_sequence(F_exit_alt_charset_mode.cap); + return append_sequence(F_alt_charset.off.cap); } //---------------------------------------------------------------------- @@ -902,7 +902,7 @@ inline auto FOptiAttr::setTermPCcharset (FChar& term) -> bool if ( alt_equal_pc_charset && term.attr.bit.alt_charset ) return false; - return append_sequence(F_enter_pc_charset_mode.cap); + return append_sequence(F_pc_charset.on.cap); } //---------------------------------------------------------------------- @@ -913,7 +913,7 @@ inline auto FOptiAttr::unsetTermPCcharset (FChar& term) -> bool if ( alt_equal_pc_charset && term.attr.bit.alt_charset ) return false; - return append_sequence(F_exit_pc_charset_mode.cap); + return append_sequence(F_pc_charset.off.cap); } //---------------------------------------------------------------------- @@ -922,11 +922,11 @@ auto FOptiAttr::setTermDefaultColor (FChar& term) -> bool term.fg_color = FColor::Default; term.bg_color = FColor::Default; - if ( append_sequence(F_orig_pair.cap) - || append_sequence(F_orig_colors.cap) ) + if ( append_sequence(F_color.orig_pair.cap) + || append_sequence(F_color.orig_colors.cap) ) return true; - if ( ansi_default_color ) + if ( F_color.ansi_default_color ) { std::string sgr_39_49{CSI "39;49m"}; append_sequence (sgr_39_49); @@ -1023,10 +1023,10 @@ inline void FOptiAttr::prevent_no_color_video_attributes ( FChar& attr { // Ignore attributes which can not combined with a color - if ( ! (hasColor(attr) || next_has_color) || attr_without_color <= 0 ) + if ( ! (hasColor(attr) || next_has_color) || F_color.attr_without_color <= 0 ) return; - auto set_bits = uInt(attr_without_color); + auto set_bits = uInt(F_color.attr_without_color); while ( set_bits ) { @@ -1086,7 +1086,7 @@ inline void FOptiAttr::deactivateAttributes (FChar& term, FChar& next) { if ( hasAttribute(term) ) { - if ( F_exit_attribute_mode.cap ) + if ( F_attributes.off.cap ) { if ( off.attr.bit.alt_charset ) // Required for rxvt terminals unsetTermAltCharset(term); @@ -1122,7 +1122,7 @@ inline void FOptiAttr::changeAttributeSGR (FChar& term, FChar& next) , next.attr.bit.alt_charset } ); if ( alt_equal_pc_charset - && F_enter_pc_charset_mode.cap + && F_pc_charset.on.cap && next.attr.bit.alt_charset ) { term.attr.bit.pc_charset = next.attr.bit.pc_charset; @@ -1165,7 +1165,7 @@ inline void FOptiAttr::changeAttributeSeparately (FChar& term, FChar& next) //---------------------------------------------------------------------- void FOptiAttr::change_color (FChar& term, FChar& next) { - if ( monochron ) + if ( F_color.monochron ) { next.fg_color = FColor::Default; next.bg_color = FColor::Default; @@ -1173,10 +1173,10 @@ void FOptiAttr::change_color (FChar& term, FChar& next) } if ( next.fg_color != FColor::Default ) - next.fg_color %= uInt16(max_color); + next.fg_color %= uInt16(F_color.max_color); if ( next.bg_color != FColor::Default ) - next.bg_color %= uInt16(max_color); + next.bg_color %= uInt16(F_color.max_color); FColor fg = next.fg_color; FColor bg = next.bg_color; @@ -1206,7 +1206,7 @@ void FOptiAttr::change_color (FChar& term, FChar& next) inline void FOptiAttr::change_to_default_color ( FChar& term, FChar& next , FColor& fg, FColor& bg ) { - if ( ansi_default_color ) + if ( F_color.ansi_default_color ) { if ( fg == FColor::Default && term.fg_color != FColor::Default && bg == FColor::Default && term.bg_color != FColor::Default ) @@ -1222,7 +1222,7 @@ inline void FOptiAttr::change_to_default_color ( FChar& term, FChar& next else if ( bg == FColor::Default && term.bg_color != FColor::Default ) { const char* sgr_49; - const auto& op = F_orig_pair.cap; + const auto& op = F_color.orig_pair.cap; if ( op && std::memcmp (op, CSI "39;49;25m", 11) == 0 ) sgr_49 = CSI "49;25m"; @@ -1245,11 +1245,11 @@ inline void FOptiAttr::change_to_default_color ( FChar& term, FChar& next inline void FOptiAttr::change_current_color ( const FChar& term , FColor fg, FColor bg ) { - const auto& AF = F_set_a_foreground.cap; - const auto& AB = F_set_a_background.cap; - const auto& Sf = F_set_foreground.cap; - const auto& Sb = F_set_background.cap; - const auto& sp = F_set_color_pair.cap; + const auto& AF = F_color.a_foreground.cap; + const auto& AB = F_color.a_background.cap; + const auto& Sf = F_color.foreground.cap; + const auto& Sb = F_color.background.cap; + const auto& sp = F_color.color_pair.cap; const auto& b0_reverse_mask = internal::var::b0_reverse_mask; const bool frev ( ( (off.attr.byte[0] & b0_reverse_mask) || (term.attr.byte[0] & b0_reverse_mask) ) && fake_reverse ); @@ -1316,9 +1316,9 @@ auto FOptiAttr::caused_reset_attributes (const char cap[], uChar test) const -> if ( cap ) { - const auto& ue = F_exit_underline_mode.cap; - const auto& se = F_exit_standout_mode.cap; - const auto& me = F_exit_attribute_mode.cap; + const auto& ue = F_underline.off.cap; + const auto& se = F_standout.off.cap; + const auto& me = F_attributes.off.cap; if ( (test & test_ansi_reset) && std::memcmp (cap, CSI "m", 3) == 0 ) return true; @@ -1346,10 +1346,10 @@ inline auto FOptiAttr::hasCharsetEquivalence() const -> bool { // Detect if alt charset and pc charset are the same sequences - const auto& alt_on = F_enter_alt_charset_mode.cap; - const auto& alt_off = F_enter_pc_charset_mode.cap; - const auto& pc_on = F_enter_pc_charset_mode.cap; - const auto& pc_off = F_exit_pc_charset_mode.cap; + const auto& alt_on = F_alt_charset.on.cap; + const auto& alt_off = F_alt_charset.off.cap; + const auto& pc_on = F_pc_charset.on.cap; + const auto& pc_off = F_pc_charset.off.cap; if ( alt_on && pc_on && std::strcmp (alt_on, pc_on) == 0 ) return true; diff --git a/final/output/tty/foptiattr.h b/final/output/tty/foptiattr.h index 68bcbe66..3e0b19d5 100644 --- a/final/output/tty/foptiattr.h +++ b/final/output/tty/foptiattr.h @@ -54,46 +54,43 @@ namespace finalcut class FOptiAttr final { public: + struct TermEnvTextStyle + { + const char* on; + const char* off; + }; + + struct TermEnvColorStyle + { + const char* a_foreground; + const char* a_background; + const char* foreground; + const char* background; + const char* color_pair; + const char* orig_pair; + const char* orig_colors; + int max_color; + int attr_without_color; + bool ansi_default_color; + }; + struct TermEnv { - const char* t_enter_bold_mode; - const char* t_exit_bold_mode; - const char* t_enter_dim_mode; - const char* t_exit_dim_mode; - const char* t_enter_italics_mode; - const char* t_exit_italics_mode; - const char* t_enter_underline_mode; - const char* t_exit_underline_mode; - const char* t_enter_blink_mode; - const char* t_exit_blink_mode; - const char* t_enter_reverse_mode; - const char* t_exit_reverse_mode; - const char* t_enter_standout_mode; - const char* t_exit_standout_mode; - const char* t_enter_secure_mode; - const char* t_exit_secure_mode; - const char* t_enter_protected_mode; - const char* t_exit_protected_mode; - const char* t_enter_crossed_out_mode; - const char* t_exit_crossed_out_mode; - const char* t_enter_dbl_underline_mode; - const char* t_exit_dbl_underline_mode; - const char* t_set_attributes; - const char* t_exit_attribute_mode; - const char* t_enter_alt_charset_mode; - const char* t_exit_alt_charset_mode; - const char* t_enter_pc_charset_mode; - const char* t_exit_pc_charset_mode; - const char* t_set_a_foreground; - const char* t_set_a_background; - const char* t_set_foreground; - const char* t_set_background; - const char* t_set_color_pair; - const char* t_orig_pair; - const char* t_orig_colors; - int max_color; - int attr_without_color; - bool ansi_default_color; + TermEnvTextStyle t_set_bold; + TermEnvTextStyle t_set_dim; + TermEnvTextStyle t_set_italics; + TermEnvTextStyle t_set_underline; + TermEnvTextStyle t_set_blink; + TermEnvTextStyle t_set_reverse; + TermEnvTextStyle t_set_standout; + TermEnvTextStyle t_set_secure; + TermEnvTextStyle t_set_protected; + TermEnvTextStyle t_set_crossed_out; + TermEnvTextStyle t_set_dbl_underline; + TermEnvTextStyle t_set_attributes; + TermEnvTextStyle t_set_alt_charset; + TermEnvTextStyle t_set_pc_charset; + TermEnvColorStyle t_set_color; }; // Constructor @@ -143,7 +140,7 @@ class FOptiAttr final void set_background_color (const char[]); void set_term_color_pair (const char[]); void set_orig_pair (const char[]); - void set_orig_orig_colors (const char[]); + void set_orig_colors (const char[]); // Inquiry static auto isNormal (const FChar&) -> bool; @@ -156,8 +153,29 @@ class FOptiAttr final private: struct Capability { - const char* cap; - bool caused_reset; + const char* cap{}; + bool caused_reset{}; + }; + + struct TextStyle + { + Capability on{}; + Capability off{}; + }; + + struct ColorStyle + { + Capability a_foreground{}; + Capability a_background{}; + Capability foreground{}; + Capability background{}; + Capability color_pair{}; + Capability orig_pair{}; + Capability orig_colors{}; + int attr_without_color{0}; + int max_color{1}; + bool monochron{true}; + bool ansi_default_color{false}; }; // Using-declarations @@ -277,51 +295,27 @@ class FOptiAttr final auto append_sequence (const std::string&) -> bool; // Data members - Capability F_enter_bold_mode{}; - Capability F_exit_bold_mode{}; - Capability F_enter_dim_mode{}; - Capability F_exit_dim_mode{}; - Capability F_enter_italics_mode{}; - Capability F_exit_italics_mode{}; - Capability F_enter_underline_mode{}; - Capability F_exit_underline_mode{}; - Capability F_enter_blink_mode{}; - Capability F_exit_blink_mode{}; - Capability F_enter_reverse_mode{}; - Capability F_exit_reverse_mode{}; - Capability F_enter_standout_mode{}; - Capability F_exit_standout_mode{}; - Capability F_enter_secure_mode{}; - Capability F_exit_secure_mode{}; - Capability F_enter_protected_mode{}; - Capability F_exit_protected_mode{}; - Capability F_enter_crossed_out_mode{}; - Capability F_exit_crossed_out_mode{}; - Capability F_enter_dbl_underline_mode{}; - Capability F_exit_dbl_underline_mode{}; - Capability F_set_attributes{}; - Capability F_exit_attribute_mode{}; - Capability F_enter_alt_charset_mode{}; - Capability F_exit_alt_charset_mode{}; - Capability F_enter_pc_charset_mode{}; - Capability F_exit_pc_charset_mode{}; - Capability F_set_a_foreground{}; - Capability F_set_a_background{}; - Capability F_set_foreground{}; - Capability F_set_background{}; - Capability F_set_color_pair{}; - Capability F_orig_pair{}; - Capability F_orig_colors{}; + TextStyle F_bold{}; + TextStyle F_dim{}; + TextStyle F_italics{}; + TextStyle F_underline{}; + TextStyle F_blink{}; + TextStyle F_reverse{}; + TextStyle F_standout{}; + TextStyle F_secure{}; + TextStyle F_protected{}; + TextStyle F_crossed_out{}; + TextStyle F_dbl_underline{}; + TextStyle F_attributes{}; + TextStyle F_alt_charset{}; + TextStyle F_pc_charset{}; + ColorStyle F_color{}; FChar on{}; FChar off{}; std::string attr_buf{}; SGRoptimizer sgr_optimizer{attr_buf}; - int max_color{1}; - int attr_without_color{0}; - bool ansi_default_color{false}; bool alt_equal_pc_charset{false}; - bool monochron{true}; bool fake_reverse{false}; }; @@ -333,19 +327,19 @@ inline auto FOptiAttr::getClassName() const -> FString //---------------------------------------------------------------------- inline void FOptiAttr::setMaxColor (const int& c) noexcept -{ max_color = c; } +{ F_color.max_color = c; } //---------------------------------------------------------------------- inline void FOptiAttr::setNoColorVideo (int attr) noexcept -{ attr_without_color = attr; } +{ F_color.attr_without_color = attr; } //---------------------------------------------------------------------- inline void FOptiAttr::setDefaultColorSupport() noexcept -{ ansi_default_color = true; } +{ F_color.ansi_default_color = true; } //---------------------------------------------------------------------- inline void FOptiAttr::unsetDefaultColorSupport() noexcept -{ ansi_default_color = false; } +{ F_color.ansi_default_color = false; } //---------------------------------------------------------------------- template bool; static auto scrollTermReverse() -> bool; - template - static void paddingPrintf (StringT&&, Args&&...); + template + static void paddingPrintf (Args&&...); static void paddingPrint (const std::string&, int = 1); static void stringPrint (const std::string&); @@ -315,19 +315,18 @@ inline void FTerm::unsetUTF8() { setUTF8(false); } //---------------------------------------------------------------------- -template -inline void FTerm::paddingPrintf (StringT&& format, Args&&... args) +template +inline void FTerm::paddingPrintf (Args&&... args) { - const int size = std::snprintf (nullptr, 0, format, args...); + const int size = std::snprintf (nullptr, 0, args...); if ( size <= 0 ) return; std::string buffer{}; - auto buffer_size = std::size_t(size + 1); + auto buffer_size = std::size_t(size) + 1; buffer.resize(buffer_size); std::snprintf ( &*buffer.begin(), buffer_size - , std::forward(format) , std::forward(args)... ); buffer_size--; buffer.resize(buffer_size); diff --git a/final/output/tty/ftermcapquirks.cpp b/final/output/tty/ftermcapquirks.cpp index 4e82dcde..c134efef 100644 --- a/final/output/tty/ftermcapquirks.cpp +++ b/final/output/tty/ftermcapquirks.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -59,49 +60,27 @@ constexpr void setTCapStringIfNotSet (CapabilityT& cap, StringT&& string) void FTermcapQuirks::terminalFixup() { static const auto& fterm_data = FTermData::getInstance(); - - if ( fterm_data.isTermType(FTermType::cygwin) ) - { - cygwin(); - } - else if ( fterm_data.isTermType(FTermType::linux_con) ) - { - linux(); - } - else if ( fterm_data.isTermType(FTermType::rxvt) ) - { - rxvt(); - } - else if ( fterm_data.isTermType(FTermType::gnome_terminal) ) - { - vte(); - } - else if ( fterm_data.isTermType(FTermType::kitty) ) + using HandlerMap = std::unordered_map> ; + HandlerMap term_handlers = { - kitty(); - } - else if ( fterm_data.isTermType(FTermType::tera_term) ) - { - teraterm(); - } - else if ( fterm_data.isTermType(FTermType::sun_con) ) - { - sunConsole(); - } - else if ( fterm_data.isTermType(FTermType::putty) ) - { - putty(); - } - else if ( fterm_data.isTermType(FTermType::screen) ) - { - screen(); - } + { FTermType::cygwin , &FTermcapQuirks::cygwin }, + { FTermType::linux_con , &FTermcapQuirks::linux }, + { FTermType::rxvt , &FTermcapQuirks::rxvt }, + { FTermType::gnome_terminal , &FTermcapQuirks::vte }, + { FTermType::kitty , &FTermcapQuirks::kitty }, + { FTermType::tera_term , &FTermcapQuirks::teraterm }, + { FTermType::sun_con , &FTermcapQuirks::sunConsole }, + { FTermType::putty , &FTermcapQuirks::putty }, + { FTermType::screen , &FTermcapQuirks::screen } #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - else if ( fterm_data.isTermType(FTermType::freebsd_con) ) - { - freebsd(); - } -#endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + , + { FTermType::freebsd_con , &FTermcapQuirks::freebsd } +#endif + }; + + for (const auto& handler : term_handlers) + if ( fterm_data.isTermType(handler.first) ) + handler.second(); // xterm and compatible terminals if ( fterm_data.isTermType(FTermType::xterm) diff --git a/final/output/tty/ftermdetection.cpp b/final/output/tty/ftermdetection.cpp index 71c2bbc1..5340343a 100644 --- a/final/output/tty/ftermdetection.cpp +++ b/final/output/tty/ftermdetection.cpp @@ -284,7 +284,7 @@ void FTermDetection::termtypeAnalysis() if ( termtype.left(12) == "rxvt-unicode" ) fterm_data.setTermType (FTermType::urxvt); - // screen/tmux + // screen or tmux with termtype screen if ( termtype.left(6) == "screen" ) { fterm_data.setTermType (FTermType::screen); @@ -294,6 +294,13 @@ void FTermDetection::termtypeAnalysis() fterm_data.setTermType (FTermType::tmux); } + // tmux + if ( termtype.left(4) == "tmux" ) + { + fterm_data.setTermType (FTermType::screen); + fterm_data.setTermType (FTermType::tmux); + } + // Linux console if ( termtype.left(5) == "linux" || termtype.left(3) == "con" ) fterm_data.setTermType (FTermType::linux_con); diff --git a/final/util/fdata.h b/final/util/fdata.h index 2199ad5c..28a24ffe 100644 --- a/final/util/fdata.h +++ b/final/util/fdata.h @@ -55,14 +55,23 @@ class FData; // Class forward declaration namespace internal { +// Enumerations +enum class IsArray { No, Yes }; +enum class IsFunction { No, Yes }; + +// Define the clean condition template ::value - , bool isFunction = std::is_function::value> + , IsArray is_array = std::is_array::value + ? IsArray::Yes + : IsArray::No + , IsFunction is_function = std::is_function::value + ? IsFunction::Yes + : IsFunction::No> struct cleanCondition; //---------------------------------------------------------------------- template -struct cleanCondition +struct cleanCondition { // Leave the type untouched using type = T; @@ -70,7 +79,7 @@ struct cleanCondition //---------------------------------------------------------------------- template -struct cleanCondition +struct cleanCondition { // Array to pointer using type = std::remove_extent_t*; @@ -78,7 +87,7 @@ struct cleanCondition //---------------------------------------------------------------------- template -struct cleanCondition +struct cleanCondition { // Add pointer to function using type = std::add_pointer_t; diff --git a/final/util/flog.h b/final/util/flog.h index 6ba968c3..557c9a7b 100644 --- a/final/util/flog.h +++ b/final/util/flog.h @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2020-2022 Markus Gans * +* Copyright 2020-2023 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -81,7 +81,7 @@ class FLog : public std::stringbuf ~FLog() override; template - auto operator << (const T& s) -> FLog&; + auto operator << (const T&) -> FLog&; auto operator << (IOManip) -> FLog&; auto operator << (LogLevel) -> FLog&; diff --git a/test/foptiattr-test.cpp b/test/foptiattr-test.cpp index 454c25fc..cffa0027 100644 --- a/test/foptiattr-test.cpp +++ b/test/foptiattr-test.cpp @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2018-2022 Markus Gans * +* Copyright 2018-2023 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -178,7 +178,7 @@ void FOptiAttrTest::sgrOptimizerTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49m"); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); finalcut::FChar from{}; @@ -387,7 +387,7 @@ void FOptiAttrTest::fakeReverseTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (nullptr); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); finalcut::FChar from{}; @@ -480,7 +480,7 @@ void FOptiAttrTest::ansiTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49m"); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); finalcut::FChar from{}; @@ -943,7 +943,7 @@ void FOptiAttrTest::vt100Test() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (nullptr); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); finalcut::FChar from{}; @@ -1409,7 +1409,7 @@ void FOptiAttrTest::xtermTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49m"); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); finalcut::FChar from{}; @@ -1878,7 +1878,7 @@ void FOptiAttrTest::rxvtTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49m"); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); finalcut::FChar from{}; @@ -2348,7 +2348,7 @@ void FOptiAttrTest::linuxTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49;25m"); - oa.set_orig_orig_colors (OSC "R"); + oa.set_orig_colors (OSC "R"); oa.initialize(); finalcut::FChar from{}; @@ -2822,7 +2822,7 @@ void FOptiAttrTest::puttyTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49m"); - oa.set_orig_orig_colors (OSC "R"); + oa.set_orig_colors (OSC "R"); oa.initialize(); @@ -3292,7 +3292,7 @@ void FOptiAttrTest::teratermTest() oa.set_background_color (nullptr); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "39;49m"); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); @@ -3763,10 +3763,9 @@ void FOptiAttrTest::ibmColorTest() "%e%p1%{7}%=%t107m%;"); oa.set_term_color_pair (nullptr); oa.set_orig_pair (CSI "32;40m"); - oa.set_orig_orig_colors (nullptr); + oa.set_orig_colors (nullptr); oa.initialize(); - finalcut::FChar from{}; finalcut::FChar to{}; CPPUNIT_ASSERT ( oa.changeAttribute(from, to).empty() ); diff --git a/test/fstringstream-test.cpp b/test/fstringstream-test.cpp index 0319dcd1..1ed00569 100644 --- a/test/fstringstream-test.cpp +++ b/test/fstringstream-test.cpp @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2020-2021 Markus Gans * +* Copyright 2020-2023 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -208,11 +208,11 @@ void FStringStreamTest::fileTest() file_stream.close(); } - std::string line{}; std::ifstream file_stream{filename}; if ( ! file_stream.eof() && file_stream.good() ) { + std::string line{}; getline(file_stream, line); CPPUNIT_ASSERT ( line == "FStringStream file test" ); } diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index a9dfff12..3fd5dc29 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -21,7 +21,10 @@ ***********************************************************************/ #include -#undef buttons // from term.h +#undef buttons // from term.h +#undef orig_pair // from term.h +#undef orig_colors // from term.h + #include #include diff --git a/test/ftermlinux-test.cpp b/test/ftermlinux-test.cpp index a036277a..1d08d52a 100644 --- a/test/ftermlinux-test.cpp +++ b/test/ftermlinux-test.cpp @@ -21,7 +21,9 @@ ***********************************************************************/ #include -#undef buttons // from term.h +#undef buttons // from term.h +#undef orig_pair // from term.h +#undef orig_colors // from term.h #include #include @@ -1761,7 +1763,6 @@ auto FSystemTest::ioctl (int file_descriptor, uLong request, ...) -> int req_string = "PIO_UNIMAP"; auto umap = static_cast(argp); 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 ) @@ -1781,6 +1782,7 @@ auto FSystemTest::ioctl (int file_descriptor, uLong request, ...) -> int if ( umap->entries ) { + std::size_t pairs_size = pairs * sizeof(unipair); std::memcpy (terminal_unicode_map.entries, umap->entries, pairs_size); errno = 0; ret_val = 0; diff --git a/test/ftermopenbsd-test.cpp b/test/ftermopenbsd-test.cpp index b983beb5..37d932cc 100644 --- a/test/ftermopenbsd-test.cpp +++ b/test/ftermopenbsd-test.cpp @@ -21,7 +21,9 @@ ***********************************************************************/ #include -#undef buttons // from term.h +#undef buttons // from term.h +#undef orig_pair // from term.h +#undef orig_colors // from term.h #include #include diff --git a/test/fwidget-test.cpp b/test/fwidget-test.cpp index 5a3ecf8c..01b631c7 100644 --- a/test/fwidget-test.cpp +++ b/test/fwidget-test.cpp @@ -914,7 +914,7 @@ void FWidgetTest::resetColorsTest() class TestWidget : public finalcut::FWidget { public: - TestWidget (finalcut::FWidget* parent = nullptr) + explicit TestWidget (finalcut::FWidget* parent = nullptr) : finalcut::FWidget{parent} { }