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

View File

@ -99,26 +99,15 @@ void tcapString (const std::string& name, const char* cap_str)
std::cout << "\r\n";
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
void debug (FApplication& TermApp)
{
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
std::cout << "\n.------------------- debug -------------------\r\n";
#if defined(__linux__)
std::cout << "| Framebuffer bpp: "
<< TermApp.framebuffer_bpp << "\r\n";
#endif
std::cout << "| after init_256colorTerminal(): "
<< TermApp.termtype_256color << "\r\n";
std::cout << "| after parseAnswerbackMsg(): "
@ -134,7 +123,11 @@ int main (int argc, char* argv[])
std::cout << "`------------------- debug -------------------\r\n";
#endif
}
//----------------------------------------------------------------------
void booleans()
{
std::cout << "\r\n[Booleans]\r\n";
tcapBooleans ( "background_color_erase"
, FTermcap::background_color_erase );
@ -150,7 +143,11 @@ int main (int argc, char* argv[])
, FTermcap::osc_support );
tcapBooleans ( "no_utf8_acs_chars"
, FTermcap::no_utf8_acs_chars );
}
//----------------------------------------------------------------------
void numeric()
{
std::cout << "\r\n[Numeric]\r\n";
tcapNumeric ("max_color"
, FTermcap::max_color);
@ -158,7 +155,11 @@ int main (int argc, char* argv[])
, FTermcap::tabstop);
tcapNumeric ("attr_without_color"
, FTermcap::attr_without_color);
}
//----------------------------------------------------------------------
void string(FTermcap::tcap_map*& tcap)
{
std::cout << "\r\n[String]\r\n";
tcapString ("t_bell"
, tcap[fc::t_bell].string);
@ -325,3 +326,27 @@ int main (int argc, char* argv[])
tcapString ("t_key_mouse"
, 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()
<< " Type: " << getTermType() << "\n"
<< " Name: " << getTermName() << "\n"
<< " Mode: " << getEncoding() << "\n"
<< " Mode: " << getEncodingString() << "\n"
<< " Size: " << x << wchar_t(fc::Times)
<< y << "\n"
<< "Colors: " << getMaxColor()

View File

@ -293,6 +293,7 @@ class FTerm
static char termtype_256color[256];
static char termtype_Answerback[256];
static char termtype_SecDA[256];
static int framebuffer_bpp;
#endif
protected:

View File

@ -106,6 +106,7 @@ char FTerm::term_name[256] = {};
char FTerm::termtype_256color[256] = {};
char FTerm::termtype_Answerback[256] = {};
char FTerm::termtype_SecDA[256] = {};
int FTerm::framebuffer_bpp = -1;
#endif
char* FTerm::locale_name = 0;
@ -2730,10 +2731,18 @@ void FTerm::detectTerminal()
if ( linux_terminal )
{
// Underline cursor
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;
#if DEBUG
framebuffer_bpp = bpp;
#endif
}
#endif
#endif