Refactoring attribute settings in FOptiAttr

This commit is contained in:
Markus Gans 2018-01-03 20:06:22 +01:00
parent 76d72208e5
commit 9bb22e7d7b
4 changed files with 188 additions and 126 deletions

View File

@ -1,4 +1,5 @@
2017-01-02 Markus Gans <guru.mail@muenster.de> 2017-01-02 Markus Gans <guru.mail@muenster.de>
* Refactoring attribute settings in FOptiAttr
* Refactoring FTerm::parseKeyString and timeout settings * Refactoring FTerm::parseKeyString and timeout settings
2017-01-02 Markus Gans <guru.mail@muenster.de> 2017-01-02 Markus Gans <guru.mail@muenster.de>

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -270,7 +270,14 @@ class FOptiAttr
bool colorChange (char_data*&, char_data*&); bool colorChange (char_data*&, char_data*&);
void resetColor (char_data*&); void resetColor (char_data*&);
void prevent_no_color_video_attributes (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_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 resetAttribute (char_data*&);
void reset (char_data*&); void reset (char_data*&);
bool caused_reset_attributes (char[], uChar = all_tests); bool caused_reset_attributes (char[], uChar = all_tests);

View File

@ -539,98 +539,23 @@ char* FOptiAttr::changeAttribute (char_data*& term, char_data*& next)
if ( ! F_enter_secure_mode.cap && next->attr.bit.invisible ) if ( ! F_enter_secure_mode.cap && next->attr.bit.invisible )
next->code = ' '; next->code = ' ';
// look for no changes // Look for no changes
if ( ! ( switchOn() || switchOff() || colorChange(term, next) ) ) if ( ! ( switchOn() || switchOff() || colorChange(term, next) ) )
return 0; return 0;
if ( cygwin_terminal && (term->fg_color > 7 || term->bg_color > 7) ) preProcessing_cygwin_quirks(term);
{
// reset blink and bold mode from colors > 7
char rst[] = CSI "m";
append_sequence (rst);
reset(term);
}
if ( hasNoAttribute(next) ) if ( hasNoAttribute(next) )
{ {
if ( hasAttribute(term) ) deactivateAttributes (term, next);
{
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);
} }
else if ( F_set_attributes.cap && ! term->attr.bit.pc_charset ) else if ( F_set_attributes.cap && ! term->attr.bit.pc_charset )
{ {
if ( switchOn() || switchOff() ) changeAttributeSGR (term, next);
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);
}
}
} }
else else
{ {
setAttributesOff(term); changeAttributeSeparately (term, next);
detectSwitchOff (term, next);
if ( switchOff() )
unsetTermAttributes(term);
if ( colorChange(term, next) )
change_color (term, next);
detectSwitchOn (term, next);
setAttributesOn(term);
} }
if ( term && fake_reverse ) 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) 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; short fg, bg;
if ( monochron || ! (term && next) ) if ( monochron || ! (term && next) )
@ -1283,41 +1317,7 @@ void FOptiAttr::change_color (char_data*& term, char_data*& next)
bg = next->bg_color; bg = next->bg_color;
if ( fg == Default || bg == Default ) if ( fg == Default || bg == Default )
{ change_to_default_color (term, next, fg, bg);
if ( ansi_default_color )
{
if ( fg == Default && term->fg_color != Default
&& bg == Default && term->bg_color != Default )
{
setTermDefaultColor(term);
}
else if ( fg == Default && term->fg_color != Default )
{
char sgr_39[] = CSI "39m";
append_sequence (sgr_39);
term->fg_color = Default;
}
else if ( bg == Default && term->bg_color != Default )
{
char* sgr_49;
char* 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 = Default;
}
}
else if ( ! setTermDefaultColor(term) )
{
// fallback to gray on black
fg = next->fg_color = LightGray;
bg = next->bg_color = Black;
}
}
if ( ! fake_reverse && fg < 0 && bg < 0 ) if ( ! fake_reverse && fg < 0 && bg < 0 )
return; return;
@ -1330,6 +1330,63 @@ void FOptiAttr::change_color (char_data*& term, char_data*& next)
setTermDefaultColor(term); 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
&& bg == Default && term->bg_color != Default )
{
setTermDefaultColor(term);
}
else if ( fg == Default && term->fg_color != Default )
{
char sgr_39[] = CSI "39m";
append_sequence (sgr_39);
term->fg_color = Default;
}
else if ( bg == Default && term->bg_color != Default )
{
char* sgr_49;
char* 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 = Default;
}
}
else if ( ! setTermDefaultColor(term) )
{
// Fallback to gray on black
fg = next->fg_color = LightGray;
bg = next->bg_color = Black;
}
}
//----------------------------------------------------------------------
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 ) if ( AF && AB )
{ {
short ansi_fg = vga2ansi(fg); short ansi_fg = vga2ansi(fg);
@ -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)) ) if ( (color_str = tparm(sp, fg, bg, 0, 0, 0, 0, 0, 0, 0)) )
append_sequence (color_str); append_sequence (color_str);
} }
term->fg_color = next->fg_color;
term->bg_color = next->bg_color;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -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]); register uChar firstchar = uChar(buffer[0]);
int key, n, len; int key, n, len;