Fix crash involving one-column-wide terminals and resizing with wide chars

This commit is contained in:
Keith Winstein
2011-02-12 02:10:32 -05:00
parent 7d1013681f
commit 1565cb169e
2 changed files with 19 additions and 3 deletions
+3 -2
View File
@@ -73,7 +73,9 @@ std::string Display::new_frame( Framebuffer &f )
&& (!f.get_row( frame.y )->wrap) && (!f.get_row( frame.y )->wrap)
&& (!initialized || last_frame.get_row( frame.y )->wrap) ) { && (!initialized || last_frame.get_row( frame.y )->wrap) ) {
frame.x = last_x; frame.x = last_x;
if ( initialized ) {
last_frame.reset_cell( last_frame.get_cell( frame.y, frame.x ) ); last_frame.reset_cell( last_frame.get_cell( frame.y, frame.x ) );
}
snprintf( tmp, 64, "\033[%d;%dH\033[K", frame.y + 1, frame.x + 1 ); snprintf( tmp, 64, "\033[%d;%dH\033[K", frame.y + 1, frame.x + 1 );
frame.append( tmp ); frame.append( tmp );
@@ -115,10 +117,9 @@ void Display::put_cell( FrameState &frame, Framebuffer &f )
char tmp[ 64 ]; char tmp[ 64 ];
Cell *cell = f.get_cell( frame.y, frame.x ); Cell *cell = f.get_cell( frame.y, frame.x );
Cell *last_cell = last_frame.get_cell( frame.y, frame.x );
if ( initialized if ( initialized
&& ( *cell == *last_cell ) ) { && ( *cell == *(last_frame.get_cell( frame.y, frame.x )) ) ) {
frame.x += cell->width; frame.x += cell->width;
return; return;
} }
+15
View File
@@ -5,6 +5,7 @@
#include <deque> #include <deque>
#include <string> #include <string>
#include <list> #include <list>
#include <assert.h>
/* Terminal framebuffer */ /* Terminal framebuffer */
@@ -171,6 +172,13 @@ namespace Terminal {
inline Cell *get_cell( void ) inline Cell *get_cell( void )
{ {
#ifdef DEBUG
assert( ds.get_cursor_row() >= 0 );
assert( ds.get_cursor_col() >= 0 );
assert( ds.get_cursor_row() < ds.get_height() );
assert( ds.get_cursor_col() < ds.get_width() );
#endif
return &rows[ ds.get_cursor_row() ].cells[ ds.get_cursor_col() ]; return &rows[ ds.get_cursor_row() ].cells[ ds.get_cursor_col() ];
} }
@@ -179,6 +187,13 @@ namespace Terminal {
if ( row == -1 ) row = ds.get_cursor_row(); if ( row == -1 ) row = ds.get_cursor_row();
if ( col == -1 ) col = ds.get_cursor_col(); if ( col == -1 ) col = ds.get_cursor_col();
#ifdef DEBUG
assert( row >= 0 );
assert( col >= 0 );
assert( row < ds.get_height() );
assert( col < ds.get_width() );
#endif
return &rows[ row ].cells[ col ]; return &rows[ row ].cells[ col ];
} }