Optional verifier for round-trippability, and fix wrapping and tab bugs.

This commit is contained in:
Keith Winstein
2012-04-16 07:46:18 -04:00
parent 18dc967c09
commit feb352c809
7 changed files with 93 additions and 19 deletions
+9
View File
@@ -143,6 +143,15 @@ void TransportSender<MyState>::tick( void )
string diff = current_state.diff_from( assumed_receiver_state->state );
/* verify diff has round-trip identity (modulo Unicode fallback rendering) */
/*
MyState newstate( assumed_receiver_state->state );
newstate.apply_string( diff );
if ( current_state.compare( newstate ) ) {
fprintf( stderr, "Diff: %s\n", diff.c_str() );
}
*/
if ( diff.empty() && (now >= next_ack_time) ) {
send_empty_ack();
return;
+23
View File
@@ -153,3 +153,26 @@ int Complete::wait_time( uint64_t now ) const
return next_echo_ack_time - now;
}
}
bool Complete::compare( const Complete &other ) const
{
bool ret = false;
for ( int x = 0; x < terminal.get_fb().ds.get_width(); x++ ) {
for ( int y = 0; y < terminal.get_fb().ds.get_height(); y++ ) {
if ( terminal.get_fb().get_cell( y, x )->compare( *other.terminal.get_fb().get_cell( y, x ) ) ) {
fprintf( stderr, "Cell (%d, %d) differs.\n", y, x );
ret = true;
}
}
}
if ( (terminal.get_fb().ds.get_cursor_row() != other.terminal.get_fb().ds.get_cursor_row())
|| (terminal.get_fb().ds.get_cursor_col() != other.terminal.get_fb().ds.get_cursor_col()) ) {
fprintf( stderr, "Cursor mismatch: (%d, %d) vs. (%d, %d).\n",
terminal.get_fb().ds.get_cursor_row(), terminal.get_fb().ds.get_cursor_col(),
other.terminal.get_fb().ds.get_cursor_row(), other.terminal.get_fb().ds.get_cursor_col() );
ret = true;
}
return ret;
}
+2
View File
@@ -60,6 +60,8 @@ namespace Terminal {
std::string diff_from( const Complete &existing ) const;
void apply_string( std::string diff );
bool operator==( const Complete &x ) const;
bool compare( const Complete &other ) const;
};
}
+2
View File
@@ -77,6 +77,8 @@ namespace Network {
string diff_from( const UserStream &existing ) const;
void apply_string( string diff );
bool operator==( const UserStream &x ) const { return actions == x.actions; }
bool compare( const UserStream & ) const { return false; }
};
}
+10 -6
View File
@@ -193,21 +193,23 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
frame.x < f.ds.get_width(); /* let put_cell() handle advance */ ) {
last_x = frame.x;
put_cell( initialized, frame, f );
}
/* To hint that a word-select should group the end of one line
with the beginning of the next, we let the real cursor
actually wrap around in cases where it wrapped around for us. */
if ( (frame.cursor_x >= f.ds.get_width())
&& (frame.y < f.ds.get_height() - 1)
&& f.get_row( frame.y )->get_wrap()
&& (!initialized || !frame.last_frame.get_row( frame.y )->get_wrap()) ) {
if ( (frame.y < f.ds.get_height() - 1)
&& f.get_row( frame.y )->get_wrap() ) {
frame.x = last_x;
frame.force_next_put = true;
put_cell( initialized, frame, f );
/* next write will wrap */
frame.cursor_x = 0;
frame.cursor_y++;
frame.force_next_put = true;
}
}
/* Turn off wrap */
if ( (frame.y < f.ds.get_height() - 1)
@@ -301,8 +303,10 @@ void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer &
if ( frame.force_next_put ) {
frame.append( " " );
frame.append_silent_move( frame.y, frame.x );
frame.cursor_x++;
frame.x++;
frame.force_next_put = false;
return;
}
/* can we go to the end of the line? */
+38 -6
View File
@@ -366,7 +366,7 @@ void DrawState::resize( int s_width, int s_height )
snap_cursor_to_border();
tabs.resize( width );
tabs.clear();
/* saved cursor will be snapped to border on restore */
@@ -482,11 +482,6 @@ std::string Renditions::sgr( void ) const
/* Reduce 256 "standard" colors to the 8 ANSI colors. */
/* We could do something fancy like find the nearest system color in
the deltaE(2000) sense, but for "business graphics," the colorimetric
intent is probably less important than just having separate colors
be separate as much as possible. */
/* Terminal emulators generally agree on the (R',G',B') values of the
"standard" 256-color pallette beyond #15, but for the first 16
colors there is disagreement. Most terminal emulators are roughly
@@ -573,3 +568,40 @@ wchar_t Cell::debug_contents( void ) const
return contents.front();
}
}
bool Cell::compare( const Cell &other ) const
{
bool ret = false;
if ( !contents_match( other ) ) {
ret = true;
fprintf( stderr, "Contents: %lc vs. %lc\n",
debug_contents(), other.debug_contents() );
}
if ( fallback != other.fallback ) {
ret = true;
fprintf( stderr, "fallback: %d vs. %d\n",
fallback, other.fallback );
}
if ( width != other.width ) {
ret = true;
fprintf( stderr, "width: %d vs. %d\n",
width, other.width );
}
if ( !(renditions == other.renditions) ) {
ret = true;
fprintf( stderr, "renditions: %s vs. %s\n",
renditions.sgr().c_str(), other.renditions.sgr().c_str() );
}
if ( wrap != other.wrap ) {
ret = true;
fprintf( stderr, "wrap: %d vs. %d\n",
wrap, other.wrap );
}
return ret;
}
+2
View File
@@ -102,6 +102,8 @@ namespace Terminal {
return ( is_blank() && other.is_blank() )
|| ( contents == other.contents );
}
bool compare( const Cell &other ) const;
};
class Row {