Dispatch for controls as well

This commit is contained in:
Keith Winstein
2011-01-31 05:13:21 -05:00
parent cda7a87f66
commit a49378b23b
4 changed files with 51 additions and 25 deletions
+1 -16
View File
@@ -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 )
+25 -7
View File
@@ -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 {
+4 -2
View File
@@ -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;
+21
View File
@@ -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 );