diff --git a/parse.cpp b/parse.cpp index bf2943d..261bb57 100644 --- a/parse.cpp +++ b/parse.cpp @@ -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() ); } diff --git a/parseraction.cpp b/parseraction.cpp index d284353..b2c9567 100644 --- a/parseraction.cpp +++ b/parseraction.cpp @@ -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 ); +} diff --git a/parseraction.hpp b/parseraction.hpp index 86e5268..16749d7 100644 --- a/parseraction.hpp +++ b/parseraction.hpp @@ -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" ); } diff --git a/terminal.cpp b/terminal.cpp index 83b495e..9035d04 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -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 ); } diff --git a/terminal.hpp b/terminal.hpp index 078ece9..44c399a 100644 --- a/terminal.hpp +++ b/terminal.hpp @@ -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 rows; void print( Parser::Print *act ); + void execute( Parser::Execute *act ); void scroll( int N ); + void autoscroll( void ); void newgrapheme( void );