From a49378b23b55678f515bbabcfa10dd6f549fcc30 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Mon, 31 Jan 2011 05:13:21 -0500 Subject: [PATCH] Dispatch for controls as well --- terminal.cpp | 17 +---------------- terminaldispatcher.cpp | 32 +++++++++++++++++++++++++------- terminaldispatcher.hpp | 6 ++++-- terminalfunctions.cpp | 21 +++++++++++++++++++++ 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/terminal.cpp b/terminal.cpp index 9d0c46c..5ea2b93 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -43,22 +43,7 @@ void Emulator::execute( Parser::Execute *act ) { assert( act->char_present ); - switch ( act->ch ) { - case 0x0a: /* LF */ - fb.move_rows_autoscroll( 1 ); - act->handled = true; - break; - - case 0x0d: /* CR */ - fb.ds.move_col( 0 ); - act->handled = true; - break; - - case 0x08: /* BS */ - fb.ds.move_col( -1, true ); - act->handled = true; - break; - } + dispatch.dispatch( CONTROL, act, &fb ); } void Emulator::print( Parser::Print *act ) diff --git a/terminaldispatcher.cpp b/terminaldispatcher.cpp index 8110ac1..76f64e7 100644 --- a/terminaldispatcher.cpp +++ b/terminaldispatcher.cpp @@ -119,6 +119,9 @@ static void register_function( Function_Type type, case CSI: global_dispatch_registry.CSI.insert( dispatch_map_t::value_type( dispatch_chars, f ) ); break; + case CONTROL: + global_dispatch_registry.control.insert( dispatch_map_t::value_type( dispatch_chars, f ) ); + break; } } @@ -132,15 +135,30 @@ Function::Function( Function_Type type, std::string dispatch_chars, void Dispatcher::dispatch( Function_Type type, Parser::Action *act, Framebuffer *fb ) { /* add final char to dispatch key */ - assert( act->char_present ); - Parser::Collect act2; - act2.char_present = true; - act2.ch = act->ch; - collect( &act2 ); - dispatch_map_t *map = (type == ESCAPE) ? &global_dispatch_registry.escape : &global_dispatch_registry.CSI; + if ( type != CONTROL ) { + assert( act->char_present ); + Parser::Collect act2; + act2.char_present = true; + act2.ch = act->ch; + collect( &act2 ); + } - dispatch_map_t::const_iterator i = map->find( dispatch_chars ); + dispatch_map_t *map; + switch ( type ) { + case ESCAPE: map = &global_dispatch_registry.escape; break; + case CSI: map = &global_dispatch_registry.CSI; break; + case CONTROL: map = &global_dispatch_registry.control; break; + } + + std::string key = dispatch_chars; + if ( type == CONTROL ) { + assert( act->ch <= 255 ); + char ctrlstr[ 2 ] = { (char)act->ch, 0 }; + key = std::string( ctrlstr ); + } + + dispatch_map_t::const_iterator i = map->find( key ); if ( i == map->end() ) { return; } else { diff --git a/terminaldispatcher.hpp b/terminaldispatcher.hpp index 0b30e13..f72d2e6 100644 --- a/terminaldispatcher.hpp +++ b/terminaldispatcher.hpp @@ -12,13 +12,14 @@ namespace Parser { class Clear; class Esc_Dispatch; class CSI_Dispatch; + class Execute; } namespace Terminal { class Framebuffer; class Dispatcher; - enum Function_Type { ESCAPE, CSI }; + enum Function_Type { ESCAPE, CSI, CONTROL }; class Function { public: @@ -34,8 +35,9 @@ namespace Terminal { public: dispatch_map_t escape; dispatch_map_t CSI; + dispatch_map_t control; - DispatchRegistry() : escape(), CSI() {} + DispatchRegistry() : escape(), CSI(), control() {} }; static DispatchRegistry global_dispatch_registry; diff --git a/terminalfunctions.cpp b/terminalfunctions.cpp index 9731305..7f387fb 100644 --- a/terminalfunctions.cpp +++ b/terminalfunctions.cpp @@ -104,3 +104,24 @@ void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) } static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN ); + +void Ctrl_LF( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +{ + fb->move_rows_autoscroll( 1 ); +} + +static Function func_Ctrl_LF( CONTROL, "\x0a", Ctrl_LF ); + +void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +{ + fb->ds.move_col( 0 ); +} + +static Function func_Ctrl_CR( CONTROL, "\x0d", Ctrl_CR ); + +void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) +{ + fb->ds.move_col( -1, true ); +} + +static Function func_Ctrl_BS( CONTROL, "\x08", Ctrl_BS );