Refactor some functions

This commit is contained in:
Markus Gans 2017-11-24 00:28:25 +01:00
parent 3ced63510c
commit 607294c71a
5 changed files with 201 additions and 75 deletions

View File

@ -205,6 +205,19 @@ class AttribDemo : public FWidget
// Methods // Methods
void printColorLine(); void printColorLine();
void printAltCharset(); void printAltCharset();
void printDim();
void printNormal();
void printBold();
void printBoldDim();
void printItalic();
void printUnderline();
void printDblUnderline();
void printCrossesOut();
void printBlink();
void printReverse();
void printStandout();
void printInvisible();
void printProtected();
void draw(); void draw();
// Data Member // Data Member
@ -266,6 +279,124 @@ void AttribDemo::printAltCharset()
print(" "); print(" ");
} }
//----------------------------------------------------------------------
void AttribDemo::printDim()
{
print(" Dim: ");
setDim();
printColorLine();
unsetDim();
}
//----------------------------------------------------------------------
void AttribDemo::printNormal()
{
print(" Normal: ");
setNormal();
printColorLine();
}
//----------------------------------------------------------------------
void AttribDemo::printBold()
{
print(" Bold: ");
setBold();
printColorLine();
unsetBold();
}
//----------------------------------------------------------------------
void AttribDemo::printBoldDim()
{
print(" Bold+Dim: ");
setBold();
setDim();
printColorLine();
unsetDim();
unsetBold();
}
//----------------------------------------------------------------------
void AttribDemo::printItalic()
{
print(" Italic: ");
setItalic();
printColorLine();
unsetItalic();
}
//----------------------------------------------------------------------
void AttribDemo::printUnderline()
{
print(" Underline: ");
setUnderline();
printColorLine();
unsetUnderline();
}
//----------------------------------------------------------------------
void AttribDemo::printDblUnderline()
{
print(" Double underline: ");
setDoubleUnderline();
printColorLine();
unsetDoubleUnderline();
}
//----------------------------------------------------------------------
void AttribDemo::printCrossesOut()
{
print(" Crossed-out: ");
setCrossedOut();
printColorLine();
unsetCrossedOut();
}
//----------------------------------------------------------------------
void AttribDemo::printBlink()
{
print(" Blink: ");
setBlink();
printColorLine();
unsetBlink();
}
//----------------------------------------------------------------------
void AttribDemo::printReverse()
{
print(" Reverse: ");
setReverse();
printColorLine();
unsetReverse();
}
//----------------------------------------------------------------------
void AttribDemo::printStandout()
{
print(" Standout: ");
setStandout();
printColorLine();
unsetStandout();
}
//----------------------------------------------------------------------
void AttribDemo::printInvisible()
{
print(" Invisible: ");
setInvisible();
printColorLine();
unsetInvisible();
}
//----------------------------------------------------------------------
void AttribDemo::printProtected()
{
print(" Protected: ");
setProtected();
printColorLine();
unsetProtected();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDemo::draw() void AttribDemo::draw()
{ {
@ -282,95 +413,55 @@ void AttribDemo::draw()
switch (y) switch (y)
{ {
case 0: case 0:
print(" Dim: "); printDim();
setDim();
printColorLine();
unsetDim();
break; break;
case 1: case 1:
print(" Normal: "); printNormal();
setNormal();
printColorLine();
break; break;
case 2: case 2:
print(" Bold: "); printBold();
setBold();
printColorLine();
unsetBold();
break; break;
case 3: case 3:
print(" Bold+Dim: "); printBoldDim();
setBold();
setDim();
printColorLine();
unsetDim();
unsetBold();
break; break;
case 4: case 4:
print(" Italic: "); printItalic();
setItalic();
printColorLine();
unsetItalic();
break; break;
case 5: case 5:
print(" Underline: "); printUnderline();
setUnderline();
printColorLine();
unsetUnderline();
break; break;
case 6: case 6:
print(" Double underline: "); printDblUnderline();
setDoubleUnderline();
printColorLine();
unsetDoubleUnderline();
break; break;
case 7: case 7:
print(" Crossed-out: "); printCrossesOut();
setCrossedOut();
printColorLine();
unsetCrossedOut();
break; break;
case 8: case 8:
print(" Blink: "); printBlink();
setBlink();
printColorLine();
unsetBlink();
break; break;
case 9: case 9:
print(" Reverse: "); printReverse();
setReverse();
printColorLine();
unsetReverse();
break; break;
case 10: case 10:
print(" Standout: "); printStandout();
setStandout();
printColorLine();
unsetStandout();
break; break;
case 11: case 11:
print(" Invisible: "); printInvisible();
setInvisible();
printColorLine();
unsetInvisible();
break; break;
case 12: case 12:
print(" Protected: "); printProtected();
setProtected();
printColorLine();
unsetProtected();
break; break;
} }
} }

View File

@ -99,26 +99,15 @@ void tcapString (const std::string& name, const char* cap_str)
std::cout << "\r\n"; std::cout << "\r\n";
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part void debug (FApplication& TermApp)
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{ {
bool disable_alt_screen = true;
FApplication TermApp (argc, argv, disable_alt_screen);
// Pointer to the global virtual terminal object
terminal = static_cast<FVTerm*>(&TermApp);
FTermcap::tcap_map* tcap = 0;
tcap = FTermcap::getTermcapMap();
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";
std::cout << "Terminal: " << TermApp.getTermType() << "\r\n";
#if DEBUG #if DEBUG
std::cout << "\n.------------------- debug -------------------\r\n"; std::cout << "\n.------------------- debug -------------------\r\n";
#if defined(__linux__)
std::cout << "| Framebuffer bpp: "
<< TermApp.framebuffer_bpp << "\r\n";
#endif
std::cout << "| after init_256colorTerminal(): " std::cout << "| after init_256colorTerminal(): "
<< TermApp.termtype_256color << "\r\n"; << TermApp.termtype_256color << "\r\n";
std::cout << "| after parseAnswerbackMsg(): " std::cout << "| after parseAnswerbackMsg(): "
@ -134,7 +123,11 @@ int main (int argc, char* argv[])
std::cout << "`------------------- debug -------------------\r\n"; std::cout << "`------------------- debug -------------------\r\n";
#endif #endif
}
//----------------------------------------------------------------------
void booleans()
{
std::cout << "\r\n[Booleans]\r\n"; std::cout << "\r\n[Booleans]\r\n";
tcapBooleans ( "background_color_erase" tcapBooleans ( "background_color_erase"
, FTermcap::background_color_erase ); , FTermcap::background_color_erase );
@ -150,7 +143,11 @@ int main (int argc, char* argv[])
, FTermcap::osc_support ); , FTermcap::osc_support );
tcapBooleans ( "no_utf8_acs_chars" tcapBooleans ( "no_utf8_acs_chars"
, FTermcap::no_utf8_acs_chars ); , FTermcap::no_utf8_acs_chars );
}
//----------------------------------------------------------------------
void numeric()
{
std::cout << "\r\n[Numeric]\r\n"; std::cout << "\r\n[Numeric]\r\n";
tcapNumeric ("max_color" tcapNumeric ("max_color"
, FTermcap::max_color); , FTermcap::max_color);
@ -158,7 +155,11 @@ int main (int argc, char* argv[])
, FTermcap::tabstop); , FTermcap::tabstop);
tcapNumeric ("attr_without_color" tcapNumeric ("attr_without_color"
, FTermcap::attr_without_color); , FTermcap::attr_without_color);
}
//----------------------------------------------------------------------
void string(FTermcap::tcap_map*& tcap)
{
std::cout << "\r\n[String]\r\n"; std::cout << "\r\n[String]\r\n";
tcapString ("t_bell" tcapString ("t_bell"
, tcap[fc::t_bell].string); , tcap[fc::t_bell].string);
@ -325,3 +326,27 @@ int main (int argc, char* argv[])
tcapString ("t_key_mouse" tcapString ("t_key_mouse"
, tcap[fc::t_key_mouse].string); , tcap[fc::t_key_mouse].string);
} }
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
bool disable_alt_screen = true;
FApplication TermApp (argc, argv, disable_alt_screen);
// Pointer to the global virtual terminal object
terminal = static_cast<FVTerm*>(&TermApp);
FTermcap::tcap_map* tcap = 0;
tcap = FTermcap::getTermcapMap();
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";
std::cout << "Terminal: " << TermApp.getTermType() << "\r\n";
debug (TermApp);
booleans();
numeric();
string(tcap);
}

