Support 256color (and assume 256color terminal). Closes #3 github issue.
This commit is contained in:
@@ -95,7 +95,7 @@ int main( void )
|
|||||||
|
|
||||||
if ( child == 0 ) {
|
if ( child == 0 ) {
|
||||||
/* child */
|
/* child */
|
||||||
if ( setenv( "TERM", "xterm", true ) < 0 ) {
|
if ( setenv( "TERM", "xterm-256color", true ) < 0 ) {
|
||||||
perror( "setenv" );
|
perror( "setenv" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ int run_server( const char *desired_ip, const char *desired_port ) {
|
|||||||
fatal_assert( sigprocmask( SIG_SETMASK, &signals_to_block, NULL ) == 0 );
|
fatal_assert( sigprocmask( SIG_SETMASK, &signals_to_block, NULL ) == 0 );
|
||||||
|
|
||||||
/* set TERM */
|
/* set TERM */
|
||||||
if ( setenv( "TERM", "xterm", true ) < 0 ) {
|
if ( setenv( "TERM", "xterm-256color", true ) < 0 ) {
|
||||||
perror( "setenv" );
|
perror( "setenv" );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ Renditions::Renditions( int s_background )
|
|||||||
background_color( s_background )
|
background_color( s_background )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/* This routine cannot be used to set a color beyond the 8-color set. */
|
||||||
void Renditions::set_rendition( int num )
|
void Renditions::set_rendition( int num )
|
||||||
{
|
{
|
||||||
if ( num == 0 ) {
|
if ( num == 0 ) {
|
||||||
@@ -377,10 +378,18 @@ void Renditions::set_rendition( int num )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (30 <= num) && (num <= 39) ) { /* foreground color */
|
if ( num == 39 ) {
|
||||||
|
foreground_color = 0;
|
||||||
|
return;
|
||||||
|
} else if ( num == 49 ) {
|
||||||
|
background_color = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (30 <= num) && (num <= 37) ) { /* foreground color in 8-color set */
|
||||||
foreground_color = num;
|
foreground_color = num;
|
||||||
return;
|
return;
|
||||||
} else if ( (40 <= num) && (num <= 49) ) { /* background color */
|
} else if ( (40 <= num) && (num <= 47) ) { /* background color in 8-color set */
|
||||||
background_color = num;
|
background_color = num;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -394,6 +403,20 @@ void Renditions::set_rendition( int num )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renditions::set_foreground_color( int num )
|
||||||
|
{
|
||||||
|
if ( (0 <= num) && (num <= 255) ) {
|
||||||
|
foreground_color = 30 + num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renditions::set_background_color( int num )
|
||||||
|
{
|
||||||
|
if ( (0 <= num) && (num <= 255) ) {
|
||||||
|
background_color = 40 + num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string Renditions::sgr( void ) const
|
std::string Renditions::sgr( void ) const
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
@@ -404,16 +427,27 @@ std::string Renditions::sgr( void ) const
|
|||||||
if ( blink ) ret.append( ";5" );
|
if ( blink ) ret.append( ";5" );
|
||||||
if ( inverse ) ret.append( ";7" );
|
if ( inverse ) ret.append( ";7" );
|
||||||
if ( invisible ) ret.append( ";8" );
|
if ( invisible ) ret.append( ";8" );
|
||||||
if ( foreground_color ) {
|
|
||||||
|
if ( foreground_color > 37 ) { /* use 256-color set */
|
||||||
|
char col[ 64 ];
|
||||||
|
snprintf( col, 64, "m\033[38;5;%d", foreground_color - 30 );
|
||||||
|
ret.append( col );
|
||||||
|
} else if ( foreground_color ) {
|
||||||
char col[ 8 ];
|
char col[ 8 ];
|
||||||
snprintf( col, 8, ";%d", foreground_color );
|
snprintf( col, 8, ";%d", foreground_color );
|
||||||
ret.append( col );
|
ret.append( col );
|
||||||
}
|
}
|
||||||
if ( background_color ) {
|
|
||||||
|
if ( background_color > 47 ) { /* use 256-color set */
|
||||||
|
char col[ 64 ];
|
||||||
|
snprintf( col, 64, "m\033[48;5;%d", background_color - 40 );
|
||||||
|
ret.append( col );
|
||||||
|
} else if ( background_color ) {
|
||||||
char col[ 8 ];
|
char col[ 8 ];
|
||||||
snprintf( col, 8, ";%d", background_color );
|
snprintf( col, 8, ";%d", background_color );
|
||||||
ret.append( col );
|
ret.append( col );
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.append( "m" );
|
ret.append( "m" );
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ namespace Terminal {
|
|||||||
int background_color;
|
int background_color;
|
||||||
|
|
||||||
Renditions( int s_background );
|
Renditions( int s_background );
|
||||||
|
void set_foreground_color( int num );
|
||||||
|
void set_background_color( int num );
|
||||||
void set_rendition( int num );
|
void set_rendition( int num );
|
||||||
std::string sgr( void ) const;
|
std::string sgr( void ) const;
|
||||||
|
|
||||||
@@ -182,9 +184,11 @@ namespace Terminal {
|
|||||||
int limit_top( void );
|
int limit_top( void );
|
||||||
int limit_bottom( void );
|
int limit_bottom( void );
|
||||||
|
|
||||||
|
void set_foreground_color( int x ) { renditions.set_foreground_color( x ); }
|
||||||
|
void set_background_color( int x ) { renditions.set_background_color( x ); }
|
||||||
void add_rendition( int x ) { renditions.set_rendition( x ); }
|
void add_rendition( int x ) { renditions.set_rendition( x ); }
|
||||||
Renditions get_renditions( void ) const { return renditions; }
|
Renditions get_renditions( void ) const { return renditions; }
|
||||||
int get_background_rendition( void ) { return renditions.background_color; }
|
int get_background_rendition( void ) const { return renditions.background_color; }
|
||||||
|
|
||||||
void save_cursor( void );
|
void save_cursor( void );
|
||||||
void restore_cursor( void );
|
void restore_cursor( void );
|
||||||
|
|||||||
@@ -332,9 +332,24 @@ static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL );
|
|||||||
/* select graphics rendition -- e.g., bold, blinking, etc. */
|
/* select graphics rendition -- e.g., bold, blinking, etc. */
|
||||||
void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch )
|
void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < dispatch->param_count(); i++ ) {
|
/* We need to special-case the handling of CSI [34]8 ; 5 ; Ps m,
|
||||||
int rendition = dispatch->getparam( i, 0 );
|
because Ps of 0 in that case does not mean reset to default, even
|
||||||
fb->ds.add_rendition( rendition );
|
though it means that otherwise (as usually renditions are applied
|
||||||
|
in order). */
|
||||||
|
|
||||||
|
if ( (dispatch->param_count() == 3)
|
||||||
|
&& (dispatch->getparam( 0, -1 ) == 38)
|
||||||
|
&& (dispatch->getparam( 1, -1 ) == 5) ) {
|
||||||
|
fb->ds.set_foreground_color( dispatch->getparam( 2, 0 ) );
|
||||||
|
} else if ( (dispatch->param_count() == 3)
|
||||||
|
&& (dispatch->getparam( 0, -1 ) == 48)
|
||||||
|
&& (dispatch->getparam( 1, -1 ) == 5) ) {
|
||||||
|
fb->ds.set_background_color( dispatch->getparam( 2, 0 ) );
|
||||||
|
} else {
|
||||||
|
for ( int i = 0; i < dispatch->param_count(); i++ ) {
|
||||||
|
int rendition = dispatch->getparam( i, 0 );
|
||||||
|
fb->ds.add_rendition( rendition );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user