Refactoring attribute settings in FOptiAttr
This commit is contained in:
parent
76d72208e5
commit
9bb22e7d7b
|
@ -1,4 +1,5 @@
|
|||
2017-01-02 Markus Gans <guru.mail@muenster.de>
|
||||
* Refactoring attribute settings in FOptiAttr
|
||||
* Refactoring FTerm::parseKeyString and timeout settings
|
||||
|
||||
2017-01-02 Markus Gans <guru.mail@muenster.de>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* *
|
||||
* This file is part of the Final Cut widget toolkit *
|
||||
* *
|
||||
* Copyright 2016-2017 Markus Gans *
|
||||
* Copyright 2016-2018 Markus Gans *
|
||||
* *
|
||||
* The Final Cut is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public License *
|
||||
|
@ -270,7 +270,14 @@ class FOptiAttr
|
|||
bool colorChange (char_data*&, char_data*&);
|
||||
void resetColor (char_data*&);
|
||||
void prevent_no_color_video_attributes (char_data*&);
|
||||
void preProcessing_cygwin_quirks (char_data*&);
|
||||
void postProcessing_cygwin_quirks (char_data*&, char_data*&);
|
||||
void deactivateAttributes (char_data*&, char_data*&);
|
||||
void changeAttributeSGR (char_data*&, char_data*&);
|
||||
void changeAttributeSeparately (char_data*&, char_data*&);
|
||||
void change_color (char_data*&, char_data*&);
|
||||
void change_to_default_color (char_data*&, char_data*&, short&, short&);
|
||||
void change_current_color (char_data*&, short, short);
|
||||
void resetAttribute (char_data*&);
|
||||
void reset (char_data*&);
|
||||
bool caused_reset_attributes (char[], uChar = all_tests);
|
||||
|
|
|
@ -539,98 +539,23 @@ char* FOptiAttr::changeAttribute (char_data*& term, char_data*& next)
|
|||
if ( ! F_enter_secure_mode.cap && next->attr.bit.invisible )
|
||||
next->code = ' ';
|
||||
|
||||
// look for no changes
|
||||
// Look for no changes
|
||||
if ( ! ( switchOn() || switchOff() || colorChange(term, next) ) )
|
||||
return 0;
|
||||
|
||||
if ( cygwin_terminal && (term->fg_color > 7 || term->bg_color > 7) )
|
||||
{
|
||||
// reset blink and bold mode from colors > 7
|
||||
char rst[] = CSI "m";
|
||||
append_sequence (rst);
|
||||
reset(term);
|
||||
}
|
||||
preProcessing_cygwin_quirks(term);
|
||||
|
||||
if ( hasNoAttribute(next) )
|
||||
{
|
||||
if ( hasAttribute(term) )
|
||||
{
|
||||
if ( F_exit_attribute_mode.cap )
|
||||
{
|
||||
unsetTermAttributes(term);
|
||||
|
||||
if ( off.attr.bit.pc_charset )
|
||||
unsetTermPCcharset(term);
|
||||
|
||||
if ( off.attr.bit.alt_charset )
|
||||
unsetTermAltCharset(term);
|
||||
}
|
||||
else
|
||||
setAttributesOff(term);
|
||||
}
|
||||
|
||||
if ( colorChange(term, next) )
|
||||
change_color (term, next);
|
||||
deactivateAttributes (term, next);
|
||||
}
|
||||
else if ( F_set_attributes.cap && ! term->attr.bit.pc_charset )
|
||||
{
|
||||
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 );
|
||||
|
||||
if ( off.attr.bit.pc_charset )
|
||||
unsetTermPCcharset(term);
|
||||
|
||||
if ( next->attr.bit.italic )
|
||||
setTermItalic(term);
|
||||
|
||||
if ( next->attr.bit.crossed_out )
|
||||
setTermCrossedOut(term);
|
||||
|
||||
if ( next->attr.bit.dbl_underline )
|
||||
setTermDoubleUnderline(term);
|
||||
|
||||
if ( next->attr.bit.pc_charset )
|
||||
setTermPCcharset(term);
|
||||
|
||||
if ( colorChange(term, next) )
|
||||
{
|
||||
change_color(term, next);
|
||||
|
||||
if ( cygwin_terminal )
|
||||
{
|
||||
if ( next->attr.bit.bold )
|
||||
setTermBold(term);
|
||||
|
||||
if ( next->attr.bit.reverse )
|
||||
setTermReverse(term);
|
||||
|
||||
if ( next->attr.bit.standout )
|
||||
setTermStandout(term);
|
||||
}
|
||||
}
|
||||
changeAttributeSGR (term, next);
|
||||
}
|
||||
else
|
||||
{
|
||||
setAttributesOff(term);
|
||||
detectSwitchOff (term, next);
|
||||
|
||||
if ( switchOff() )
|
||||
unsetTermAttributes(term);
|
||||
|
||||
if ( colorChange(term, next) )
|
||||
change_color (term, next);
|
||||
|
||||
detectSwitchOn (term, next);
|
||||
setAttributesOn(term);
|
||||
changeAttributeSeparately (term, next);
|
||||
}
|
||||
|
||||
if ( term && fake_reverse )
|
||||
|
@ -1265,15 +1190,124 @@ inline void FOptiAttr::prevent_no_color_video_attributes (char_data*& attr)
|
|||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::preProcessing_cygwin_quirks (char_data*& term)
|
||||
{
|
||||
// Cygwin bold color fix pre processing
|
||||
|
||||
if ( ! cygwin_terminal )
|
||||
return;
|
||||
|
||||
if ( term->fg_color > 7 || term->bg_color > 7 )
|
||||
{
|
||||
// Reset blink and bold mode from colors > 7
|
||||
char rst[] = CSI "m";
|
||||
append_sequence (rst);
|
||||
reset(term);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::postProcessing_cygwin_quirks ( char_data*& term
|
||||
, char_data*& next )
|
||||
{
|
||||
// Cygwin bold color fix post processing
|
||||
|
||||
if ( ! cygwin_terminal )
|
||||
return;
|
||||
|
||||
if ( next->attr.bit.bold )
|
||||
setTermBold(term);
|
||||
|
||||
if ( next->attr.bit.reverse )
|
||||
setTermReverse(term);
|
||||
|
||||
if ( next->attr.bit.standout )
|
||||
setTermStandout(term);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::deactivateAttributes ( char_data*& term
|
||||
, char_data*& next )
|
||||
{
|
||||
if ( hasAttribute(term) )
|
||||
{
|
||||
if ( F_exit_attribute_mode.cap )
|
||||
{
|
||||
unsetTermAttributes(term);
|
||||
|
||||
if ( off.attr.bit.pc_charset )
|
||||
unsetTermPCcharset(term);
|
||||
|
||||
if ( off.attr.bit.alt_charset )
|
||||
unsetTermAltCharset(term);
|
||||
}
|
||||
else
|
||||
setAttributesOff(term);
|
||||
}
|
||||
|
||||
if ( colorChange(term, next) )
|
||||
change_color (term, next);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::changeAttributeSGR ( char_data*& term
|
||||
, char_data*& next )
|
||||
{
|
||||
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 );
|
||||
|
||||
if ( off.attr.bit.pc_charset )
|
||||
unsetTermPCcharset(term);
|
||||
|
||||
if ( next->attr.bit.italic )
|
||||
setTermItalic(term);
|
||||
|
||||
if ( next->attr.bit.crossed_out )
|
||||
setTermCrossedOut(term);
|
||||
|
||||
if ( next->attr.bit.dbl_underline )
|
||||
setTermDoubleUnderline(term);
|
||||
|
||||
if ( next->attr.bit.pc_charset )
|
||||
setTermPCcharset(term);
|
||||
|
||||
if ( colorChange(term, next) )
|
||||
{
|
||||
change_color(term, next);
|
||||
postProcessing_cygwin_quirks(term, next);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::changeAttributeSeparately ( char_data*& term
|
||||
, char_data*& next )
|
||||
{
|
||||
setAttributesOff(term);
|
||||
detectSwitchOff (term, next);
|
||||
|
||||
if ( switchOff() )
|
||||
unsetTermAttributes(term);
|
||||
|
||||
if ( colorChange(term, next) )
|
||||
change_color (term, next);
|
||||
|
||||
detectSwitchOn (term, next);
|
||||
setAttributesOn(term);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FOptiAttr::change_color (char_data*& term, char_data*& next)
|
||||
{
|
||||
char* color_str;
|
||||
char* AF = F_set_a_foreground.cap;
|
||||
char* AB = F_set_a_background.cap;
|
||||
char* Sf = F_set_foreground.cap;
|
||||
char* Sb = F_set_background.cap;
|
||||
char* sp = F_set_color_pair.cap;
|
||||
short fg, bg;
|
||||
|
||||
if ( monochron || ! (term && next) )
|
||||
|
@ -1283,7 +1317,30 @@ void FOptiAttr::change_color (char_data*& term, char_data*& next)
|
|||
bg = next->bg_color;
|
||||
|
||||
if ( fg == Default || bg == Default )
|
||||
change_to_default_color (term, next, fg, bg);
|
||||
|
||||
if ( ! fake_reverse && fg < 0 && bg < 0 )
|
||||
return;
|
||||
|
||||
if ( fake_reverse )
|
||||
{
|
||||
std::swap (fg, bg);
|
||||
|
||||
if ( fg == Default || bg == Default )
|
||||
setTermDefaultColor(term);
|
||||
}
|
||||
|
||||
change_current_color (term, fg, bg);
|
||||
|
||||
term->fg_color = next->fg_color;
|
||||
term->bg_color = next->bg_color;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::change_to_default_color ( char_data*& term
|
||||
, char_data*& next
|
||||
, short& fg, short& bg )
|
||||
{
|
||||
if ( ansi_default_color )
|
||||
{
|
||||
if ( fg == Default && term->fg_color != Default
|
||||
|
@ -1313,22 +1370,22 @@ void FOptiAttr::change_color (char_data*& term, char_data*& next)
|
|||
}
|
||||
else if ( ! setTermDefaultColor(term) )
|
||||
{
|
||||
// fallback to gray on black
|
||||
// Fallback to gray on black
|
||||
fg = next->fg_color = LightGray;
|
||||
bg = next->bg_color = Black;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! fake_reverse && fg < 0 && bg < 0 )
|
||||
return;
|
||||
|
||||
if ( fake_reverse )
|
||||
{
|
||||
std::swap (fg, bg);
|
||||
|
||||
if ( fg == Default || bg == Default )
|
||||
setTermDefaultColor(term);
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
inline void FOptiAttr::change_current_color ( char_data*& term
|
||||
, short fg, short bg )
|
||||
{
|
||||
char* color_str;
|
||||
char* AF = F_set_a_foreground.cap;
|
||||
char* AB = F_set_a_background.cap;
|
||||
char* Sf = F_set_foreground.cap;
|
||||
char* Sb = F_set_background.cap;
|
||||
char* sp = F_set_color_pair.cap;
|
||||
|
||||
if ( AF && AB )
|
||||
{
|
||||
|
@ -1361,9 +1418,6 @@ void FOptiAttr::change_color (char_data*& term, char_data*& next)
|
|||
if ( (color_str = tparm(sp, fg, bg, 0, 0, 0, 0, 0, 0, 0)) )
|
||||
append_sequence (color_str);
|
||||
}
|
||||
|
||||
term->fg_color = next->fg_color;
|
||||
term->bg_color = next->bg_color;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -4867,7 +4867,7 @@ inline int FTerm::getMetaKey ( char buffer[]
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
int FTerm::getSingleKey (char buffer[], int buf_size)
|
||||
inline int FTerm::getSingleKey (char buffer[], int buf_size)
|
||||
{
|
||||
register uChar firstchar = uChar(buffer[0]);
|
||||
int key, n, len;
|
||||
|
|
Loading…
Reference in New Issue