Display: Abstract terminfo capability functions

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2013-01-27 21:36:05 -05:00
committed by Keith Winstein
parent 03217ddb5a
commit 2ae960f7f0
2 changed files with 34 additions and 21 deletions
+4
View File
@@ -65,6 +65,10 @@ namespace Terminal {
class Display { class Display {
private: private:
bool ti_flag( const char *capname ) const;
int ti_num( const char *capname ) const;
const char *ti_str( const char *capname ) const;
bool has_ech; /* erase character is part of vt200 but not supported by tmux bool has_ech; /* erase character is part of vt200 but not supported by tmux
(or by "screen" terminfo entry, which is what tmux advertises) */ (or by "screen" terminfo entry, which is what tmux advertises) */
+30 -21
View File
@@ -61,6 +61,33 @@
using namespace Terminal; using namespace Terminal;
bool Display::ti_flag( const char *capname ) const
{
int val = tigetflag( const_cast<char *>( capname ) );
if ( val == -1 ) {
throw std::string( "Invalid terminfo boolean capability " ) + capname;
}
return val;
}
int Display::ti_num( const char *capname ) const
{
int val = tigetnum( const_cast<char *>( capname ) );
if ( val == -2 ) {
throw std::string( "Invalid terminfo numeric capability " ) + capname;
}
return val;
}
const char *Display::ti_str( const char *capname ) const
{
const char *val = tigetstr( const_cast<char *>( capname ) );
if ( val == (const char *)-1 ) {
throw std::string( "Invalid terminfo string capability " ) + capname;
}
return val;
}
Display::Display( bool use_environment ) Display::Display( bool use_environment )
: has_ech( true ), has_bce( true ), has_title( true ), posterize_colors( false ) : has_ech( true ), has_bce( true ), has_title( true ), posterize_colors( false )
{ {
@@ -86,22 +113,10 @@ Display::Display( bool use_environment )
} }
/* check for ECH */ /* check for ECH */
char ech_name[] = "ech"; has_ech = ti_str( "ech" );
char *val = tigetstr( ech_name );
if ( val == (char *)-1 ) {
throw std::string( "Invalid terminfo string capability " ) + ech_name;
} else if ( val == 0 ) {
has_ech = false;
}
/* check for BCE */ /* check for BCE */
char bce_name[] = "bce"; has_bce = ti_flag( "bce" );
int bce_val = tigetflag( bce_name );
if ( bce_val == -1 ) {
throw std::string( "Invalid terminfo boolean capability " ) + bce_name;
} else if ( bce_val == 0 ) {
has_bce = false;
}
/* Check if we can set the window title and icon name. terminfo does not /* Check if we can set the window title and icon name. terminfo does not
have reliable information on this, so we hardcode a whitelist of have reliable information on this, so we hardcode a whitelist of
@@ -128,13 +143,7 @@ Display::Display( bool use_environment )
/* posterization disabled because server now only advertises /* posterization disabled because server now only advertises
xterm-256color when client has colors = 256 */ xterm-256color when client has colors = 256 */
/* /*
char colors_name[] = "colors"; posterize_colors = ti_num( "colors" ) < 256;
int color_val = tigetnum( colors_name );
if ( color_val == -2 ) {
throw std::string( "Invalid terminfo numeric capability " ) + colors_name;
} else if ( color_val < 256 ) {
posterize_colors = true;
}
*/ */
} }
} }