diff --git a/termemu.cpp b/termemu.cpp index 5f65d0b..4545507 100644 --- a/termemu.cpp +++ b/termemu.cpp @@ -172,12 +172,29 @@ int termemu( int fd, Terminal::Emulator *terminal ) return -1; } + std::string terminal_to_host; + /* feed to terminal */ for ( int i = 0; i < bytes_read; i++ ) { - terminal->input( buf[ i ] ); + terminal_to_host.append( terminal->input( buf[ i ] ) ); } 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; } diff --git a/terminal.cpp b/terminal.cpp index 7bf7bf8..62723d2 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -38,7 +38,8 @@ Emulator::Emulator( size_t s_width, size_t s_height ) cursor_col( 0 ), cursor_row( 0 ), combining_char_col( 0 ), combining_char_row( 0 ), 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 vec = parser.input( c ); for ( std::vector::iterator i = vec.begin(); @@ -61,6 +64,8 @@ void Emulator::input( char c ) delete act; } + + return terminal_to_host; } void Emulator::scroll( int N ) @@ -229,6 +234,8 @@ void Emulator::CSI_dispatch( Parser::CSI_Dispatch *act ) || (dispatch_chars == "D") || (dispatch_chars == "H") ) { CSI_cursormove(); + } else if ( dispatch_chars == "c" ) { + CSI_DA(); } } diff --git a/terminal.hpp b/terminal.hpp index 663f5ff..c24a455 100644 --- a/terminal.hpp +++ b/terminal.hpp @@ -48,6 +48,7 @@ namespace Terminal { std::string params; std::string dispatch_chars; + std::string terminal_to_host; std::string errors; /* action methods */ @@ -70,12 +71,13 @@ namespace Terminal { void CSI_EL( void ); void CSI_ED( void ); void CSI_cursormove( void ); + void CSI_DA( void ); public: Emulator( size_t s_width, size_t s_height ); ~Emulator(); - void input( char c ); + std::string input( char c ); void resize( size_t s_width, size_t s_height ); diff --git a/terminalcsi.cpp b/terminalcsi.cpp index de0633d..a9c0fce 100644 --- a/terminalcsi.cpp +++ b/terminalcsi.cpp @@ -83,3 +83,8 @@ void Emulator::CSI_cursormove( void ) newgrapheme(); } + +void Emulator::CSI_DA( void ) +{ + terminal_to_host.append( "\033[?1;0c" ); +}