diff --git a/terminaldisplay.cpp b/terminaldisplay.cpp index 54eedc5..3e85451 100644 --- a/terminaldisplay.cpp +++ b/terminaldisplay.cpp @@ -49,19 +49,18 @@ std::string Display::new_frame( Framebuffer &f ) /* iterate for every cell */ for ( int y = 0; y < f.ds.get_height(); y++ ) { for ( int x = 0; x < f.ds.get_width(); /* let charwidth handle advance */ ) { - std::string cell_string; Cell *cell = f.get_cell( y, x ); - bool different = false; + + if ( initialized + && ( *cell == *(last_frame.get_cell( y, x )) ) ) { + x += cell->width; + continue; + } char curmove[ 32 ]; snprintf( curmove, 32, "\033[%d;%dH", y + 1, x + 1 ); - cell_string.append( curmove ); - - /* have renditions changed? */ - if ( (!initialized) - || (cell->renditions != last_frame.get_cell( y, x )->renditions) ) { - different = true; - } + screen.append( curmove ); + cursor_was_moved = true; std::vector cell_print_renditions; cell_print_renditions = cell->renditions; @@ -69,53 +68,35 @@ std::string Display::new_frame( Framebuffer &f ) if ( cell_print_renditions != current_renditions ) { /* print renditions */ - cell_string.append( "\033[0" ); + screen.append( "\033[0" ); char rendition[ 32 ]; for ( std::vector::iterator i = cell->renditions.begin(); i != cell->renditions.end(); i++ ) { snprintf( rendition, 32, ";%d", *i ); - cell_string.append( rendition ); + screen.append( rendition ); } - cell_string.append( "m" ); + screen.append( "m" ); + + current_renditions = cell_print_renditions; } /* clear cell */ - cell_string.append( "\033[X" ); - - /* did fallback status change? */ - if ( (!initialized) - || (cell->fallback != last_frame.get_cell( y, x )->fallback) ) { - different = true; - } + screen.append( "\033[X" ); /* cells that begin with combining character get combiner attached to no-break space */ if ( cell->fallback ) { char utf8[ 8 ]; snprintf( utf8, 8, "%lc", 0xA0 ); - cell_string.append( utf8 ); + screen.append( utf8 ); } - /* have cell contents changed? */ - if ( (!initialized) - || (cell->contents != last_frame.get_cell( y, x )->contents) ) { - different = true; - } - - /* always restrike the cell contents if anything changed */ for ( std::vector::iterator i = cell->contents.begin(); i != cell->contents.end(); i++ ) { char utf8[ 8 ]; snprintf( utf8, 8, "%lc", *i ); - cell_string.append( utf8 ); - } - - /* if anything changed, redo cell */ - if ( different ) { - screen.append( cell_string ); - cursor_was_moved = true; - current_renditions = cell_print_renditions; + screen.append( utf8 ); } x += cell->width; diff --git a/terminalframebuffer.cpp b/terminalframebuffer.cpp index 0ab0e5a..ae966a7 100644 --- a/terminalframebuffer.cpp +++ b/terminalframebuffer.cpp @@ -25,6 +25,17 @@ void Cell::reset( void ) need_back_color_erase = true; } +bool Cell::operator==( const Cell &x ) +{ + assert( !need_back_color_erase ); + assert( !x.need_back_color_erase ); + + return ( (contents == x.contents) + && (fallback == x.fallback) + && (width == x.width) + && (renditions == x.renditions) ); +} + DrawState::DrawState( int s_width, int s_height ) : width( s_width ), height( s_height ), cursor_col( 0 ), cursor_row( 0 ), @@ -412,16 +423,14 @@ void Framebuffer::back_color_erase( void ) { int bg_color = ds.get_background_rendition(); - if ( bg_color < 0 ) { - return; - } - for ( int row = 0; row < ds.get_height(); row++ ) { for ( int col = 0; col < ds.get_width(); col++ ) { Cell *cell = get_cell( row, col ); if ( cell->need_back_color_erase ) { assert( cell->renditions.empty() ); - cell->renditions.push_back( bg_color ); + if ( bg_color > 0 ) { + cell->renditions.push_back( bg_color ); + } cell->need_back_color_erase = false; } } diff --git a/terminalframebuffer.hpp b/terminalframebuffer.hpp index 15bfe0a..1e86275 100644 --- a/terminalframebuffer.hpp +++ b/terminalframebuffer.hpp @@ -19,6 +19,8 @@ namespace Terminal { Cell(); void reset( void ); + + bool operator==( const Cell &x ); }; class Row {