View File

@ -772,7 +772,7 @@ void MyDialog::cb_terminfo (FWidget*, data_ptr)
, FString() , FString()
<< " Type: " << getTermType() << "\n" << " Type: " << getTermType() << "\n"
<< " Name: " << getTermName() << "\n" << " Name: " << getTermName() << "\n"
<< " Mode: " << getEncoding() << "\n" << " Mode: " << getEncodingString() << "\n"
<< " Size: " << x << wchar_t(fc::Times) << " Size: " << x << wchar_t(fc::Times)
<< y << "\n" << y << "\n"
<< "Colors: " << getMaxColor() << "Colors: " << getMaxColor()

View File

@ -290,9 +290,10 @@ class FTerm
static int UTF8decode (const char[]); static int UTF8decode (const char[]);
#if DEBUG #if DEBUG
static char termtype_256color[256]; static char termtype_256color[256];
static char termtype_Answerback[256]; static char termtype_Answerback[256];
static char termtype_SecDA[256]; static char termtype_SecDA[256];
static int framebuffer_bpp;
#endif #endif
protected: protected:

View File

@ -106,6 +106,7 @@ char FTerm::term_name[256] = {};
char FTerm::termtype_256color[256] = {}; char FTerm::termtype_256color[256] = {};
char FTerm::termtype_Answerback[256] = {}; char FTerm::termtype_Answerback[256] = {};
char FTerm::termtype_SecDA[256] = {}; char FTerm::termtype_SecDA[256] = {};
int FTerm::framebuffer_bpp = -1;
#endif #endif
char* FTerm::locale_name = 0; char* FTerm::locale_name = 0;
@ -2711,7 +2712,7 @@ void FTerm::detectTerminal()
FTermcap::max_color = 16; FTermcap::max_color = 16;
} }
// Initialize Linux console // Initialize Linux console
#if defined(__linux__) #if defined(__linux__)
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(__x86_64__) || defined(__i386) || defined(__arm__)
// Enable 16 background colors // Enable 16 background colors
@ -2730,10 +2731,18 @@ void FTerm::detectTerminal()
if ( linux_terminal ) if ( linux_terminal )
{ {
// Underline cursor
setLinuxConsoleCursorStyle (fc::underscore_cursor, true); setLinuxConsoleCursorStyle (fc::underscore_cursor, true);
if ( getFramebuffer_bpp() >= 4 ) // Framebuffer color depth in bits per pixel
int bpp = getFramebuffer_bpp();
if ( bpp >= 4 )
FTermcap::max_color = 16; FTermcap::max_color = 16;
#if DEBUG
framebuffer_bpp = bpp;
#endif
} }
#endif #endif
#endif #endif