Remove some debugging routines and add comments

This commit is contained in:
Keith Winstein
2011-02-06 14:43:47 -05:00
parent bab3f90e2b
commit 1ee54cd70a
4 changed files with 28 additions and 100 deletions
+26 -29
View File
@@ -27,28 +27,14 @@
const size_t buf_size = 16384; const size_t buf_size = 16384;
void emulate_terminal( int fd, int debug_fd ); void emulate_terminal( int fd );
int copy( int src, int dest ); int copy( int src, int dest );
int termemu( int host_fd, int src_fd, bool user, int debug_fd, int termemu( int host_fd, int src_fd, bool user,
Parser::UTF8Parser *parser, Parser::UTF8Parser *parser,
Terminal::Emulator *terminal ); Terminal::Emulator *terminal );
int main( int argc, char *argv[] ) int main( void )
{ {
int debug_fd;
if ( argc == 1 ) {
debug_fd = -1;
} else if ( argc == 2 ) {
debug_fd = open( argv[ 1 ], O_WRONLY );
if ( debug_fd < 0 ) {
perror( "open" );
exit( 1 );
}
} else {
fprintf( stderr, "Usage: %s [debugfd]\n", argv[ 0 ] );
exit( 1 );
}
int master; int master;
struct termios saved_termios, raw_termios, child_termios; struct termios saved_termios, raw_termios, child_termios;
@@ -122,7 +108,7 @@ int main( int argc, char *argv[] )
exit( 1 ); exit( 1 );
} }
emulate_terminal( master, debug_fd ); emulate_terminal( master );
if ( tcsetattr( STDIN_FILENO, TCSANOW, &saved_termios ) < 0 ) { if ( tcsetattr( STDIN_FILENO, TCSANOW, &saved_termios ) < 0 ) {
perror( "tcsetattr" ); perror( "tcsetattr" );
@@ -135,6 +121,7 @@ int main( int argc, char *argv[] )
return 0; return 0;
} }
/* Print a frame if the last frame was more than 1/50 seconds ago */
bool tick( Terminal::Emulator *e ) bool tick( Terminal::Emulator *e )
{ {
static bool initialized = false; static bool initialized = false;
@@ -162,7 +149,24 @@ bool tick( Terminal::Emulator *e )
return false; return false;
} }
void emulate_terminal( int fd, int debug_fd ) /* This is the main loop.
1. New bytes from the user get applied to the terminal emulator
as "UserByte" actions.
2. New bytes from the host get sent to the Parser, and then
those actions are applied to the terminal.
3. Resize events (from a SIGWINCH signal) get turned into
"Resize" actions and applied to the terminal.
At every event from poll(), we run the tick() function to
possibly print a new frame (if we haven't printed one in the
last 1/50 second). The new frames are "differential" -- they
assume the previous frame was sent to the real terminal.
*/
void emulate_terminal( int fd )
{ {
/* establish WINCH fd and start listening for signal */ /* establish WINCH fd and start listening for signal */
sigset_t signal_mask; sigset_t signal_mask;
@@ -218,11 +222,11 @@ void emulate_terminal( int fd, int debug_fd )
} }
if ( pollfds[ 0 ].revents & POLLIN ) { if ( pollfds[ 0 ].revents & POLLIN ) {
if ( termemu( fd, STDIN_FILENO, true, debug_fd, &parser, &terminal ) < 0 ) { if ( termemu( fd, STDIN_FILENO, true, &parser, &terminal ) < 0 ) {
break; break;
} }
} else if ( pollfds[ 1 ].revents & POLLIN ) { } else if ( pollfds[ 1 ].revents & POLLIN ) {
if ( termemu( fd, fd, false, debug_fd, &parser, &terminal ) < 0 ) { if ( termemu( fd, fd, false, &parser, &terminal ) < 0 ) {
break; break;
} }
} else if ( pollfds[ 2 ].revents & POLLIN ) { } else if ( pollfds[ 2 ].revents & POLLIN ) {
@@ -264,7 +268,7 @@ void emulate_terminal( int fd, int debug_fd )
swrite( STDOUT_FILENO, terminal.close().c_str() ); swrite( STDOUT_FILENO, terminal.close().c_str() );
} }
int termemu( int host_fd, int src_fd, bool user, int debug_fd, int termemu( int host_fd, int src_fd, bool user,
Parser::UTF8Parser *parser, Parser::UTF8Parser *parser,
Terminal::Emulator *terminal ) Terminal::Emulator *terminal )
{ {
@@ -296,13 +300,6 @@ int termemu( int host_fd, int src_fd, bool user, int debug_fd,
/* apply action to terminal */ /* apply action to terminal */
act->act_on_terminal( terminal ); act->act_on_terminal( terminal );
/* print out action for debugging */
if ( (debug_fd > 0) && (!act->handled) ) {
char actsum[ 64 ];
snprintf( actsum, 64, "%s ", act->str().c_str() );
swrite( debug_fd, actsum );
}
delete *i; delete *i;
} }
} }
-69
View File
@@ -121,75 +121,6 @@ void Emulator::Esc_dispatch( Parser::Esc_Dispatch *act )
} }
} }
void Emulator::debug_printout( int fd )
{
fb.back_color_erase();
std::string screen;
/* set window title */
screen.append( "\033]0;[rtm] " );
std::vector<wchar_t> window_title = fb.get_window_title();
for ( std::vector<wchar_t>::iterator i = window_title.begin();
i != window_title.end();
i++ ) {
char utf8[ 8 ];
snprintf( utf8, 8, "%lc", *i );
screen.append( utf8 );
}
screen.append( "\033\\" );
/* set reverse video */
char rev[ 8 ];
snprintf( rev, 8, "\033[?5%c", (fb.ds.reverse_video ? 'h' : 'l') );
screen.append( rev );
for ( int y = 0; y < fb.ds.get_height(); y++ ) {
for ( int x = 0; x < fb.ds.get_width(); /* let charwidth handle advance */ ) {
char curmove[ 32 ];
snprintf( curmove, 32, "\033[%d;%dH", y + 1, x + 1 );
screen.append( curmove );
Cell *cell = fb.get_cell( y, x );
/* print renditions */
screen.append( cell->renditions.sgr() );
/* clear cell */
screen.append( "\033[X" );
/* print cell contents */
/* cells that begin with combining character get combiner attached to no-break space */
if ( cell->fallback ) {
char utf8[ 8 ];
snprintf( utf8, 8, "%lc", 0xA0 );
screen.append( utf8 );
}
for ( std::vector<wchar_t>::iterator i = cell->contents.begin();
i != cell->contents.end();
i++ ) {
char utf8[ 8 ];
snprintf( utf8, 8, "%lc", *i );
screen.append( utf8 );
}
x += cell->width;
}
}
char curmove[ 32 ];
if ( fb.ds.cursor_visible ) {
snprintf( curmove, 32, "\033[?25h\033[%d;%dH", fb.ds.get_cursor_row() + 1,
fb.ds.get_cursor_col() + 1 );
} else {
snprintf( curmove, 32, "\033[?25l" );
}
screen.append( curmove );
swrite( fd, screen.c_str() );
}
std::string Emulator::open( void ) std::string Emulator::open( void )
{ {
char appmode[ 6 ] = { 0x1b, '[', '?', '1', 'h', 0 }; char appmode[ 6 ] = { 0x1b, '[', '?', '1', 'h', 0 };
-2
View File
@@ -62,8 +62,6 @@ namespace Terminal {
std::string read_octets_to_host( void ); std::string read_octets_to_host( void );
void debug_printout( int fd );
std::string open( void ); /* put user cursor keys in application mode */ std::string open( void ); /* put user cursor keys in application mode */
std::string close( void ); /* restore user cursor keys */ std::string close( void ); /* restore user cursor keys */
+2
View File
@@ -2,6 +2,8 @@
using namespace Terminal; using namespace Terminal;
/* Print a new "frame" to the terminal, using ANSI/ECMA-48 escape codes. */
std::string Display::new_frame( Framebuffer &f ) std::string Display::new_frame( Framebuffer &f )
{ {
f.back_color_erase(); f.back_color_erase();