2016-01-08 01:00:05 +01:00
|
|
|
// File: foptiattr.h
|
|
|
|
// Provides: class FOptiAttr
|
|
|
|
//
|
|
|
|
// Standalone class
|
|
|
|
// ════════════════
|
|
|
|
//
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FOptiAttr ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FOPTIATTR_H
|
|
|
|
#define FOPTIATTR_H
|
2016-01-08 01:00:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include <algorithm> // need for std::swap
|
|
|
|
#include <assert.h>
|
|
|
|
#include <term.h> // need for tparm
|
|
|
|
|
2017-09-07 23:35:24 +02:00
|
|
|
#include "fc.h"
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FOptiAttr
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FOptiAttr
|
|
|
|
{
|
|
|
|
public:
|
2016-11-02 00:37:58 +01:00
|
|
|
// Typedef
|
2016-01-08 01:00:05 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int code; // character code
|
|
|
|
short fg_color; // foreground color
|
|
|
|
short bg_color; // background color
|
2017-08-20 17:30:30 +02:00
|
|
|
|
|
|
|
union attribute
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
// Attribute byte #1
|
|
|
|
uChar bold : 1; // bold
|
|
|
|
uChar dim : 1; // dim
|
|
|
|
uChar italic : 1; // italic
|
|
|
|
uChar underline : 1; // underline
|
|
|
|
uChar blink : 1; // blink
|
|
|
|
uChar reverse : 1; // reverse
|
|
|
|
uChar standout : 1; // standout
|
|
|
|
uChar invisible : 1; // invisible
|
|
|
|
// Attribute byte #2
|
|
|
|
uChar protect : 1; // protect mode
|
|
|
|
uChar crossed_out : 1; // crossed out
|
|
|
|
uChar dbl_underline : 1; // double underline
|
|
|
|
uChar alt_charset : 1; // alternate character set (vt100)
|
|
|
|
uChar pc_charset : 1; // pc character set (CP437)
|
|
|
|
uChar transparent : 1; // transparent
|
|
|
|
uChar trans_shadow : 1; // transparent shadow
|
|
|
|
uChar inherit_bg : 1; // inherit background
|
|
|
|
// Attribute byte #3
|
|
|
|
uChar no_changes : 1; // no changes required
|
|
|
|
uChar printed : 1; // is printed to VTerm
|
|
|
|
uChar : 6; // padding bits
|
|
|
|
} bit;
|
|
|
|
|
|
|
|
uChar byte1;
|
|
|
|
uChar byte2;
|
|
|
|
uChar byte3;
|
|
|
|
} attr;
|
|
|
|
|
2016-01-08 01:00:05 +01:00
|
|
|
} char_data;
|
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
|
|
|
explicit FOptiAttr();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
|
|
|
~FOptiAttr();
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Friend operator functions
|
|
|
|
friend bool operator == (const char_data&, const char_data&);
|
|
|
|
friend bool operator != (const char_data&, const char_data&);
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Mutators
|
2016-01-08 01:00:05 +01:00
|
|
|
void setMaxColor (int&);
|
|
|
|
void setNoColorVideo (int);
|
2016-01-10 00:56:52 +01:00
|
|
|
void setDefaultColorSupport();
|
2016-01-08 01:00:05 +01:00
|
|
|
void setCygwinTerminal();
|
|
|
|
void set_enter_bold_mode (char*&);
|
|
|
|
void set_exit_bold_mode (char*&);
|
|
|
|
void set_enter_dim_mode (char*&);
|
|
|
|
void set_exit_dim_mode (char*&);
|
|
|
|
void set_enter_italics_mode (char*&);
|
|
|
|
void set_exit_italics_mode (char*&);
|
|
|
|
void set_enter_underline_mode (char*&);
|
|
|
|
void set_exit_underline_mode (char*&);
|
|
|
|
void set_enter_blink_mode (char*&);
|
|
|
|
void set_exit_blink_mode (char*&);
|
|
|
|
void set_enter_reverse_mode (char*&);
|
|
|
|
void set_exit_reverse_mode (char*&);
|
|
|
|
void set_enter_secure_mode (char*&);
|
|
|
|
void set_exit_secure_mode (char*&);
|
|
|
|
void set_enter_protected_mode (char*&);
|
|
|
|
void set_exit_protected_mode (char*&);
|
|
|
|
void set_enter_crossed_out_mode (char*&);
|
|
|
|
void set_exit_crossed_out_mode (char*&);
|
|
|
|
void set_enter_dbl_underline_mode (char*&);
|
|
|
|
void set_exit_dbl_underline_mode (char*&);
|
|
|
|
void set_enter_standout_mode (char*&);
|
|
|
|
void set_exit_standout_mode (char*&);
|
|
|
|
void set_set_attributes (char*&);
|
|
|
|
void set_exit_attribute_mode (char*&);
|
|
|
|
void set_enter_alt_charset_mode (char*&);
|
|
|
|
void set_exit_alt_charset_mode (char*&);
|
|
|
|
void set_enter_pc_charset_mode (char*&);
|
|
|
|
void set_exit_pc_charset_mode (char*&);
|
|
|
|
void set_a_foreground_color (char*&);
|
|
|
|
void set_a_background_color (char*&);
|
|
|
|
void set_foreground_color (char*&);
|
|
|
|
void set_background_color (char*&);
|
|
|
|
void set_term_color_pair (char*&);
|
2016-01-10 00:56:52 +01:00
|
|
|
void set_orig_pair (char*&);
|
|
|
|
void set_orig_orig_colors (char*&);
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-26 15:18:44 +01:00
|
|
|
// Inquiry
|
2016-11-26 18:15:31 +01:00
|
|
|
static bool isNormal (char_data*&);
|
2016-11-26 15:18:44 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Methods
|
|
|
|
void init();
|
|
|
|
static short vga2ansi (register short);
|
|
|
|
char* changeAttribute (char_data*&, char_data*&);
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
private:
|
|
|
|
// Typedefs and Enumerations
|
|
|
|
typedef unsigned char uChar;
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char* cap;
|
|
|
|
bool caused_reset;
|
|
|
|
} capability;
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
enum init_reset_tests
|
|
|
|
{
|
|
|
|
no_test = 0x00,
|
|
|
|
test_ansi_reset = 0x01, // ANSI X3.64 terminal
|
|
|
|
test_adm3_reset = 0x02, // Lear Siegler ADM-3 terminal
|
|
|
|
same_like_ue = 0x04,
|
|
|
|
same_like_se = 0x08,
|
|
|
|
same_like_me = 0x10,
|
|
|
|
all_tests = 0x1f
|
|
|
|
};
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
enum default_color
|
|
|
|
{
|
|
|
|
Default = -1,
|
|
|
|
Black = 0,
|
|
|
|
LightGray = 7
|
|
|
|
};
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FOptiAttr (const FOptiAttr&);
|
2016-01-10 00:56:52 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
FOptiAttr& operator = (const FOptiAttr&);
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Mutators
|
|
|
|
bool setTermBold (char_data*&);
|
|
|
|
bool unsetTermBold (char_data*&);
|
|
|
|
bool setTermDim (char_data*&);
|
|
|
|
bool unsetTermDim (char_data*&);
|
|
|
|
bool setTermItalic (char_data*&);
|
|
|
|
bool unsetTermItalic (char_data*&);
|
|
|
|
bool setTermUnderline (char_data*&);
|
|
|
|
bool unsetTermUnderline (char_data*&);
|
|
|
|
bool setTermBlink (char_data*&);
|
|
|
|
bool unsetTermBlink (char_data*&);
|
|
|
|
bool setTermReverse (char_data*&);
|
|
|
|
bool unsetTermReverse (char_data*&);
|
|
|
|
bool setTermStandout (char_data*&);
|
|
|
|
bool unsetTermStandout (char_data*&);
|
|
|
|
bool setTermInvisible (char_data*&);
|
|
|
|
bool unsetTermInvisible (char_data*&);
|
|
|
|
bool setTermProtected (char_data*&);
|
|
|
|
bool unsetTermProtected (char_data*&);
|
|
|
|
bool setTermCrossedOut (char_data*&);
|
|
|
|
bool unsetTermCrossedOut (char_data*&);
|
|
|
|
bool setTermDoubleUnderline (char_data*&);
|
|
|
|
bool unsetTermDoubleUnderline (char_data*&);
|
|
|
|
bool setTermAttributes ( char_data*&
|
|
|
|
, bool, bool, bool
|
|
|
|
, bool, bool, bool
|
|
|
|
, bool, bool, bool );
|
|
|
|
bool unsetTermAttributes (char_data*&);
|
|
|
|
bool setTermAltCharset (char_data*&);
|
|
|
|
bool unsetTermAltCharset (char_data*&);
|
|
|
|
bool setTermPCcharset (char_data*&);
|
|
|
|
bool unsetTermPCcharset (char_data*&);
|
|
|
|
bool setTermDefaultColor (char_data*&);
|
2016-01-08 01:00:05 +01:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Inquiries
|
2016-11-26 18:15:31 +01:00
|
|
|
static bool hasColor (char_data*&);
|
|
|
|
static bool hasAttribute (char_data*&);
|
|
|
|
static bool hasNoAttribute (char_data*&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// Methods
|
|
|
|
bool colorChange (char_data*&, char_data*&);
|
|
|
|
void resetColor (char_data*&);
|
|
|
|
void prevent_no_color_video_attributes (char_data*&);
|
|
|
|
void change_color (char_data*&, char_data*&);
|
|
|
|
void resetAttribute (char_data*&);
|
|
|
|
void reset (char_data*&);
|
|
|
|
bool caused_reset_attributes (char*&, uChar = all_tests);
|
|
|
|
void detectSwitchOn (char_data*&, char_data*&);
|
|
|
|
void detectSwitchOff (char_data*&, char_data*&);
|
|
|
|
bool switchOn();
|
|
|
|
bool switchOff();
|
|
|
|
bool append_sequence (char*&);
|
|
|
|
bool replace_sequence (char*&);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
char_data on;
|
|
|
|
char_data off;
|
|
|
|
|
|
|
|
int max_color;
|
|
|
|
int attr_without_color;
|
|
|
|
bool ansi_default_color;
|
|
|
|
bool monochron;
|
|
|
|
bool fake_reverse;
|
|
|
|
bool cygwin_terminal;
|
|
|
|
char attr_buf[8192];
|
|
|
|
char* attr_ptr;
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FOptiAttr inline functions
|
2016-01-08 01:00:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool operator == ( const FOptiAttr::char_data& lhs,
|
|
|
|
const FOptiAttr::char_data& rhs )
|
|
|
|
{
|
2017-08-20 17:30:30 +02:00
|
|
|
return lhs.code == rhs.code
|
|
|
|
&& lhs.fg_color == rhs.fg_color
|
|
|
|
&& lhs.bg_color == rhs.bg_color
|
|
|
|
&& lhs.attr.byte1 == rhs.attr.byte1
|
|
|
|
&& lhs.attr.byte2 == rhs.attr.byte2;
|
2016-01-08 01:00:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool operator != ( const FOptiAttr::char_data& lhs,
|
|
|
|
const FOptiAttr::char_data& rhs )
|
|
|
|
{ return ! ( lhs == rhs ); }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FOptiAttr::setMaxColor (int& c)
|
|
|
|
{ max_color = c; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FOptiAttr::setNoColorVideo (int attr)
|
|
|
|
{ attr_without_color = attr; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FOptiAttr::setDefaultColorSupport()
|
|
|
|
{ ansi_default_color = true; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FOptiAttr::setCygwinTerminal()
|
|
|
|
{ cygwin_terminal = true; }
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FOPTIATTR_H
|