From d7ea3abb65eb87bdfb2b6bbb1dbf3d4f932b9a0b Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sat, 22 Jan 2011 15:01:30 -0500 Subject: [PATCH] Implement ED (clear screen) --- terminal.cpp | 40 ++++++++++++++++++++++++---------------- terminal.hpp | 3 +++ terminalcsi.cpp | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/terminal.cpp b/terminal.cpp index d477449..7bf7bf8 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -138,27 +138,16 @@ void Emulator::print( Parser::Print *act ) autoscroll(); - this_cell = &rows[ cursor_row ].cells[ cursor_col ]; - this_cell->contents.clear(); + this_cell = &rows[ cursor_row ].cells[ cursor_col ]; + this_cell->reset(); this_cell->contents.push_back( act->ch ); - for ( std::vector::iterator i - = this_cell->overlapped_cells.begin(); - i != this_cell->overlapped_cells.end(); - i++ ) { - **i = Cell(); - } - this_cell->overlapped_cells.clear(); newgrapheme(); - if ( cursor_col < width - 1 ) { + if ( (cursor_col < width - 1) && (chwidth == 2) ) { Cell *next_cell = &rows[ cursor_row ].cells[ cursor_col + 1 ]; - if ( chwidth == 2 ) { - this_cell->overlapped_cells.push_back( next_cell ); - next_cell->overlapping_cell = this_cell; - } else { - next_cell->overlapping_cell = NULL; - } + this_cell->overlapped_cells.push_back( next_cell ); + next_cell->overlapping_cell = this_cell; } cursor_col += chwidth; @@ -232,6 +221,8 @@ void Emulator::CSI_dispatch( Parser::CSI_Dispatch *act ) if ( dispatch_chars == "K" ) { CSI_EL(); + } else if ( dispatch_chars == "J" ) { + CSI_ED(); } else if ( (dispatch_chars == "A") || (dispatch_chars == "B") || (dispatch_chars == "C") @@ -288,3 +279,20 @@ int Emulator::getparam( size_t N, int defaultval ) return ret; } + +void Cell::reset( void ) +{ + if ( overlapping_cell ) { + assert( overlapped_cells.size() == 0 ); + contents.clear(); + } else { + contents.clear(); + for ( std::vector::iterator i = overlapped_cells.begin(); + i != overlapped_cells.end(); + i++ ) { + (*i)->overlapping_cell = NULL; + (*i)->reset(); + } + overlapped_cells.clear(); + } +} diff --git a/terminal.hpp b/terminal.hpp index 4cacd7c..663f5ff 100644 --- a/terminal.hpp +++ b/terminal.hpp @@ -19,6 +19,8 @@ namespace Terminal { Cell( const Cell & ); Cell & operator=( const Cell & ); + + void reset( void ); }; class Row { @@ -66,6 +68,7 @@ namespace Terminal { /* CSI methods */ void CSI_EL( void ); + void CSI_ED( void ); void CSI_cursormove( void ); public: diff --git a/terminalcsi.cpp b/terminalcsi.cpp index 23cfe20..de0633d 100644 --- a/terminalcsi.cpp +++ b/terminalcsi.cpp @@ -8,13 +8,45 @@ void Emulator::CSI_EL( void ) { if ( params == "1" ) { /* start of screen to active position, inclusive */ for ( int x = 0; x <= cursor_col; x++ ) { - rows[ cursor_row ].cells[ x ].contents.clear(); + if ( x < width ) { + rows[ cursor_row ].cells[ x ].reset(); + } } } else if ( params == "2" ) { /* all of line */ rows[ cursor_row ] = Row( width ); } else { /* active position to end of line, inclusive */ for ( int x = cursor_col; x < width; x++ ) { - rows[ cursor_row ].cells[ x ].contents.clear(); + rows[ cursor_row ].cells[ x ].reset(); + } + } +} + +void Emulator::CSI_ED( void ) { + if ( params == "1" ) { /* start of screen to active position, inclusive */ + for ( int y = 0; y < cursor_row; y++ ) { + for ( int x = 0; x < width; x++ ) { + rows[ y ].cells[ x ].reset(); + } + } + for ( int x = 0; x <= cursor_col; x++ ) { + if ( x < width ) { + rows[ cursor_row ].cells[ x ].reset(); + } + } + } else if ( params == "2" ) { /* entire screen */ + for ( int y = 0; y < height; y++ ) { + for ( int x = 0; x < width; x++ ) { + rows[ y ].cells[ x ].reset(); + } + } + } else { /* active position to end of screen, inclusive */ + for ( int x = cursor_col; x < width; x++ ) { + rows[ cursor_row ].cells[ x ].reset(); + } + for ( int y = cursor_row + 1; y < height; y++ ) { + for ( int x = 0; x < width; x++ ) { + rows[ y ].cells[ x ].reset(); + } } } }