diff --git a/src/terminal/terminalfunctions.cc b/src/terminal/terminalfunctions.cc index 833fb7d..5cab15a 100644 --- a/src/terminal/terminalfunctions.cc +++ b/src/terminal/terminalfunctions.cc @@ -380,24 +380,22 @@ static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL ); /* select graphics rendition -- e.g., bold, blinking, etc. */ static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) { - /* We need to special-case the handling of CSI [34]8 ; 5 ; Ps m, - because Ps of 0 in that case does not mean reset to default, even - 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 ); + for ( int i = 0; i < dispatch->param_count(); i++ ) { + int rendition = dispatch->getparam( i, 0 ); + /* We need to special-case the handling of [34]8 ; 5 ; Ps, + because Ps of 0 in that case does not mean reset to default, even + though it means that otherwise (as usually renditions are applied + in order). */ + if ((rendition == 38 || rendition == 48) && + (dispatch->param_count() - i >= 3) && + (dispatch->getparam( i+1, -1 ) == 5)) { + (rendition == 38) ? + fb->ds.set_foreground_color( dispatch->getparam( i+2, 0 ) ) : + fb->ds.set_background_color( dispatch->getparam( i+2, 0 ) ); + i += 2; + continue; } + fb->ds.add_rendition( rendition ); } }