@@ -39,56 +39,76 @@ namespace finalcut
3939namespace internal
4040{
4141
42- constexpr auto getReverseMask () noexcept -> uInt32
42+ template <typename F>
43+ constexpr auto createMask (F setter) noexcept -> uInt32
4344{
4445 FCharAttribute mask{};
45- mask.reverse = true ;
46- mask.standout = true ;
46+ setter (mask);
4747 return FCharAttribute_to_uInt32 (mask);
4848}
4949
50- constexpr auto getAttributeMask ( ) noexcept -> uInt32
50+ constexpr void setReverseMask (FCharAttribute& attr ) noexcept
5151{
52- FCharAttribute mask{};
53- mask.bold = true ;
54- mask.dim = true ;
55- mask.italic = true ;
56- mask.underline = true ;
57- mask.blink = true ;
58- mask.reverse = true ;
59- mask.standout = true ;
60- mask.invisible = true ;
61- mask.protect = true ;
62- mask.crossed_out = true ;
63- mask.dbl_underline = true ;
64- mask.alt_charset = true ;
65- mask.pc_charset = true ;
66- return FCharAttribute_to_uInt32 (mask);
52+ attr.reverse = true ;
53+ attr.standout = true ;
54+ }
55+
56+ constexpr void setAltCharsetMask (FCharAttribute& attr) noexcept
57+ {
58+ attr.alt_charset = true ;
6759}
6860
69- constexpr auto getResetMask () noexcept -> uInt32
61+ constexpr void setPcCharsetMask (FCharAttribute& attr) noexcept
62+ {
63+ attr.pc_charset = true ;
64+ }
65+
66+ constexpr void setAttributeMask (FCharAttribute& attr) noexcept
67+ {
68+ attr.bold = true ;
69+ attr.dim = true ;
70+ attr.italic = true ;
71+ attr.underline = true ;
72+ attr.blink = true ;
73+ attr.reverse = true ;
74+ attr.standout = true ;
75+ attr.invisible = true ;
76+ attr.protect = true ;
77+ attr.crossed_out = true ;
78+ attr.dbl_underline = true ;
79+ attr.alt_charset = true ;
80+ attr.pc_charset = true ;
81+ }
82+
83+ constexpr void setResetMask (FCharAttribute& attr) noexcept
7084{
7185 // Set bits that must not be reset
72- FCharAttribute mask{};
73- mask.transparent = true ;
74- mask.color_overlay = true ;
75- mask.inherit_background = true ;
76- mask.no_changes = true ;
77- mask.printed = true ;
78- return FCharAttribute_to_uInt32 (mask);
86+ attr.transparent = true ;
87+ attr.color_overlay = true ;
88+ attr.inherit_background = true ;
89+ attr.no_changes = true ;
90+ attr.printed = true ;
7991}
8092
8193struct var
8294{
83- static constexpr auto reverse_mask = getReverseMask();
84- static constexpr auto attribute_mask = getAttributeMask();
85- static constexpr auto reset_mask = getResetMask();
86- static constexpr char sgr_39[] = {CSI " 39m" };
87- static constexpr char sgr_39_49[] = {CSI " 39;49m" };
95+ static constexpr auto reverse_mask = createMask(setReverseMask);
96+ static constexpr auto alt_charset_mask = createMask(setAltCharsetMask);
97+ static constexpr auto pc_charset_mask = createMask(setPcCharsetMask);
98+ static constexpr auto attribute_mask = createMask(setAttributeMask);
99+ static constexpr auto alt_charset_reset_mask = ~alt_charset_mask;
100+ static constexpr auto pc_charset_reset_mask = ~pc_charset_mask;
101+ static constexpr auto reset_mask = createMask(setResetMask);
102+ static constexpr char sgr_39[] = {CSI " 39m" };
103+ static constexpr char sgr_39_49[] = {CSI " 39;49m" };
88104};
89105
90106constexpr uInt32 var::reverse_mask;
107+ constexpr uInt32 var::alt_charset_mask;
108+ constexpr uInt32 var::pc_charset_mask;
91109constexpr uInt32 var::attribute_mask;
110+ constexpr uInt32 var::alt_charset_reset_mask;
111+ constexpr uInt32 var::pc_charset_reset_mask;
92112constexpr uInt32 var::reset_mask;
93113constexpr char var::sgr_39[];
94114constexpr char var::sgr_39_49[];
@@ -468,7 +488,7 @@ auto FOptiAttr::changeAttribute (FChar& term, FChar& next) -> std::string
468488 deactivateAttributes (term, next);
469489 }
470490 else if ( F_attributes.on .cap
471- && (! term.attr .bit . pc_charset || alt_equal_pc_charset) )
491+ && (! ( term.attr .data & internal::var::pc_charset_mask) || alt_equal_pc_charset) )
472492 {
473493 changeAttributeSGR (term, next);
474494 }
@@ -780,9 +800,10 @@ inline auto FOptiAttr::unsetTermAttributes (FChar& term) noexcept -> bool
780800// ----------------------------------------------------------------------
781801inline auto FOptiAttr::setTermAltCharset (FChar& term) noexcept -> bool
782802{
783- term.attr .bit . alt_charset = true ;
803+ term.attr .data |= internal::var::alt_charset_mask ;
784804
785- if ( alt_equal_pc_charset && term.attr .bit .pc_charset )
805+ if ( alt_equal_pc_charset
806+ && term.attr .data & internal::var::pc_charset_mask )
786807 return false ;
787808
788809 return append_sequence (F_alt_charset.on .cap );
@@ -791,9 +812,10 @@ inline auto FOptiAttr::setTermAltCharset (FChar& term) noexcept -> bool
791812// ----------------------------------------------------------------------
792813inline auto FOptiAttr::unsetTermAltCharset (FChar& term) noexcept -> bool
793814{
794- term.attr .bit . alt_charset = false ;
815+ term.attr .data &= internal::var::alt_charset_reset_mask ;
795816
796- if ( alt_equal_pc_charset && term.attr .bit .pc_charset )
817+ if ( alt_equal_pc_charset
818+ && term.attr .data & internal::var::pc_charset_mask )
797819 return false ;
798820
799821 return append_sequence (F_alt_charset.off .cap );
@@ -802,9 +824,10 @@ inline auto FOptiAttr::unsetTermAltCharset (FChar& term) noexcept -> bool
802824// ----------------------------------------------------------------------
803825inline auto FOptiAttr::setTermPCcharset (FChar& term) noexcept -> bool
804826{
805- term.attr .bit . pc_charset = true ;
827+ term.attr .data |= internal::var::pc_charset_mask ;
806828
807- if ( alt_equal_pc_charset && term.attr .bit .alt_charset )
829+ if ( alt_equal_pc_charset
830+ && term.attr .data & internal::var::alt_charset_mask )
808831 return false ;
809832
810833 return append_sequence (F_pc_charset.on .cap );
@@ -813,9 +836,10 @@ inline auto FOptiAttr::setTermPCcharset (FChar& term) noexcept -> bool
813836// ----------------------------------------------------------------------
814837inline auto FOptiAttr::unsetTermPCcharset (FChar& term) noexcept -> bool
815838{
816- term.attr .bit . pc_charset = false ;
839+ term.attr .data &= internal::var::pc_charset_reset_mask ;
817840
818- if ( alt_equal_pc_charset && term.attr .bit .alt_charset )
841+ if ( alt_equal_pc_charset
842+ && term.attr .data & internal::var::alt_charset_mask )
819843 return false ;
820844
821845 return append_sequence (F_pc_charset.off .cap );
@@ -923,7 +947,8 @@ inline auto FOptiAttr::isDoubleUnderlineUsed ( const FChar& term
923947inline auto FOptiAttr::isPCcharsetUsed ( const FChar& term
924948 , const FChar& next ) const noexcept -> bool
925949{
926- return ! term.attr .bit .pc_charset && next.attr .bit .pc_charset ;
950+ return ! (term.attr .data & internal::var::pc_charset_mask)
951+ && next.attr .data & internal::var::pc_charset_mask;
927952}
928953
929954// ----------------------------------------------------------------------
@@ -932,10 +957,10 @@ inline auto FOptiAttr::isPCcharsetUsable ( FChar& term
932957{
933958 if ( alt_equal_pc_charset
934959 && F_pc_charset.on .cap
935- && next.attr .bit . alt_charset )
960+ && next.attr .data & internal::var::alt_charset_mask )
936961 {
937962 term.attr .bit .pc_charset = next.attr .bit .pc_charset ;
938- changes.off .attr .bit . pc_charset = false ;
963+ changes.off .attr .data &= internal::var::pc_charset_reset_mask ;
939964 return false ;
940965 }
941966
@@ -995,12 +1020,12 @@ inline void FOptiAttr::deactivateAttributes (FChar& term, FChar& next)
9951020 {
9961021 if ( F_attributes.off .cap )
9971022 {
998- if ( changes.off .attr .bit . alt_charset ) // Required for rxvt terminals
1023+ if ( changes.off .attr .data & internal::var::alt_charset_mask ) // Required for rxvt terminals
9991024 unsetTermAltCharset (term);
10001025
10011026 unsetTermAttributes (term);
10021027
1003- if ( changes.off .attr .bit . pc_charset )
1028+ if ( changes.off .attr .data & internal::var::pc_charset_mask )
10041029 unsetTermPCcharset (term);
10051030 }
10061031 else
@@ -1028,7 +1053,7 @@ inline void FOptiAttr::changeAttributeSGR (FChar& term, FChar& next)
10281053
10291054 const auto pc_charset_usable = isPCcharsetUsable (term, next);
10301055
1031- if ( changes.off .attr .bit . pc_charset )
1056+ if ( changes.off .attr .data & internal::var::pc_charset_mask )
10321057 unsetTermPCcharset (term);
10331058
10341059 if ( isItalicsUsed (term, next) )
0 commit comments