Determine xterm maximum number of colors via OSC 4

This commit is contained in:
Markus Gans 2016-11-05 23:12:05 +01:00
parent b9cc271765
commit e66f00ea92
7 changed files with 113 additions and 34 deletions

View File

@ -1,3 +1,8 @@
2016-11-05 Markus Gans <guru.mail@muenster.de>
* Determine xterm maximum number of colors via OSC 4
* The method clearArea can now fill the background
with certain character
2016-11-03 Markus Gans <guru.mail@muenster.de> 2016-11-03 Markus Gans <guru.mail@muenster.de>
* xterm should be able to use at least 16 colors * xterm should be able to use at least 16 colors

View File

@ -813,6 +813,39 @@ const FString FTerm::getXTermTitle()
return title; return title;
} }
//----------------------------------------------------------------------
const FString FTerm::getXTermColorName (int color)
{
FString color_str("");
if ( raw_mode && non_blocking_stdin )
{
int n;
int c = color;
int digits = 0;
while ( c /= 10 )
digits++;
char temp[512] = {};
putstringf (OSC "4;%d;?" BEL, color); // get color
std::fflush(stdout);
usleep(150000); // wait 150 ms
// read the terminal answer
n = int(read(fileno(stdin), &temp, sizeof(temp)-1));
// BEL + '\0' = string terminator
if ( n >= 6 && temp[n-1] == BEL[0] && temp[n] == '\0' )
{
temp[n-1] = '\0';
color_str = static_cast<char*>(temp + 6 + digits);
}
}
return color_str;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::setXTermCursorStyle (fc::xtermCursorStyle style) void FTerm::setXTermCursorStyle (fc::xtermCursorStyle style)
{ {
@ -1544,6 +1577,16 @@ bool FTerm::gpmMouse (bool on)
// private methods of FTerm // private methods of FTerm
//----------------------------------------------------------------------
int FTerm::isConsole()
{
char arg = 0;
// get keyboard type an compare
return ( isatty (fd_tty)
&& ioctl(fd_tty, KDGKBTYPE, &arg) == 0
&& ((arg == KB_101) || (arg == KB_84)) );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline uInt16 FTerm::getInputStatusRegisterOne() inline uInt16 FTerm::getInputStatusRegisterOne()
{ {
@ -1705,16 +1748,6 @@ int FTerm::closeConsole()
return -1; return -1;
} }
//----------------------------------------------------------------------
int FTerm::isConsole()
{
char arg = 0;
// get keyboard type an compare
return ( isatty (fd_tty)
&& ioctl(fd_tty, KDGKBTYPE, &arg) == 0
&& ((arg == KB_101) || (arg == KB_84)) );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::identifyTermType() void FTerm::identifyTermType()
{ {
@ -2954,6 +2987,22 @@ void FTerm::init()
// Identify the terminal via the secondary device attributes (SEC_DA) // Identify the terminal via the secondary device attributes (SEC_DA)
new_termtype = parseSecDA (new_termtype); new_termtype = parseSecDA (new_termtype);
if ( ! color256 && getXTermColorName(0) != "" )
{
if ( getXTermColorName(256) != "" )
{
new_termtype = const_cast<char*>("xterm-256color");
}
else if ( FTermcap::max_color < 88 && getXTermColorName(87) != "" )
{
new_termtype = const_cast<char*>("xterm-88color");
}
else if ( FTermcap::max_color < 16 && getXTermColorName(15) != "" )
{
new_termtype = const_cast<char*>("xterm-16color");
}
}
unsetRawMode(); unsetRawMode();
// ...end of terminal detection // ...end of terminal detection
@ -3069,19 +3118,7 @@ void FTerm::init()
} }
setXTermCursorStyle(fc::blinking_underline); setXTermCursorStyle(fc::blinking_underline);
setXTermMouseBackground("rgb:ffff/ffff/ffff"); setXTermColors();
setXTermMouseForeground ("rgb:0000/0000/0000");
if ( ! gnome_terminal )
setXTermCursorColor("rgb:ffff/ffff/ffff");
if ( ! (mintty_terminal || rxvt_terminal || screen_terminal) )
{
// mintty and rxvt can't reset these settings
setXTermBackground("rgb:8080/a4a4/ecec");
setXTermForeground("rgb:0000/0000/0000");
setXTermHighlightBackground("rgb:8686/8686/8686");
}
setRawMode(); setRawMode();
@ -3313,6 +3350,24 @@ void FTerm::finish()
delete opti_move; delete opti_move;
} }
//----------------------------------------------------------------------
void FTerm::setXTermColors()
{
setXTermMouseBackground("rgb:ffff/ffff/ffff");
setXTermMouseForeground ("rgb:0000/0000/0000");
if ( ! gnome_terminal )
setXTermCursorColor("rgb:ffff/ffff/ffff");
if ( ! (mintty_terminal || rxvt_terminal || screen_terminal) )
{
// mintty and rxvt can't reset these settings
setXTermBackground("rgb:8080/a4a4/ecec");
setXTermForeground("rgb:0000/0000/0000");
setXTermHighlightBackground("rgb:8686/8686/8686");
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt FTerm::cp437_to_unicode (uChar c) uInt FTerm::cp437_to_unicode (uChar c)
{ {

View File

@ -168,6 +168,7 @@ class FTerm
static void setKDECursor (fc::kdeKonsoleCursorShape); static void setKDECursor (fc::kdeKonsoleCursorShape);
static const FString getXTermFont(); static const FString getXTermFont();
static const FString getXTermTitle(); static const FString getXTermTitle();
static const FString getXTermColorName (int);
static void setXTermCursorStyle (fc::xtermCursorStyle); static void setXTermCursorStyle (fc::xtermCursorStyle);
static void setXTermTitle (const FString&); static void setXTermTitle (const FString&);
static void setXTermForeground (const FString&); static void setXTermForeground (const FString&);
@ -201,6 +202,7 @@ class FTerm
// function pointer -> static function // function pointer -> static function
static int (*Fputchar)(int); static int (*Fputchar)(int);
static void putstringf (const char*, ...) static void putstringf (const char*, ...)
#if defined(__clang__) #if defined(__clang__)
__attribute__((__format__ (__printf__, 1, 2))) __attribute__((__format__ (__printf__, 1, 2)))
@ -267,6 +269,9 @@ class FTerm
// Disable assignment operator (=) // Disable assignment operator (=)
FTerm& operator = (const FTerm&); FTerm& operator = (const FTerm&);
// Inquiries
static int isConsole();
// Methods // Methods
static uInt16 getInputStatusRegisterOne(); static uInt16 getInputStatusRegisterOne();
static uChar readAttributeController (uChar); static uChar readAttributeController (uChar);
@ -277,7 +282,6 @@ class FTerm
static int getFramebuffer_bpp(); static int getFramebuffer_bpp();
static int openConsole(); static int openConsole();
static int closeConsole(); static int closeConsole();
static int isConsole();
static void identifyTermType(); static void identifyTermType();
static int getScreenFont(); static int getScreenFont();
static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false); static int setScreenFont (uChar*, uInt, uInt, uInt, bool = false);
@ -296,6 +300,7 @@ class FTerm
static void init_encoding(); static void init_encoding();
void init(); void init();
void finish(); void finish();
static void setXTermColors();
static uInt cp437_to_unicode (uChar); static uInt cp437_to_unicode (uChar);
static void signal_handler (int); static void signal_handler (int);

View File

@ -121,18 +121,20 @@ bool FVTerm::hideCursor (bool on)
char* hide_str = disableCursor(); char* hide_str = disableCursor();
if ( hide_str ) if ( hide_str )
{
appendOutputBuffer (hide_str); appendOutputBuffer (hide_str);
hidden_cursor = true; // global
hidden_cursor = true; // global }
} }
else else
{ {
char* show_str = enableCursor(); char* show_str = enableCursor();
if ( show_str ) if ( show_str )
{
appendOutputBuffer (show_str); appendOutputBuffer (show_str);
hidden_cursor = false;
hidden_cursor = false; }
} }
flush_out(); flush_out();
@ -1160,6 +1162,7 @@ void FVTerm::restoreVTerm (int x, int y, int w, int h)
|| s_ch.code == fc::UpperHalfBlock || s_ch.code == fc::UpperHalfBlock
|| s_ch.code == fc::LeftHalfBlock || s_ch.code == fc::LeftHalfBlock
|| s_ch.code == fc::RightHalfBlock || s_ch.code == fc::RightHalfBlock
|| s_ch.code == fc::MediumShade
|| s_ch.code == fc::FullBlock ) || s_ch.code == fc::FullBlock )
s_ch.code = ' '; s_ch.code = ' ';
@ -1360,6 +1363,7 @@ void FVTerm::updateVTerm (term_area* area)
|| ch.code == fc::UpperHalfBlock || ch.code == fc::UpperHalfBlock
|| ch.code == fc::LeftHalfBlock || ch.code == fc::LeftHalfBlock
|| ch.code == fc::RightHalfBlock || ch.code == fc::RightHalfBlock
|| ch.code == fc::MediumShade
|| ch.code == fc::FullBlock ) || ch.code == fc::FullBlock )
ch.code = ' '; ch.code = ' ';
@ -1388,6 +1392,7 @@ void FVTerm::updateVTerm (term_area* area)
|| ch.code == fc::UpperHalfBlock || ch.code == fc::UpperHalfBlock
|| ch.code == fc::LeftHalfBlock || ch.code == fc::LeftHalfBlock
|| ch.code == fc::RightHalfBlock || ch.code == fc::RightHalfBlock
|| ch.code == fc::MediumShade
|| ch.code == fc::FullBlock ) || ch.code == fc::FullBlock )
ch.code = ' '; ch.code = ' ';
@ -1707,6 +1712,7 @@ void FVTerm::putArea (int ax, int ay, term_area* area)
|| ch.code == fc::UpperHalfBlock || ch.code == fc::UpperHalfBlock
|| ch.code == fc::LeftHalfBlock || ch.code == fc::LeftHalfBlock
|| ch.code == fc::RightHalfBlock || ch.code == fc::RightHalfBlock
|| ch.code == fc::MediumShade
|| ch.code == fc::FullBlock ) || ch.code == fc::FullBlock )
ch.code = ' '; ch.code = ' ';
@ -1820,7 +1826,7 @@ void FVTerm::scrollAreaReverse (term_area* area)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FVTerm::clearArea (term_area* area) void FVTerm::clearArea (term_area* area, int fillchar)
{ {
// clear the area with the current attributes // clear the area with the current attributes
char_data nc; // next character char_data nc; // next character
@ -1829,7 +1835,7 @@ void FVTerm::clearArea (term_area* area)
// current attributes with a space character // current attributes with a space character
std::memcpy (&nc, &next_attribute, sizeof(char_data)); std::memcpy (&nc, &next_attribute, sizeof(char_data));
nc.code = ' '; nc.code = fillchar;
if ( ! area ) if ( ! area )
return; return;

View File

@ -279,7 +279,7 @@ class FVTerm : public FObject, public FTerm
static void putArea (int, int, term_area*); static void putArea (int, int, term_area*);
static void scrollAreaForward (term_area*); static void scrollAreaForward (term_area*);
static void scrollAreaReverse (term_area*); static void scrollAreaReverse (term_area*);
static void clearArea (term_area*); static void clearArea (term_area*, int = ' ');
static char_data getCharacter ( character_type static char_data getCharacter ( character_type
, const FPoint& , const FPoint&

View File

@ -243,7 +243,7 @@ Calc::Calc (FWidget* parent)
setText ("calculator"); setText ("calculator");
setGeometry (19, 6, 37, 18); setGeometry (19, 6, 37, 18);
addAccelerator('q'); // press 'q' to quit addAccelerator('q'); // press 'q' to quit
setShadow(); //setShadow();
for (int key=0; key < Calc::NUM_OF_BUTTONS; key++) for (int key=0; key < Calc::NUM_OF_BUTTONS; key++)
{ {
@ -372,6 +372,10 @@ void Calc::drawDispay()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::draw() void Calc::draw()
{ {
setBold();
setColor (fc::Blue, fc::Cyan);
clearArea (vdesktop, fc::MediumShade);
unsetBold();
FDialog::draw(); FDialog::draw();
drawDispay(); drawDispay();
} }

View File

@ -79,7 +79,11 @@ void Transparent::draw()
} }
else if ( type == inherit_background ) else if ( type == inherit_background )
{ {
setColor(fc::Blue, fc::Black); if ( getMaxColor() > 8 )
setColor(fc::Blue, fc::Black);
else
setColor(fc::Green, fc::Black);
setInheritBackground(); setInheritBackground();
} }
else else