finalcut/src/foptiattr.cpp

1667 lines
43 KiB
C++
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* foptiattr.cpp - Sets video attributes in optimized order *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2016-2019 Markus Gans *
2017-11-04 07:03:53 +01:00
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <cstring>
#include "final/fc.h"
#include "final/foptiattr.h"
2019-12-31 06:32:51 +01:00
#include "final/fstartoptions.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FOptiAttr
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FOptiAttr::FOptiAttr()
{
// Set bits that must not be reset
reset_byte_mask.attr.bit.transparent = true;
reset_byte_mask.attr.bit.trans_shadow = true;
reset_byte_mask.attr.bit.inherit_bg = true;
reset_byte_mask.attr.bit.no_changes = true;
reset_byte_mask.attr.bit.printed = true;
}
//----------------------------------------------------------------------
2017-09-11 03:06:02 +02:00
FOptiAttr::~FOptiAttr() // destructor
{ }
// public methods of FOptiAttr
//----------------------------------------------------------------------
void FOptiAttr::setTermEnvironment (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);
2019-09-08 02:04:24 +02:00
max_color = term_env.max_color;
attr_without_color = term_env.attr_without_color;
ansi_default_color = term_env.ansi_default_color;
initialize();
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_bold_mode (char cap[])
{
if ( cap )
{
F_enter_bold_mode.cap = cap;
F_enter_bold_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_bold_mode (char cap[])
{
if ( cap )
{
F_exit_bold_mode.cap = cap;
F_exit_bold_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_dim_mode (char cap[])
{
if ( cap )
{
F_enter_dim_mode.cap = cap;
F_enter_dim_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_dim_mode (char cap[])
{
if ( cap )
{
F_exit_dim_mode.cap = cap;
F_exit_dim_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_italics_mode (char cap[])
{
if ( cap )
{
F_enter_italics_mode.cap = cap;
F_enter_italics_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_italics_mode (char cap[])
{
if ( cap )
{
F_exit_italics_mode.cap = cap;
F_exit_italics_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_underline_mode (char cap[])
{
if ( cap )
{
F_enter_underline_mode.cap = cap;
F_enter_underline_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_underline_mode (char cap[])
{
if ( cap )
{
F_exit_underline_mode.cap = cap;
F_exit_underline_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_blink_mode (char cap[])
{
if ( cap )
{
F_enter_blink_mode.cap = cap;
F_enter_blink_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_blink_mode (char cap[])
{
if ( cap )
{
F_exit_blink_mode.cap = cap;
F_exit_blink_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_reverse_mode (char cap[])
{
if ( cap )
{
F_enter_reverse_mode.cap = cap;
F_enter_reverse_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_reverse_mode (char cap[])
{
if ( cap )
{
F_exit_reverse_mode.cap = cap;
F_exit_reverse_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_secure_mode (char cap[])
{
if ( cap )
{
F_enter_secure_mode.cap = cap;
F_enter_secure_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_secure_mode (char cap[])
{
if ( cap )
{
F_exit_secure_mode.cap = cap;
F_exit_secure_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_protected_mode (char cap[])
{
if ( cap )
{
F_enter_protected_mode.cap = cap;
F_enter_protected_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_protected_mode (char cap[])
{
if ( cap )
{
F_exit_protected_mode.cap = cap;
F_exit_protected_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_crossed_out_mode (char cap[])
{
if ( cap )
{
F_enter_crossed_out_mode.cap = cap;
F_enter_crossed_out_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_crossed_out_mode (char cap[])
{
if ( cap )
{
F_exit_crossed_out_mode.cap = cap;
F_exit_crossed_out_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_dbl_underline_mode (char cap[])
{
if ( cap )
{
F_enter_dbl_underline_mode.cap = cap;
F_enter_dbl_underline_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_dbl_underline_mode (char cap[])
{
if ( cap )
{
F_exit_dbl_underline_mode.cap = cap;
F_exit_dbl_underline_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_standout_mode (char cap[])
{
if ( cap )
{
F_enter_standout_mode.cap = cap;
F_enter_standout_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_standout_mode (char cap[])
{
if ( cap )
{
F_exit_standout_mode.cap = cap;
F_exit_standout_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_set_attributes (char cap[])
{
if ( cap )
{
F_set_attributes.cap = cap;
F_set_attributes.caused_reset = true;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_attribute_mode (char cap[])
{
if ( cap )
{
F_exit_attribute_mode.cap = cap;
F_exit_attribute_mode.caused_reset = true;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_alt_charset_mode (char cap[])
{
if ( cap )
{
F_enter_alt_charset_mode.cap = cap;
F_enter_alt_charset_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_alt_charset_mode (char cap[])
{
if ( cap )
{
F_exit_alt_charset_mode.cap = cap;
F_exit_alt_charset_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_enter_pc_charset_mode (char cap[])
{
if ( cap )
{
F_enter_pc_charset_mode.cap = cap;
F_enter_pc_charset_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_exit_pc_charset_mode (char cap[])
{
if ( cap )
{
F_exit_pc_charset_mode.cap = cap;
F_exit_pc_charset_mode.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_a_foreground_color (char cap[])
{
if ( cap )
{
F_set_a_foreground.cap = cap;
F_set_a_foreground.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_a_background_color (char cap[])
{
if ( cap )
{
F_set_a_background.cap = cap;
F_set_a_background.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_foreground_color (char cap[])
{
if ( cap )
{
F_set_foreground.cap = cap;
F_set_foreground.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_background_color (char cap[])
{
if ( cap )
{
F_set_background.cap = cap;
F_set_background.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_term_color_pair (char cap[])
{
if ( cap )
{
F_set_color_pair.cap = cap;
F_set_color_pair.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_orig_pair (char cap[])
{
if ( cap )
{
F_orig_pair.cap = cap;
F_orig_pair.caused_reset = false;
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
void FOptiAttr::set_orig_orig_colors (char cap[])
{
if ( cap )
{
F_orig_colors.cap = cap;
F_orig_colors.caused_reset = false;
}
}
2016-11-26 18:15:31 +01:00
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
bool FOptiAttr::isNormal (FChar*& ch)
2016-11-26 18:15:31 +01:00
{
return hasNoAttribute(ch) && ! hasColor(ch);
}
//----------------------------------------------------------------------
void FOptiAttr::initialize()
{
if ( max_color < 8 )
monochron = true;
else
monochron = false;
if ( caused_reset_attributes(F_exit_bold_mode.cap) )
F_exit_bold_mode.caused_reset = true;
if ( caused_reset_attributes(F_exit_dim_mode.cap) )
F_exit_dim_mode.caused_reset = true;
if ( caused_reset_attributes(F_exit_italics_mode.cap) )
F_exit_italics_mode.caused_reset = true;
if ( caused_reset_attributes(F_exit_blink_mode.cap) )
F_exit_blink_mode.caused_reset = true;
if ( caused_reset_attributes ( F_exit_underline_mode.cap
, all_tests & ~same_like_ue) )
F_exit_underline_mode.caused_reset = true;
if ( caused_reset_attributes(F_exit_reverse_mode.cap) )
F_exit_reverse_mode.caused_reset = true;
if ( caused_reset_attributes(F_exit_secure_mode.cap) )
F_exit_secure_mode.caused_reset = true;
if ( caused_reset_attributes(F_exit_protected_mode.cap) )
F_exit_protected_mode.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_exit_dbl_underline_mode.cap) )
F_exit_dbl_underline_mode.caused_reset = true;
if ( caused_reset_attributes ( F_exit_standout_mode.cap
, all_tests & ~same_like_se) )
F_exit_standout_mode.caused_reset = true;
if ( hasCharsetEquivalence() )
alt_equal_pc_charset = true;
}
//----------------------------------------------------------------------
2018-11-07 22:06:58 +01:00
FColor FOptiAttr::vga2ansi (FColor color)
{
// VGA | ANSI
// i R G B | i B G R
//---------+---------
// 0 0 0 0 | 0 0 0 0 i = intensity bit
// 0 0 0 1 | 0 1 0 0 R = red
// 0 0 1 0 | 0 0 1 0 G = green
// 0 0 1 1 | 0 1 1 0 B = blue
// 0 1 0 0 | 0 0 0 1
// 0 1 0 1 | 0 1 0 1
// 0 1 1 0 | 0 0 1 1
// 0 1 1 1 | 0 1 1 1
// 1 0 0 0 | 1 0 0 0
// 1 0 0 1 | 1 1 0 0
// 1 0 1 0 | 1 0 1 0
// 1 0 1 1 | 1 1 1 0
// 1 1 0 0 | 1 0 0 1
// 1 1 0 1 | 1 1 0 1
// 1 1 1 0 | 1 0 1 1
// 1 1 1 1 | 1 1 1 1
2018-11-07 22:06:58 +01:00
if ( color == fc::Default )
color = 0;
else if ( color < 16 )
{
2018-11-13 02:51:41 +01:00
static const FColor lookup_table[] =
{
0, 4, 2, 6, 1, 5, 3, 7,
8, 12, 10, 14, 9, 13, 11, 15
};
color = lookup_table[color];
}
return color;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
char* FOptiAttr::changeAttribute (FChar*& term, FChar*& next)
{
const bool next_has_color = hasColor(next);
fake_reverse = false;
attr_buf[0] = '\0';
if ( ! (term && next) )
return attr_buf;
prevent_no_color_video_attributes (term, next_has_color);
prevent_no_color_video_attributes (next);
detectSwitchOn (term, next);
detectSwitchOff (term, next);
// Simulate invisible characters
if ( ! F_enter_secure_mode.cap && next->attr.bit.invisible )
2019-10-08 04:37:19 +02:00
next->encoded_char = ' ';
// Look for no changes
2018-11-07 22:06:58 +01:00
if ( ! (switchOn() || switchOff() || hasColorChanged(term, next)) )
return 0;
if ( hasNoAttribute(next) )
{
deactivateAttributes (term, next);
}
2018-04-08 16:32:02 +02:00
else if ( F_set_attributes.cap
2018-04-15 19:55:50 +02:00
&& (! term->attr.bit.pc_charset || alt_equal_pc_charset) )
{
changeAttributeSGR (term, next);
}
else
{
changeAttributeSeparately (term, next);
}
2019-12-31 06:32:51 +01:00
if ( FStartOptions::getFStartOptions().sgr_optimizer )
sgr_optimizer.optimize();
return attr_buf;
}
// private methods of FOptiAttr
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermBold (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.bold = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_bold_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermBold (FChar*& term)
{
// Back to normal intensity (turns off bold + dim)
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_bold_mode.caused_reset )
reset(term);
else
{
term->attr.bit.bold = false;
term->attr.bit.dim = false;
}
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_bold_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermDim (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.dim = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_dim_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermDim (FChar*& term)
{
// Back to normal intensity (turns off bold + dim)
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_dim_mode.caused_reset )
reset(term);
else
{
term->attr.bit.bold = false;
term->attr.bit.dim = false;
}
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_dim_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermItalic (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.italic = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_italics_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermItalic (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_italics_mode.caused_reset )
reset(term);
else
term->attr.bit.italic = false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_italics_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermUnderline (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.underline = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_underline_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermUnderline (FChar*& term)
{
// Turns off every underlining
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_underline_mode.caused_reset )
reset(term);
else
{
term->attr.bit.underline = false;
term->attr.bit.dbl_underline = false;
}
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_underline_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermBlink (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.blink = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_blink_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermBlink (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_blink_mode.caused_reset )
reset(term);
else
2018-11-20 21:11:04 +01:00
term->attr.bit.blink = false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_blink_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermReverse (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.reverse = true;
2018-04-15 19:55:50 +02:00
if ( ! fake_reverse && append_sequence(F_enter_reverse_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermReverse (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_reverse_mode.caused_reset )
reset(term);
else
term->attr.bit.reverse = false;
2018-04-15 19:55:50 +02:00
if ( ! fake_reverse && append_sequence(F_exit_reverse_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermStandout (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.standout = true;
2018-04-15 19:55:50 +02:00
if ( ! fake_reverse && append_sequence(F_enter_standout_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermStandout (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_standout_mode.caused_reset )
reset(term);
else
term->attr.bit.standout = false;
2018-04-15 19:55:50 +02:00
if ( ! fake_reverse && append_sequence(F_exit_standout_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermInvisible (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.invisible = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_secure_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermInvisible (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_secure_mode.caused_reset )
reset(term);
else
term->attr.bit.invisible = false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_secure_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermProtected (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.protect = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_protected_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermProtected (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_protected_mode.caused_reset )
reset(term);
else
term->attr.bit.protect = false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_protected_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermCrossedOut (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.crossed_out = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_crossed_out_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermCrossedOut (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_crossed_out_mode.caused_reset )
reset(term);
else
term->attr.bit.crossed_out = false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_crossed_out_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermDoubleUnderline (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.dbl_underline = true;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_dbl_underline_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermDoubleUnderline (FChar*& term)
{
// Turns off every underlining
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
if ( F_exit_dbl_underline_mode.caused_reset )
reset(term);
else
{
term->attr.bit.underline = false;
term->attr.bit.dbl_underline = false;
}
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_dbl_underline_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
bool FOptiAttr::setTermAttributes ( FChar*& term
, bool p1, bool p2, bool p3
, bool p4, bool p5, bool p6
, bool p7, bool p8, bool p9 )
{
if ( term && F_set_attributes.cap )
{
char* sgr = tparm ( F_set_attributes.cap
2018-04-15 19:55:50 +02:00
, p1 && ! fake_reverse
, p2
, p3 && ! fake_reverse
, p4
, p5
, p6
, p7
, p8
, p9 );
append_sequence (sgr);
resetColor(term);
term->attr.bit.standout = p1;
term->attr.bit.underline = p2;
term->attr.bit.reverse = p3;
term->attr.bit.blink = p4;
term->attr.bit.dim = p5;
term->attr.bit.bold = p6;
term->attr.bit.invisible = p7;
term->attr.bit.protect = p8;
term->attr.bit.alt_charset = p9;
term->attr.bit.pc_charset = false;
term->attr.bit.italic = false;
term->attr.bit.crossed_out = false;
term->attr.bit.dbl_underline = false;
return true;
}
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermAttributes (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
reset(term);
2018-04-08 16:32:02 +02:00
if ( append_sequence(F_exit_attribute_mode.cap) )
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermAltCharset (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.alt_charset = true;
if ( alt_equal_pc_charset && term->attr.bit.pc_charset )
return false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_alt_charset_mode.cap) )
2016-01-08 12:39:38 +01:00
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermAltCharset (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.alt_charset = false;
if ( alt_equal_pc_charset && term->attr.bit.pc_charset )
return false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_alt_charset_mode.cap) )
2016-01-08 12:39:38 +01:00
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::setTermPCcharset (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.pc_charset = true;
if ( alt_equal_pc_charset && term->attr.bit.alt_charset )
return false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_enter_pc_charset_mode.cap) )
2016-01-08 12:39:38 +01:00
return true;
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::unsetTermPCcharset (FChar*& term)
{
2018-04-02 22:47:39 +02:00
if ( ! term )
return false;
term->attr.bit.pc_charset = false;
if ( alt_equal_pc_charset && term->attr.bit.alt_charset )
return false;
2018-04-02 22:47:39 +02:00
if ( append_sequence(F_exit_pc_charset_mode.cap) )
2016-01-08 12:39:38 +01:00
return true;
else
return false;
}
2016-01-10 00:56:52 +01:00
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
bool FOptiAttr::setTermDefaultColor (FChar*& term)
2016-01-10 00:56:52 +01:00
{
if ( ! term )
return false;
term->fg_color = fc::Default;
term->bg_color = fc::Default;
2018-04-02 22:47:39 +02:00
2016-01-10 00:56:52 +01:00
if ( append_sequence(F_orig_pair.cap) )
return true;
else if ( append_sequence(F_orig_colors.cap) )
return true;
else if ( ansi_default_color )
{
char sgr_39_49[] = CSI "39;49m";
2016-01-10 00:56:52 +01:00
append_sequence (sgr_39_49);
return true;
}
else
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
void FOptiAttr::setAttributesOn (FChar*& term)
{
if ( on.attr.bit.alt_charset )
setTermAltCharset(term);
if ( on.attr.bit.pc_charset )
setTermPCcharset(term);
if ( on.attr.bit.bold )
setTermBold(term);
if ( on.attr.bit.dim )
setTermDim(term);
if ( on.attr.bit.italic )
setTermItalic(term);
if ( on.attr.bit.underline )
setTermUnderline(term);
if ( on.attr.bit.blink )
setTermBlink(term);
if ( on.attr.bit.reverse )
setTermReverse(term);
if ( on.attr.bit.standout )
setTermStandout(term);
if ( on.attr.bit.invisible )
setTermInvisible(term);
if ( on.attr.bit.protect )
setTermProtected(term);
if ( on.attr.bit.crossed_out )
setTermCrossedOut(term);
if ( on.attr.bit.dbl_underline )
setTermDoubleUnderline(term);
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
void FOptiAttr::setAttributesOff (FChar*& term)
{
if ( off.attr.bit.pc_charset )
unsetTermPCcharset(term);
if ( off.attr.bit.alt_charset )
unsetTermAltCharset(term);
if ( off.attr.bit.bold )
unsetTermBold(term);
if ( off.attr.bit.dim )
unsetTermDim(term);
if ( off.attr.bit.italic )
unsetTermItalic(term);
if ( off.attr.bit.underline )
unsetTermUnderline(term);
if ( off.attr.bit.blink )
unsetTermBlink(term);
if ( off.attr.bit.reverse )
unsetTermReverse(term);
if ( off.attr.bit.standout )
unsetTermStandout(term);
if ( off.attr.bit.invisible )
unsetTermInvisible(term);
if ( off.attr.bit.protect )
unsetTermProtected(term);
if ( off.attr.bit.crossed_out )
unsetTermCrossedOut(term);
if ( off.attr.bit.dbl_underline )
unsetTermDoubleUnderline(term);
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
bool FOptiAttr::hasColor (FChar*& attr)
{
2018-11-07 22:06:58 +01:00
if ( attr
&& attr->fg_color == fc::Default
&& attr->bg_color == fc::Default )
return false;
else
return true;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
bool FOptiAttr::hasAttribute (FChar*& attr)
{
if ( attr )
{
return attr->attr.bit.bold == 1
|| attr->attr.bit.dim == 1
|| attr->attr.bit.italic == 1
|| attr->attr.bit.underline == 1
|| attr->attr.bit.blink == 1
|| attr->attr.bit.reverse == 1
|| attr->attr.bit.standout == 1
|| attr->attr.bit.invisible == 1
|| attr->attr.bit.protect == 1
|| attr->attr.bit.crossed_out == 1
|| attr->attr.bit.dbl_underline == 1
|| attr->attr.bit.alt_charset == 1
|| attr->attr.bit.pc_charset == 1;
}
return false;
}
2016-11-26 18:15:31 +01:00
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
bool FOptiAttr::hasNoAttribute (FChar*& attr)
{
return ! hasAttribute(attr);
}
2016-11-26 18:15:31 +01:00
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline bool FOptiAttr::hasColorChanged (FChar*& term, FChar*& next)
{
if ( term && next )
{
bool frev ( ( on.attr.bit.reverse
2018-04-15 19:55:50 +02:00
|| on.attr.bit.standout
|| off.attr.bit.reverse
|| off.attr.bit.standout ) && fake_reverse );
2018-04-15 19:55:50 +02:00
return bool ( frev
2017-11-26 22:37:18 +01:00
|| term->fg_color != next->fg_color
|| term->bg_color != next->bg_color );
}
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::resetColor (FChar*& attr)
{
if ( attr )
{
attr->fg_color = fc::Default;
attr->bg_color = fc::Default;
}
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::prevent_no_color_video_attributes ( FChar*& attr
, bool next_has_color )
{
// Ignore attributes which can not combined with a color
if ( ! attr
|| ! (hasColor(attr) || next_has_color)
|| attr_without_color <= 0 )
return;
2019-08-25 22:16:00 +02:00
for (int bit{1}; bit < no_mode; bit <<= 1)
{
switch ( bit & attr_without_color )
{
case standout_mode:
attr->attr.bit.standout = false;
break;
case underline_mode:
attr->attr.bit.underline = false;
break;
case reverse_mode:
2018-04-15 19:55:50 +02:00
fake_reverse = true;
break;
case blink_mode:
attr->attr.bit.blink = false;
break;
case dim_mode:
attr->attr.bit.dim = false;
break;
case bold_mode:
attr->attr.bit.bold = false;
break;
case invisible_mode:
attr->attr.bit.invisible = false;
break;
case protected_mode:
attr->attr.bit.protect = false;
break;
case alt_charset_mode:
attr->attr.bit.alt_charset = false;
break;
case italic_mode:
attr->attr.bit.italic = false;
break;
default:
break;
}
}
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::deactivateAttributes ( FChar*& term
, FChar*& next )
{
if ( hasAttribute(term) )
{
if ( F_exit_attribute_mode.cap )
{
2018-04-08 16:32:02 +02:00
if ( off.attr.bit.alt_charset ) // Required for rxvt terminals
unsetTermAltCharset(term);
unsetTermAttributes(term);
if ( off.attr.bit.pc_charset )
unsetTermPCcharset(term);
}
else
setAttributesOff(term);
}
2018-11-07 22:06:58 +01:00
if ( hasColorChanged(term, next) )
change_color (term, next);
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::changeAttributeSGR ( FChar*& term
, FChar*& next )
{
2019-08-25 22:16:00 +02:00
bool pc_charset_usable{true};
if ( ! (term && next) )
return;
if ( switchOn() || switchOff() )
setTermAttributes ( term
, next->attr.bit.standout
, next->attr.bit.underline
, next->attr.bit.reverse
, next->attr.bit.blink
, next->attr.bit.dim
, next->attr.bit.bold
, next->attr.bit.invisible
, next->attr.bit.protect
, next->attr.bit.alt_charset );
2018-04-15 19:55:50 +02:00
if ( alt_equal_pc_charset
&& F_enter_pc_charset_mode.cap
&& next->attr.bit.alt_charset )
{
2018-04-08 16:32:02 +02:00
term->attr.bit.pc_charset = next->attr.bit.pc_charset;
off.attr.bit.pc_charset = false;
pc_charset_usable = false;
}
if ( off.attr.bit.pc_charset )
unsetTermPCcharset(term);
2018-04-15 19:55:50 +02:00
if ( ! term->attr.bit.italic && next->attr.bit.italic )
setTermItalic(term);
2018-04-15 19:55:50 +02:00
if ( ! term->attr.bit.crossed_out && next->attr.bit.crossed_out )
setTermCrossedOut(term);
2018-04-15 19:55:50 +02:00
if ( ! term->attr.bit.dbl_underline && next->attr.bit.dbl_underline )
setTermDoubleUnderline(term);
2018-04-15 19:55:50 +02:00
if ( ! term->attr.bit.pc_charset && next->attr.bit.pc_charset
&& pc_charset_usable )
setTermPCcharset(term);
2018-11-07 22:06:58 +01:00
if ( hasColorChanged(term, next) )
change_color(term, next);
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::changeAttributeSeparately ( FChar*& term
, FChar*& next )
{
setAttributesOff(term);
2018-11-07 22:06:58 +01:00
if ( hasColorChanged(term, next) )
change_color (term, next);
detectSwitchOn (term, next); // After reset all attributes
setAttributesOn(term);
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
void FOptiAttr::change_color (FChar*& term, FChar*& next)
{
2018-04-15 19:55:50 +02:00
if ( ! (term && next) )
return;
if ( monochron )
{
next->fg_color = fc::Default;
next->bg_color = fc::Default;
return;
2018-04-15 19:55:50 +02:00
}
2018-11-07 22:06:58 +01:00
if ( next->fg_color != fc::Default )
next->fg_color %= max_color;
if ( next->bg_color != fc::Default )
next->bg_color %= max_color;
2019-08-25 22:16:00 +02:00
FColor fg = next->fg_color;
FColor bg = next->bg_color;
if ( fg == fc::Default || bg == fc::Default )
change_to_default_color (term, next, fg, bg);
2018-11-07 22:06:58 +01:00
if ( fake_reverse && fg == fc::Default && bg == fc::Default )
return;
2018-04-15 19:55:50 +02:00
if ( fake_reverse
&& (next->attr.bit.reverse || next->attr.bit.standout) )
{
std::swap (fg, bg);
if ( fg == fc::Default || bg == fc::Default )
setTermDefaultColor(term);
}
change_current_color (term, fg, bg);
term->fg_color = next->fg_color;
term->bg_color = next->bg_color;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::change_to_default_color ( FChar*& term
, FChar*& next
2018-11-07 22:06:58 +01:00
, FColor& fg, FColor& bg )
{
if ( ansi_default_color )
{
if ( fg == fc::Default && term->fg_color != fc::Default
&& bg == fc::Default && term->bg_color != fc::Default )
{
setTermDefaultColor(term);
}
else if ( fg == fc::Default && term->fg_color != fc::Default )
{
2019-08-25 22:16:00 +02:00
char sgr_39[]{ CSI "39m" };
append_sequence (sgr_39);
term->fg_color = fc::Default;
}
else if ( bg == fc::Default && term->bg_color != fc::Default )
{
char* sgr_49;
auto& op = F_orig_pair.cap;
if ( op && std::strncmp (op, CSI "39;49;25m", 11) == 0 )
sgr_49 = C_STR(CSI "49;25m");
else
sgr_49 = C_STR(CSI "49m");
append_sequence (sgr_49);
term->bg_color = fc::Default;
}
}
else if ( ! setTermDefaultColor(term) )
{
// Fallback to gray on black
fg = next->fg_color = fc::LightGray;
bg = next->bg_color = fc::Black;
}
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::change_current_color ( FChar*& term
2018-11-07 22:06:58 +01:00
, FColor fg, FColor bg )
{
2019-08-25 22:16:00 +02:00
char* color_str{};
auto& AF = F_set_a_foreground.cap;
auto& AB = F_set_a_background.cap;
auto& Sf = F_set_foreground.cap;
auto& Sb = F_set_background.cap;
auto& sp = F_set_color_pair.cap;
bool frev ( ( off.attr.bit.reverse
2018-04-15 19:55:50 +02:00
|| off.attr.bit.standout
|| term->attr.bit.reverse
|| term->attr.bit.standout ) && fake_reverse );
if ( AF && AB )
{
auto ansi_fg = vga2ansi(fg);
auto ansi_bg = vga2ansi(bg);
2018-04-15 19:55:50 +02:00
if ( (term->fg_color != fg || frev)
2017-11-26 22:37:18 +01:00
&& (color_str = tparm(AF, ansi_fg, 0, 0, 0, 0, 0, 0, 0, 0)) )
2016-11-20 21:15:43 +01:00
append_sequence (color_str);
2018-04-15 19:55:50 +02:00
if ( (term->bg_color != bg || frev)
2017-11-26 22:37:18 +01:00
&& (color_str = tparm(AB, ansi_bg, 0, 0, 0, 0, 0, 0, 0, 0)) )
2016-11-20 21:15:43 +01:00
append_sequence (color_str);
}
else if ( Sf && Sb )
{
2018-04-15 19:55:50 +02:00
if ( (term->fg_color != fg || frev)
2017-11-26 22:37:18 +01:00
&& (color_str = tparm(Sf, fg, 0, 0, 0, 0, 0, 0, 0, 0)) )
append_sequence (color_str);
2018-04-15 19:55:50 +02:00
if ( (term->bg_color != bg || frev)
2017-11-26 22:37:18 +01:00
&& (color_str = tparm(Sb, bg, 0, 0, 0, 0, 0, 0, 0, 0)) )
append_sequence (color_str);
}
else if ( sp )
{
fg = vga2ansi(fg);
bg = vga2ansi(bg);
if ( (color_str = tparm(sp, fg, bg, 0, 0, 0, 0, 0, 0, 0)) )
append_sequence (color_str);
}
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::resetAttribute (FChar*& attr)
{
if ( attr )
{
attr->attr.byte[0] = 0;
attr->attr.byte[1] &= reset_byte_mask.attr.byte[1];
}
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::reset (FChar*& attr)
{
if ( attr )
{
resetAttribute(attr);
resetColor(attr);
}
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
bool FOptiAttr::caused_reset_attributes (char cap[], uChar test)
{
// test if "cap" reset all attributes
if ( cap )
{
2019-07-14 18:30:35 +02:00
auto& ue = F_exit_underline_mode.cap;
auto& se = F_exit_standout_mode.cap;
auto& me = F_exit_attribute_mode.cap;
if ( (test & test_ansi_reset) && std::strncmp (cap, CSI "m", 3) == 0 )
return true;
if ( (test & test_adm3_reset) && std::strncmp (cap, ESC "G0", 3) == 0 )
return true;
2018-04-08 16:32:02 +02:00
if ( (test & same_like_ue) && ue && std::strcmp (cap, ue) == 0
&& std::strncmp (cap, CSI "24m", 5) != 0)
return true;
2018-04-08 16:32:02 +02:00
if ( (test & same_like_se) && se && std::strcmp (cap, se) == 0
&& std::strncmp (cap, CSI "27m", 5) != 0 )
return true;
if ( (test & same_like_me) && me && std::strcmp (cap, me) == 0 )
return true;
}
return false;
}
//----------------------------------------------------------------------
inline bool FOptiAttr::hasCharsetEquivalence()
{
// Detect if alt charset and pc charset are the same sequences
auto& alt_on = F_enter_alt_charset_mode.cap;
auto& alt_off = F_enter_pc_charset_mode.cap;
auto& pc_on = F_enter_pc_charset_mode.cap;
auto& pc_off = F_exit_pc_charset_mode.cap;
if ( alt_on && pc_on && std::strcmp (alt_on, pc_on) == 0 )
return true;
if ( alt_off && pc_off && std::strcmp (alt_off, pc_off) == 0 )
return true;
return false;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::detectSwitchOn (FChar*& term, FChar*& next)
{
if ( ! (term && next) )
return;
on.attr.bit.bold = ! term->attr.bit.bold && next->attr.bit.bold;
on.attr.bit.dim = ! term->attr.bit.dim && next->attr.bit.dim;
on.attr.bit.italic = ! term->attr.bit.italic && next->attr.bit.italic;
on.attr.bit.underline = ! term->attr.bit.underline && next->attr.bit.underline;
on.attr.bit.blink = ! term->attr.bit.blink && next->attr.bit.blink;
on.attr.bit.reverse = ! term->attr.bit.reverse && next->attr.bit.reverse;
on.attr.bit.standout = ! term->attr.bit.standout && next->attr.bit.standout;
on.attr.bit.invisible = ! term->attr.bit.invisible && next->attr.bit.invisible;
on.attr.bit.protect = ! term->attr.bit.protect && next->attr.bit.protect;
on.attr.bit.crossed_out = ! term->attr.bit.crossed_out && next->attr.bit.crossed_out;
on.attr.bit.dbl_underline = ! term->attr.bit.dbl_underline && next->attr.bit.dbl_underline;
on.attr.bit.alt_charset = ! term->attr.bit.alt_charset && next->attr.bit.alt_charset;
on.attr.bit.pc_charset = ! term->attr.bit.pc_charset && next->attr.bit.pc_charset;
}
//----------------------------------------------------------------------
2019-10-08 04:37:19 +02:00
inline void FOptiAttr::detectSwitchOff (FChar*& term, FChar*& next)
{
if ( ! (term && next) )
return;
off.attr.bit.bold = term->attr.bit.bold && ! next->attr.bit.bold;
off.attr.bit.dim = term->attr.bit.dim && ! next->attr.bit.dim;
off.attr.bit.italic = term->attr.bit.italic && ! next->attr.bit.italic;
off.attr.bit.underline = term->attr.bit.underline && ! next->attr.bit.underline;
off.attr.bit.blink = term->attr.bit.blink && ! next->attr.bit.blink;
off.attr.bit.reverse = term->attr.bit.reverse && ! next->attr.bit.reverse;
off.attr.bit.standout = term->attr.bit.standout && ! next->attr.bit.standout;
off.attr.bit.invisible = term->attr.bit.invisible && ! next->attr.bit.invisible;
off.attr.bit.protect = term->attr.bit.protect && ! next->attr.bit.protect;
off.attr.bit.crossed_out = term->attr.bit.crossed_out && ! next->attr.bit.crossed_out;
off.attr.bit.dbl_underline = term->attr.bit.dbl_underline && ! next->attr.bit.dbl_underline;
off.attr.bit.alt_charset = term->attr.bit.alt_charset && ! next->attr.bit.alt_charset;
off.attr.bit.pc_charset = term->attr.bit.pc_charset && ! next->attr.bit.pc_charset;
}
//----------------------------------------------------------------------
inline bool FOptiAttr::switchOn()
{
auto on_ptr = &on;
return hasAttribute(on_ptr);
}
//----------------------------------------------------------------------
inline bool FOptiAttr::switchOff()
{
auto off_ptr = &off;
return hasAttribute(off_ptr);
}
//----------------------------------------------------------------------
2017-12-19 02:06:27 +01:00
inline bool FOptiAttr::append_sequence (char seq[])
{
2019-12-31 06:32:51 +01:00
if ( ! seq )
return false;
2019-12-31 06:32:51 +01:00
std::strncat (attr_ptr, seq, sizeof(attr_buf) - std::strlen(attr_ptr));
attr_buf[sizeof(attr_buf) - 1] = '\0';
return true;
}
} // namespace finalcut