Implement DA (device attributes), including writeback to host

This commit is contained in:
Keith Winstein
2011-01-22 15:25:52 -05:00
parent d7ea3abb65
commit 1c6819ae0d
4 changed files with 35 additions and 4 deletions
+18 -1
View File
@@ -172,12 +172,29 @@ int termemu( int fd, Terminal::Emulator *terminal )
return -1; return -1;
} }
std::string terminal_to_host;
/* feed to terminal */ /* feed to terminal */
for ( int i = 0; i < bytes_read; i++ ) { for ( int i = 0; i < bytes_read; i++ ) {
terminal->input( buf[ i ] ); terminal_to_host.append( terminal->input( buf[ i ] ) );
} }
terminal->debug_printout( stdout ); terminal->debug_printout( stdout );
/* write writeback */
ssize_t total_bytes_written = 0;
ssize_t bytes_to_write = terminal_to_host.length();
const char *str = terminal_to_host.c_str();
while ( total_bytes_written < bytes_to_write ) {
ssize_t bytes_written = write( fd, str + total_bytes_written,
bytes_to_write - total_bytes_written );
if ( bytes_written <= 0 ) {
perror( "write" );
return -1;
} else {
total_bytes_written += bytes_written;
}
}
return 0; return 0;
} }
+9 -2
View File
@@ -38,7 +38,8 @@ Emulator::Emulator( size_t s_width, size_t s_height )
cursor_col( 0 ), cursor_row( 0 ), cursor_col( 0 ), cursor_row( 0 ),
combining_char_col( 0 ), combining_char_row( 0 ), combining_char_col( 0 ), combining_char_row( 0 ),
rows( height, Row( width ) ), rows( height, Row( width ) ),
params(), dispatch_chars(), errors(), parsed_params() params(), dispatch_chars(), terminal_to_host(),
errors(), parsed_params()
{ {
} }
@@ -48,8 +49,10 @@ Emulator::~Emulator()
} }
void Emulator::input( char c ) std::string Emulator::input( char c )
{ {
terminal_to_host.clear();
std::vector<Parser::Action *> vec = parser.input( c ); std::vector<Parser::Action *> vec = parser.input( c );
for ( std::vector<Parser::Action *>::iterator i = vec.begin(); for ( std::vector<Parser::Action *>::iterator i = vec.begin();
@@ -61,6 +64,8 @@ void Emulator::input( char c )
delete act; delete act;
} }
return terminal_to_host;
} }
void Emulator::scroll( int N ) void Emulator::scroll( int N )
@@ -229,6 +234,8 @@ void Emulator::CSI_dispatch( Parser::CSI_Dispatch *act )
|| (dispatch_chars == "D") || (dispatch_chars == "D")
|| (dispatch_chars == "H") ) { || (dispatch_chars == "H") ) {
CSI_cursormove(); CSI_cursormove();
} else if ( dispatch_chars == "c" ) {
CSI_DA();
} }
} }
+3 -1
View File
@@ -48,6 +48,7 @@ namespace Terminal {
std::string params; std::string params;
std::string dispatch_chars; std::string dispatch_chars;
std::string terminal_to_host;
std::string errors; std::string errors;
/* action methods */ /* action methods */
@@ -70,12 +71,13 @@ namespace Terminal {
void CSI_EL( void ); void CSI_EL( void );
void CSI_ED( void ); void CSI_ED( void );
void CSI_cursormove( void ); void CSI_cursormove( void );
void CSI_DA( void );
public: public:
Emulator( size_t s_width, size_t s_height ); Emulator( size_t s_width, size_t s_height );
~Emulator(); ~Emulator();
void input( char c ); std::string input( char c );
void resize( size_t s_width, size_t s_height ); void resize( size_t s_width, size_t s_height );
+5
View File
@@ -83,3 +83,8 @@ void Emulator::CSI_cursormove( void )
newgrapheme(); newgrapheme();
} }
void Emulator::CSI_DA( void )
{
terminal_to_host.append( "\033[?1;0c" );
}