Fix prediction unicode bug. Make all Cell members private.

Fixes #702.
This commit is contained in:
John Hood
2015-12-21 19:13:43 -05:00
parent 90a529b18a
commit 2ac3bbeb9b
11 changed files with 226 additions and 49 deletions
+5 -6
View File
@@ -107,7 +107,7 @@ void Emulator::print( const Parser::Print *act )
fb.reset_cell( this_cell );
this_cell->append( ch );
this_cell->width = chwidth;
this_cell->set_width( chwidth );
fb.apply_renditions_to_cell( this_cell );
if ( chwidth == 2 ) { /* erase overlapped cell */
@@ -128,18 +128,17 @@ void Emulator::print( const Parser::Print *act )
break;
}
if ( combining_cell->contents.size() == 0 ) {
if ( combining_cell->empty() ) {
/* cell starts with combining character */
/* ... but isn't necessarily the target for a new
base character [e.g. start of line], if the
combining character has been cleared with
a sequence like ED ("J") or EL ("K") */
assert( combining_cell->width == 1 );
combining_cell->fallback = true;
assert( combining_cell->get_width() == 1 );
combining_cell->set_fallback( true );
fb.ds.move_col( 1, true, true );
}
if ( combining_cell->contents.size() < 32 ) {
/* seems like a reasonable limit on combining characters */
if ( !combining_cell->full() ) {
combining_cell->append( ch );
}
act->handled = true;
+12 -12
View File
@@ -337,10 +337,10 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
/* If we're forced to write the first column because of wrap, go ahead and do so. */
if ( wrap ) {
const Cell &cell = cells.at( 0 );
frame.update_rendition( cell.renditions );
frame.update_rendition( cell.get_renditions() );
frame.append_cell( cell );
frame_x += cell.width;
frame.cursor_x += cell.width;
frame_x += cell.get_width();
frame.cursor_x += cell.get_width();
}
/* If rows are the same object, we don't need to do anything at all. */
@@ -361,16 +361,16 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
if ( initialized
&& !clear_count
&& ( cell == old_cells.at( frame_x ) ) ) {
frame_x += cell.width;
frame_x += cell.get_width();
continue;
}
/* Slurp up all the empty cells */
if ( cell.contents.empty() ) {
if ( cell.empty() ) {
if ( !clear_count ) {
blank_renditions = cell.renditions;
blank_renditions = cell.get_renditions();
}
if ( cell.renditions == blank_renditions ) {
if ( cell.get_renditions() == blank_renditions ) {
/* Remember run of blank cells */
clear_count++;
frame_x++;
@@ -394,8 +394,8 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
clear_count = 0;
// If the current character is *another* empty cell in a different rendition,
// we restart counting and continue here
if ( cell.contents.empty() ) {
blank_renditions = cell.renditions;
if ( cell.empty() ) {
blank_renditions = cell.get_renditions();
clear_count = 1;
frame_x++;
continue;
@@ -406,10 +406,10 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
/* Now draw a character cell. */
/* Move to the right position. */
frame.append_silent_move( frame_y, frame_x );
frame.update_rendition( cell.renditions );
frame.update_rendition( cell.get_renditions() );
frame.append_cell( cell );
frame_x += cell.width;
frame.cursor_x += cell.width;
frame_x += cell.get_width();
frame.cursor_x += cell.get_width();
if ( frame_x >= f.ds.get_width() ) {
wrote_last_cell = true;
}
-1
View File
@@ -53,7 +53,6 @@ namespace Terminal {
void append( const size_t s, const char c ) { str.append( s, c ); }
void append( const wchar_t wc ) { Cell::append_to_str( str, wc ); }
void append( const char * s ) { str.append( s ); }
void append( const Cell::content_type &contents ) { str.append( contents.begin(), contents.end() ); }
void append_string( const std::string &append ) { str.append(append); }
void append_cell(const Cell & cell) { cell.print_grapheme( str ); }
+1 -1
View File
@@ -270,7 +270,7 @@ void Framebuffer::apply_renditions_to_cell( Cell *cell )
if (!cell) {
cell = get_mutable_cell();
}
cell->renditions = ds.get_renditions();
cell->set_renditions( ds.get_renditions() );
}
SavedCursor::SavedCursor()
+19 -2
View File
@@ -85,13 +85,14 @@ namespace Terminal {
};
class Cell {
public:
private:
typedef std::string content_type; /* can be std::string, std::vector<uint8_t>, or __gnu_cxx::__vstring */
content_type contents;
Renditions renditions;
uint8_t width;
bool fallback; /* first character is combining character */
public:
Cell( color_type background_color );
Cell(); /* default constructor required by C++11 STL */
@@ -107,8 +108,14 @@ namespace Terminal {
bool operator!=( const Cell &x ) const { return !operator==( x ); }
/* Accessors for contents field */
std::string debug_contents( void ) const;
bool empty( void ) const { return contents.empty(); }
/* 32 seems like a reasonable limit on combining characters */
bool full( void ) const { return contents.size() >= 32; }
void clear( void ) { contents.clear(); }
bool is_blank( void ) const
{
// XXX fix.
@@ -176,6 +183,15 @@ namespace Terminal {
}
output.append( contents );
}
/* Other accessors */
const Renditions& get_renditions( void ) const { return renditions; }
Renditions& get_renditions( void ) { return renditions; }
void set_renditions( const Renditions& r ) { renditions = r; }
unsigned int get_width( void ) const { return width; }
void set_width( unsigned int w ) { width = w; }
bool get_fallback( void ) const { return fallback; }
void set_fallback( bool f ) { fallback = f; }
};
class Row {
@@ -299,7 +315,8 @@ namespace Terminal {
void set_foreground_color( int x ) { renditions.set_foreground_color( x ); }
void set_background_color( int x ) { renditions.set_background_color( x ); }
void add_rendition( color_type x ) { renditions.set_rendition( x ); }
Renditions get_renditions( void ) const { return renditions; }
const Renditions& get_renditions( void ) const { return renditions; }
Renditions& get_renditions( void ) { return renditions; }
int get_background_rendition( void ) const { return renditions.background_color; }
void save_cursor( void );
+1 -1
View File
@@ -148,7 +148,7 @@ static void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unuse
for ( int y = 0; y < fb->ds.get_height(); y++ ) {
for ( int x = 0; x < fb->ds.get_width(); x++ ) {
fb->reset_cell( fb->get_mutable_cell( y, x ) );
fb->get_mutable_cell( y, x )->contents.push_back( L'E' );
fb->get_mutable_cell( y, x )->append( 'E' );
}
}
}