Support some executes (LF, CR, BS+rubout)
This commit is contained in:
@@ -188,7 +188,11 @@ int vt_parser( int fd, Parser::UTF8Parser *parser )
|
|||||||
assert( act );
|
assert( act );
|
||||||
|
|
||||||
if ( act->char_present ) {
|
if ( act->char_present ) {
|
||||||
|
if ( isprint( act->ch ) ) {
|
||||||
printf( "%s(0x%02x=%lc) ", act->name().c_str(), act->ch, 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 {
|
} else {
|
||||||
printf( "[%s] ", act->name().c_str() );
|
printf( "[%s] ", act->name().c_str() );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,3 +7,8 @@ void Print::act_on_terminal( Terminal::Emulator *emu )
|
|||||||
{
|
{
|
||||||
emu->print( this );
|
emu->print( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Execute::act_on_terminal( Terminal::Emulator *emu )
|
||||||
|
{
|
||||||
|
emu->execute( this );
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace Parser {
|
|||||||
};
|
};
|
||||||
class Execute : public Action {
|
class Execute : public Action {
|
||||||
public: std::string name( void ) { return std::string( "Execute" ); }
|
public: std::string name( void ) { return std::string( "Execute" ); }
|
||||||
|
void act_on_terminal( Terminal::Emulator *emu );
|
||||||
};
|
};
|
||||||
class Clear : public Action {
|
class Clear : public Action {
|
||||||
public: std::string name( void ) { return std::string( "Clear" ); }
|
public: std::string name( void ) { return std::string( "Clear" ); }
|
||||||
|
|||||||
+37
-3
@@ -68,6 +68,7 @@ void Emulator::scroll( int N )
|
|||||||
rows.pop_front();
|
rows.pop_front();
|
||||||
rows.push_back( Row( width ) );
|
rows.push_back( Row( width ) );
|
||||||
cursor_row--;
|
cursor_row--;
|
||||||
|
combining_char_row--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,6 +79,36 @@ void Emulator::newgrapheme( void )
|
|||||||
combining_char_row = cursor_row;
|
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 )
|
void Emulator::print( Parser::Print *act )
|
||||||
{
|
{
|
||||||
assert( act->char_present );
|
assert( act->char_present );
|
||||||
@@ -99,14 +130,15 @@ void Emulator::print( Parser::Print *act )
|
|||||||
cursor_row++;
|
cursor_row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cursor_row >= height ) { /* scroll */
|
autoscroll();
|
||||||
scroll( cursor_row - height + 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
rows[ cursor_row ].cells[ cursor_col ].contents.clear();
|
rows[ cursor_row ].cells[ cursor_col ].contents.clear();
|
||||||
rows[ cursor_row ].cells[ cursor_col ].contents.push_back( act->ch );
|
rows[ cursor_row ].cells[ cursor_col ].contents.push_back( act->ch );
|
||||||
newgrapheme();
|
newgrapheme();
|
||||||
cursor_col++;
|
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 );
|
fflush( NULL );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Terminal {
|
|||||||
|
|
||||||
class Emulator {
|
class Emulator {
|
||||||
friend void Parser::Print::act_on_terminal( Emulator * );
|
friend void Parser::Print::act_on_terminal( Emulator * );
|
||||||
|
friend void Parser::Execute::act_on_terminal( Emulator * );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Parser::UTF8Parser parser;
|
Parser::UTF8Parser parser;
|
||||||
@@ -41,8 +42,10 @@ namespace Terminal {
|
|||||||
std::deque<Row> rows;
|
std::deque<Row> rows;
|
||||||
|
|
||||||
void print( Parser::Print *act );
|
void print( Parser::Print *act );
|
||||||
|
void execute( Parser::Execute *act );
|
||||||
|
|
||||||
void scroll( int N );
|
void scroll( int N );
|
||||||
|
void autoscroll( void );
|
||||||
|
|
||||||
void newgrapheme( void );
|
void newgrapheme( void );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user