diff --git a/templates.cpp b/templates.cpp index ff66ccd..ffca101 100644 --- a/templates.cpp +++ b/templates.cpp @@ -21,4 +21,5 @@ template class vector; template class vector; template class map; template class vector; - +template class list; +template void std::list >::remove_if(bool (*)(int const&)); diff --git a/terminal.cpp b/terminal.cpp index f996d86..2097596 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -154,7 +154,7 @@ void Emulator::debug_printout( int fd ) /* print renditions */ screen.append( "\033[0" ); char rendition[ 32 ]; - for ( std::vector::iterator i = cell->renditions.begin(); + for ( std::list::iterator i = cell->renditions.begin(); i != cell->renditions.end(); i++ ) { snprintf( rendition, 32, ";%d", *i ); diff --git a/terminal.hpp b/terminal.hpp index 0f8c3a8..8598047 100644 --- a/terminal.hpp +++ b/terminal.hpp @@ -16,7 +16,7 @@ namespace Terminal { private: bool initialized; Framebuffer last_frame; - std::vector current_renditions; + std::list current_renditions; public: Display( int width, int height ) diff --git a/terminaldisplay.cpp b/terminaldisplay.cpp index e18707a..a8d2851 100644 --- a/terminaldisplay.cpp +++ b/terminaldisplay.cpp @@ -66,7 +66,7 @@ std::string Display::new_frame( Framebuffer &f ) cursor_was_moved = true; } - std::vector cell_print_renditions; + std::list cell_print_renditions; cell_print_renditions = cell->renditions; cell_print_renditions.insert( cell_print_renditions.begin(), 0 ); @@ -74,7 +74,7 @@ std::string Display::new_frame( Framebuffer &f ) /* print renditions */ screen.append( "\033[0" ); char rendition[ 32 ]; - for ( std::vector::iterator i = cell->renditions.begin(); + for ( std::list::iterator i = cell->renditions.begin(); i != cell->renditions.end(); i++ ) { snprintf( rendition, 32, ";%d", *i ); diff --git a/terminalframebuffer.cpp b/terminalframebuffer.cpp index ae966a7..41d3042 100644 --- a/terminalframebuffer.cpp +++ b/terminalframebuffer.cpp @@ -407,11 +407,11 @@ void DrawState::resize( int s_width, int s_height ) int DrawState::get_background_rendition( void ) { int color = -1; - for ( std::vector::iterator i = renditions.begin(); + for ( std::list::iterator i = renditions.begin(); i != renditions.end(); i++ ) { int r = *i; - if ( (40 <= r) && (r <= 47) ) { + if ( (40 <= r) && (r <= 49) ) { color = r; } } @@ -436,3 +436,30 @@ void Framebuffer::back_color_erase( void ) } } } + +static bool fg_colorval( const int &x ) { return (30 <= x) && (x <= 39); } +static bool bg_colorval( const int &x ) { return (40 <= x) && (x <= 49); } + +void DrawState::add_rendition( int x ) +{ + /* Filter out older renditions that we know + will now be reset */ + + renditions.remove( x ); + + switch ( x ) { + case 1: case 22: renditions.remove( 1 ); renditions.remove( 22 ); break; /* bold */ + case 4: case 24: renditions.remove( 4 ); renditions.remove( 24 ); break; /* underlined */ + case 5: case 25: renditions.remove( 5 ); renditions.remove( 25 ); break; /* blink */ + case 7: case 27: renditions.remove( 7 ); renditions.remove( 27 ); break; /* inverse */ + case 8: case 28: renditions.remove( 8 ); renditions.remove( 28 ); break; /* invisible */ + } + + if ( (30 <= x) && (x <= 39) ) { /* foreground color */ + renditions.remove_if( fg_colorval ); + } else if ( (40 <= x) && (x <= 49) ) { /* background color */ + renditions.remove_if( bg_colorval ); + } + + renditions.push_back( x ); +} diff --git a/terminalframebuffer.hpp b/terminalframebuffer.hpp index 1e86275..4defa5f 100644 --- a/terminalframebuffer.hpp +++ b/terminalframebuffer.hpp @@ -4,6 +4,7 @@ #include #include #include +#include /* Terminal framebuffer */ @@ -13,7 +14,7 @@ namespace Terminal { std::vector contents; char fallback; /* first character is combining character */ int width; - std::vector renditions; /* e.g., bold, blinking, etc. */ + std::list renditions; /* e.g., bold, blinking, etc. */ bool need_back_color_erase; Cell(); @@ -36,7 +37,7 @@ namespace Terminal { class SavedCursor { public: int cursor_col, cursor_row; - std::vector renditions; + std::list renditions; /* character set shift state */ bool auto_wrap_mode; bool origin_mode; @@ -59,7 +60,7 @@ namespace Terminal { int scrolling_region_top_row, scrolling_region_bottom_row; - std::vector renditions; + std::list renditions; SavedCursor save; @@ -100,8 +101,8 @@ namespace Terminal { int limit_bottom( void ); void clear_renditions( void ) { renditions.clear(); } - void add_rendition( int x ) { renditions.push_back( x ); } - const std::vector get_renditions( void ) { return renditions; } + void add_rendition( int x ); + const std::list get_renditions( void ) { return renditions; } int get_background_rendition( void ); void save_cursor( void );