Dispatch for controls as well
This commit is contained in:
+1
-16
@@ -43,22 +43,7 @@ void Emulator::execute( Parser::Execute *act )
|
|||||||
{
|
{
|
||||||
assert( act->char_present );
|
assert( act->char_present );
|
||||||
|
|
||||||
switch ( act->ch ) {
|
dispatch.dispatch( CONTROL, act, &fb );
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::print( Parser::Print *act )
|
void Emulator::print( Parser::Print *act )
|
||||||
|
|||||||
+20
-2
@@ -119,6 +119,9 @@ static void register_function( Function_Type type,
|
|||||||
case CSI:
|
case CSI:
|
||||||
global_dispatch_registry.CSI.insert( dispatch_map_t::value_type( dispatch_chars, f ) );
|
global_dispatch_registry.CSI.insert( dispatch_map_t::value_type( dispatch_chars, f ) );
|
||||||
break;
|
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 )
|
void Dispatcher::dispatch( Function_Type type, Parser::Action *act, Framebuffer *fb )
|
||||||
{
|
{
|
||||||
/* add final char to dispatch key */
|
/* add final char to dispatch key */
|
||||||
|
|
||||||
|
if ( type != CONTROL ) {
|
||||||
assert( act->char_present );
|
assert( act->char_present );
|
||||||
Parser::Collect act2;
|
Parser::Collect act2;
|
||||||
act2.char_present = true;
|
act2.char_present = true;
|
||||||
act2.ch = act->ch;
|
act2.ch = act->ch;
|
||||||
collect( &act2 );
|
collect( &act2 );
|
||||||
|
}
|
||||||
|
|
||||||
dispatch_map_t *map = (type == ESCAPE) ? &global_dispatch_registry.escape : &global_dispatch_registry.CSI;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
dispatch_map_t::const_iterator i = map->find( dispatch_chars );
|
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() ) {
|
if ( i == map->end() ) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ namespace Parser {
|
|||||||
class Clear;
|
class Clear;
|
||||||
class Esc_Dispatch;
|
class Esc_Dispatch;
|
||||||
class CSI_Dispatch;
|
class CSI_Dispatch;
|
||||||
|
class Execute;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
class Framebuffer;
|
class Framebuffer;
|
||||||
class Dispatcher;
|
class Dispatcher;
|
||||||
|
|
||||||
enum Function_Type { ESCAPE, CSI };
|
enum Function_Type { ESCAPE, CSI, CONTROL };
|
||||||
|
|
||||||
class Function {
|
class Function {
|
||||||
public:
|
public:
|
||||||
@@ -34,8 +35,9 @@ namespace Terminal {
|
|||||||
public:
|
public:
|
||||||
dispatch_map_t escape;
|
dispatch_map_t escape;
|
||||||
dispatch_map_t CSI;
|
dispatch_map_t CSI;
|
||||||
|
dispatch_map_t control;
|
||||||
|
|
||||||
DispatchRegistry() : escape(), CSI() {}
|
DispatchRegistry() : escape(), CSI(), control() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
static DispatchRegistry global_dispatch_registry;
|
static DispatchRegistry global_dispatch_registry;
|
||||||
|
|||||||
@@ -104,3 +104,24 @@ void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN );
|
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 );
|
||||||
|
|||||||
Reference in New Issue
Block a user