Support some executes (LF, CR, BS+rubout)

This commit is contained in:
Keith Winstein
2011-01-21 17:22:52 -05:00
parent 30ab4371db
commit c1d6b3f30e
5 changed files with 51 additions and 4 deletions
+5 -1
View File
@@ -188,7 +188,11 @@ int vt_parser( int fd, Parser::UTF8Parser *parser )
assert( act );
if ( act->char_present ) {
printf( "%s(0x%02x=%lc) ", act->name().c_str(), act->ch, act->ch );
if ( isprint( act->ch ) ) {
printf( "%s(0x%02x=%lc) ", act->name().c_str(), act->ch, act->ch );
} else {
printf( "%s(0x%02x) ", act->name().c_str(), act->ch );
}
} else {
printf( "[%s] ", act->name().c_str() );
}
+5
View File
@@ -7,3 +7,8 @@ void Print::act_on_terminal( Terminal::Emulator *emu )
{
emu->print( this );
}
void Execute::act_on_terminal( Terminal::Emulator *emu )
{
emu->execute( this );
}
+1
View File
@@ -32,6 +32,7 @@ namespace Parser {
};
class Execute : public Action {
public: std::string name( void ) { return std::string( "Execute" ); }
void act_on_terminal( Terminal::Emulator *emu );
};
class Clear : public Action {
public: std::string name( void ) { return std::string( "Clear" ); }
+37 -3
View File
@@ -68,6 +68,7 @@ void Emulator::scroll( int N )
rows.pop_front();
rows.push_back( Row( width ) );
cursor_row--;
combining_char_row--;
}
}
}
@@ -78,6 +79,36 @@ void Emulator::newgrapheme( void )
combining_char_row = cursor_row;
}
void Emulator::autoscroll( void )
{
if ( cursor_row >= height ) { /* scroll */
scroll( cursor_row - height + 1 );
}
}
void Emulator::execute( Parser::Execute *act )
{
assert( act->char_present );
switch ( act->ch ) {
case 0x0a: /* LF */
cursor_row++;
autoscroll();
break;
case 0x0d: /* CR */
cursor_col = 0;
break;
case 0x08: /* BS */
if ( cursor_col > 0 ) {
cursor_col--;
rows[ cursor_row ].cells[ cursor_col ].contents.clear();
}
break;
}
}
void Emulator::print( Parser::Print *act )
{
assert( act->char_present );
@@ -99,14 +130,15 @@ void Emulator::print( Parser::Print *act )
cursor_row++;
}
if ( cursor_row >= height ) { /* scroll */
scroll( cursor_row - height + 1 );
}
autoscroll();
rows[ cursor_row ].cells[ cursor_col ].contents.clear();
rows[ cursor_row ].cells[ cursor_col ].contents.push_back( act->ch );
newgrapheme();
cursor_col++;
break;
default:
break;
}
}
@@ -126,5 +158,7 @@ void Emulator::debug_printout( FILE *f )
}
}
fprintf( f, "\033[%d;%dH", cursor_row + 1, cursor_col + 1 );
fflush( NULL );
}
+3
View File
@@ -30,6 +30,7 @@ namespace Terminal {
class Emulator {
friend void Parser::Print::act_on_terminal( Emulator * );
friend void Parser::Execute::act_on_terminal( Emulator * );
private:
Parser::UTF8Parser parser;
@@ -41,8 +42,10 @@ namespace Terminal {
std::deque<Row> rows;
void print( Parser::Print *act );
void execute( Parser::Execute *act );
void scroll( int N );
void autoscroll( void );
void newgrapheme( void );