Refactor in progress for more modular terminal
This commit is contained in:
+5
-5
@@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
using namespace Parser;
|
using namespace Parser;
|
||||||
|
|
||||||
std::string Parser::str( void )
|
std::string Action::str( void )
|
||||||
{
|
{
|
||||||
char thechar[ 10 ] = { 0 };
|
char thechar[ 10 ] = { 0 };
|
||||||
if ( char_present ) {
|
if ( char_present ) {
|
||||||
snprintf( thechar, 10, isprint( ch ) ? "(%lc)" : "(0x%x)", act->ch );
|
snprintf( thechar, 10, isprint( ch ) ? "(%lc)" : "(0x%x)", ch );
|
||||||
}
|
}
|
||||||
|
|
||||||
return name() + std::string( thechar );
|
return name() + std::string( thechar );
|
||||||
@@ -28,17 +28,17 @@ void Execute::act_on_terminal( Terminal::Emulator *emu )
|
|||||||
|
|
||||||
void Clear::act_on_terminal( Terminal::Emulator *emu )
|
void Clear::act_on_terminal( Terminal::Emulator *emu )
|
||||||
{
|
{
|
||||||
emu->clear( this );
|
emu->as.clear( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Param::act_on_terminal( Terminal::Emulator *emu )
|
void Param::act_on_terminal( Terminal::Emulator *emu )
|
||||||
{
|
{
|
||||||
emu->param( this );
|
emu->as.newparamchar( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Collect::act_on_terminal( Terminal::Emulator *emu )
|
void Collect::act_on_terminal( Terminal::Emulator *emu )
|
||||||
{
|
{
|
||||||
emu->collect( this );
|
emu->as.collect( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSI_Dispatch::act_on_terminal( Terminal::Emulator *emu )
|
void CSI_Dispatch::act_on_terminal( Terminal::Emulator *emu )
|
||||||
|
|||||||
+40
-38
@@ -10,7 +10,7 @@
|
|||||||
using namespace Terminal;
|
using namespace Terminal;
|
||||||
|
|
||||||
Emulator::Emulator( size_t s_width, size_t s_height )
|
Emulator::Emulator( size_t s_width, size_t s_height )
|
||||||
: parser(), fb( s_height, s_width ), as(), terminal_to_host()
|
: parser(), fb( s_width, s_height ), as(), terminal_to_host()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string Emulator::input( char c, int actfd )
|
std::string Emulator::input( char c, int actfd )
|
||||||
@@ -45,22 +45,22 @@ void Emulator::execute( Parser::Execute *act )
|
|||||||
|
|
||||||
switch ( act->ch ) {
|
switch ( act->ch ) {
|
||||||
case 0x0a: /* LF */
|
case 0x0a: /* LF */
|
||||||
cursor_row++;
|
fb.cursor_row++;
|
||||||
autoscroll();
|
fb.autoscroll();
|
||||||
newgrapheme();
|
fb.newgrapheme();
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0d: /* CR */
|
case 0x0d: /* CR */
|
||||||
cursor_col = 0;
|
fb.cursor_col = 0;
|
||||||
newgrapheme();
|
fb.newgrapheme();
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x08: /* BS */
|
case 0x08: /* BS */
|
||||||
if ( cursor_col > 0 ) {
|
if ( fb.cursor_col > 0 ) {
|
||||||
cursor_col--;
|
fb.cursor_col--;
|
||||||
newgrapheme(); /* this is not xterm's behavior */
|
fb.newgrapheme(); /* this is not xterm's behavior */
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -71,14 +71,14 @@ void Emulator::print( Parser::Print *act )
|
|||||||
{
|
{
|
||||||
assert( act->char_present );
|
assert( act->char_present );
|
||||||
|
|
||||||
if ( (width == 0) || (height == 0) ) {
|
if ( (fb.width == 0) || (fb.height == 0) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( cursor_row < height ); /* must be on screen */
|
assert( fb.cursor_row < fb.height ); /* must be on screen */
|
||||||
assert( cursor_col <= width + 1 ); /* two off is ok */
|
assert( fb.cursor_col <= fb.width + 1 ); /* two off is ok */
|
||||||
assert( combining_char_row < height );
|
assert( fb.combining_char_row < fb.height );
|
||||||
assert( combining_char_col < width );
|
assert( fb.combining_char_col < fb.width );
|
||||||
|
|
||||||
int chwidth = act->ch == L'\0' ? -1 : wcwidth( act->ch );
|
int chwidth = act->ch == L'\0' ? -1 : wcwidth( act->ch );
|
||||||
|
|
||||||
@@ -87,40 +87,40 @@ void Emulator::print( Parser::Print *act )
|
|||||||
switch ( chwidth ) {
|
switch ( chwidth ) {
|
||||||
case 1: /* normal character */
|
case 1: /* normal character */
|
||||||
case 2: /* wide character */
|
case 2: /* wide character */
|
||||||
if ( cursor_col >= width ) { /* wrap */
|
if ( fb.cursor_col >= fb.width ) { /* wrap */
|
||||||
cursor_col = 0;
|
fb.cursor_col = 0;
|
||||||
cursor_row++;
|
fb.cursor_row++;
|
||||||
}
|
}
|
||||||
|
|
||||||
autoscroll();
|
fb.autoscroll();
|
||||||
newgrapheme();
|
fb.newgrapheme();
|
||||||
|
|
||||||
this_cell = &rows[ cursor_row ].cells[ cursor_col ];
|
this_cell = &fb.rows[ fb.cursor_row ].cells[ fb.cursor_col ];
|
||||||
this_cell->reset();
|
this_cell->reset();
|
||||||
this_cell->contents.push_back( act->ch );
|
this_cell->contents.push_back( act->ch );
|
||||||
|
|
||||||
if ( (cursor_col < width - 1) && (chwidth == 2) ) {
|
if ( (fb.cursor_col < fb.width - 1) && (chwidth == 2) ) {
|
||||||
Cell *next_cell = &rows[ cursor_row ].cells[ cursor_col + 1 ];
|
Cell *next_cell = &fb.rows[ fb.cursor_row ].cells[ fb.cursor_col + 1 ];
|
||||||
this_cell->overlapped_cells.push_back( next_cell );
|
this_cell->overlapped_cells.push_back( next_cell );
|
||||||
next_cell->overlapping_cell = this_cell;
|
next_cell->overlapping_cell = this_cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor_col += chwidth;
|
fb.cursor_col += chwidth;
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
break;
|
break;
|
||||||
case 0: /* combining character */
|
case 0: /* combining character */
|
||||||
if ( rows[ combining_char_row ].cells[ combining_char_col ].contents.size() == 0 ) {
|
if ( fb.rows[ fb.combining_char_row ].cells[ fb.combining_char_col ].contents.size() == 0 ) {
|
||||||
/* cell starts with combining character */
|
/* cell starts with combining character */
|
||||||
rows[ combining_char_row ].cells[ combining_char_col ].fallback = true;
|
fb.rows[ fb.combining_char_row ].cells[ fb.combining_char_col ].fallback = true;
|
||||||
assert( cursor_col == combining_char_col );
|
assert( fb.cursor_col == fb.combining_char_col );
|
||||||
assert( cursor_row == combining_char_row );
|
assert( fb.cursor_row == fb.combining_char_row );
|
||||||
assert( cursor_col < width );
|
assert( fb.cursor_col < fb.width );
|
||||||
cursor_col++;
|
fb.cursor_col++;
|
||||||
/* a combining character should never be able to wrap us */
|
/* a combining character should never be able to wrap us */
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( rows[ combining_char_row ].cells[ combining_char_col ].contents.size() < 16 ) { /* seems like a reasonable limit on combining character */
|
if ( fb.rows[ fb.combining_char_row ].cells[ fb.combining_char_col ].contents.size() < 16 ) { /* seems like a reasonable limit on combining character */
|
||||||
rows[ combining_char_row ].cells[ combining_char_col ].contents.push_back( act->ch );
|
fb.rows[ fb.combining_char_row ].cells[ fb.combining_char_col ].contents.push_back( act->ch );
|
||||||
}
|
}
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
break;
|
break;
|
||||||
@@ -136,12 +136,12 @@ void Emulator::debug_printout( int fd )
|
|||||||
std::string screen;
|
std::string screen;
|
||||||
screen.append( "\033[H\033[2J" );
|
screen.append( "\033[H\033[2J" );
|
||||||
|
|
||||||
for ( int y = 0; y < height; y++ ) {
|
for ( int y = 0; y < fb.height; y++ ) {
|
||||||
for ( int x = 0; x < width; x++ ) {
|
for ( int x = 0; x < fb.width; x++ ) {
|
||||||
char curmove[ 32 ];
|
char curmove[ 32 ];
|
||||||
snprintf( curmove, 32, "\033[%d;%dH", y + 1, x + 1 );
|
snprintf( curmove, 32, "\033[%d;%dH", y + 1, x + 1 );
|
||||||
screen.append( curmove );
|
screen.append( curmove );
|
||||||
Cell *cell = &rows[ y ].cells[ x ];
|
Cell *cell = &fb.rows[ y ].cells[ x ];
|
||||||
if ( cell->overlapping_cell ) continue;
|
if ( cell->overlapping_cell ) continue;
|
||||||
|
|
||||||
if ( cell->fallback ) {
|
if ( cell->fallback ) {
|
||||||
@@ -161,7 +161,7 @@ void Emulator::debug_printout( int fd )
|
|||||||
}
|
}
|
||||||
|
|
||||||
char curmove[ 32 ];
|
char curmove[ 32 ];
|
||||||
snprintf( curmove, 32, "\033[%d;%dH", cursor_row + 1, cursor_col + 1 );
|
snprintf( curmove, 32, "\033[%d;%dH", fb.cursor_row + 1, fb.cursor_col + 1 );
|
||||||
screen.append( curmove );
|
screen.append( curmove );
|
||||||
|
|
||||||
swrite( fd, screen.c_str() );
|
swrite( fd, screen.c_str() );
|
||||||
@@ -174,7 +174,9 @@ void Emulator::CSI_dispatch( Parser::CSI_Dispatch *act )
|
|||||||
Parser::Collect act2;
|
Parser::Collect act2;
|
||||||
act2.char_present = true;
|
act2.char_present = true;
|
||||||
act2.ch = act->ch;
|
act2.ch = act->ch;
|
||||||
collect( &act2 );
|
as.collect( &act2 );
|
||||||
|
|
||||||
|
std::string dispatch_chars = as.dispatch_chars;
|
||||||
|
|
||||||
if ( dispatch_chars == "K" ) {
|
if ( dispatch_chars == "K" ) {
|
||||||
CSI_EL();
|
CSI_EL();
|
||||||
@@ -203,9 +205,9 @@ void Emulator::Esc_dispatch( Parser::Esc_Dispatch *act )
|
|||||||
Parser::Collect act2;
|
Parser::Collect act2;
|
||||||
act2.char_present = true;
|
act2.char_present = true;
|
||||||
act2.ch = act->ch;
|
act2.ch = act->ch;
|
||||||
collect( &act2 );
|
as.collect( &act2 );
|
||||||
|
|
||||||
if ( dispatch_chars == "#8" ) {
|
if ( as.dispatch_chars == "#8" ) {
|
||||||
Esc_DECALN();
|
Esc_DECALN();
|
||||||
act->handled = true;
|
act->handled = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "terminalactionstate.hpp"
|
#include "terminalactionstate.hpp"
|
||||||
#include "parseraction.hpp"
|
#include "parseraction.hpp"
|
||||||
@@ -9,7 +11,7 @@ ActionState::ActionState()
|
|||||||
: params(), parsed_params(), parsed( false ), dispatch_chars()
|
: params(), parsed_params(), parsed( false ), dispatch_chars()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void newparamchar( Parser::Param *act )
|
void ActionState::newparamchar( Parser::Param *act )
|
||||||
{
|
{
|
||||||
assert( act->char_present );
|
assert( act->char_present );
|
||||||
assert( (act->ch == ';') || ( (act->ch >= '0') && (act->ch <= '9') ) );
|
assert( (act->ch == ';') || ( (act->ch >= '0') && (act->ch <= '9') ) );
|
||||||
@@ -100,7 +102,7 @@ int ActionState::getparam( size_t N, int defaultval )
|
|||||||
std::string ActionState::str( void )
|
std::string ActionState::str( void )
|
||||||
{
|
{
|
||||||
char assum[ 64 ];
|
char assum[ 64 ];
|
||||||
snprintf( assum, 64, "[dispatch=%s params=%s]",
|
snprintf( assum, 64, "[dispatch=\"%s\" params=\"%s\"]",
|
||||||
dispatch_chars.c_str(), params.c_str() );
|
dispatch_chars.c_str(), params.c_str() );
|
||||||
return std::string( assum );
|
return std::string( assum );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define TERMINALACTIONSTATE_HPP
|
#define TERMINALACTIONSTATE_HPP
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Parser {
|
namespace Parser {
|
||||||
class Param;
|
class Param;
|
||||||
@@ -12,6 +13,7 @@ namespace Parser {
|
|||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
class ActionState {
|
class ActionState {
|
||||||
private:
|
private:
|
||||||
|
public: /* tmp */
|
||||||
std::string params;
|
std::string params;
|
||||||
std::vector<int> parsed_params;
|
std::vector<int> parsed_params;
|
||||||
bool parsed;
|
bool parsed;
|
||||||
|
|||||||
+43
-44
@@ -6,46 +6,46 @@ using namespace Terminal;
|
|||||||
|
|
||||||
void Emulator::CSI_EL( void )
|
void Emulator::CSI_EL( void )
|
||||||
{
|
{
|
||||||
if ( params == "1" ) { /* start of screen to active position, inclusive */
|
if ( as.params == "1" ) { /* start of screen to active position, inclusive */
|
||||||
for ( int x = 0; x <= cursor_col; x++ ) {
|
for ( int x = 0; x <= fb.cursor_col; x++ ) {
|
||||||
if ( x < width ) {
|
if ( x < fb.width ) {
|
||||||
rows[ cursor_row ].cells[ x ].reset();
|
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( params == "2" ) { /* all of line */
|
} else if ( as.params == "2" ) { /* all of line */
|
||||||
rows[ cursor_row ] = Row( width );
|
fb.rows[ fb.cursor_row ] = Row( fb.width );
|
||||||
} else { /* active position to end of line, inclusive */
|
} else { /* active position to end of line, inclusive */
|
||||||
for ( int x = cursor_col; x < width; x++ ) {
|
for ( int x = fb.cursor_col; x < fb.width; x++ ) {
|
||||||
rows[ cursor_row ].cells[ x ].reset();
|
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::CSI_ED( void ) {
|
void Emulator::CSI_ED( void ) {
|
||||||
if ( params == "1" ) { /* start of screen to active position, inclusive */
|
if ( as.params == "1" ) { /* start of screen to active position, inclusive */
|
||||||
for ( int y = 0; y < cursor_row; y++ ) {
|
for ( int y = 0; y < fb.cursor_row; y++ ) {
|
||||||
for ( int x = 0; x < width; x++ ) {
|
for ( int x = 0; x < fb.width; x++ ) {
|
||||||
rows[ y ].cells[ x ].reset();
|
fb.rows[ y ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( int x = 0; x <= cursor_col; x++ ) {
|
for ( int x = 0; x <= fb.cursor_col; x++ ) {
|
||||||
if ( x < width ) {
|
if ( x < fb.width ) {
|
||||||
rows[ cursor_row ].cells[ x ].reset();
|
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( params == "2" ) { /* entire screen */
|
} else if ( as.params == "2" ) { /* entire screen */
|
||||||
for ( int y = 0; y < height; y++ ) {
|
for ( int y = 0; y < fb.height; y++ ) {
|
||||||
for ( int x = 0; x < width; x++ ) {
|
for ( int x = 0; x < fb.width; x++ ) {
|
||||||
rows[ y ].cells[ x ].reset();
|
fb.rows[ y ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* active position to end of screen, inclusive */
|
} else { /* active position to end of screen, inclusive */
|
||||||
for ( int x = cursor_col; x < width; x++ ) {
|
for ( int x = fb.cursor_col; x < fb.width; x++ ) {
|
||||||
rows[ cursor_row ].cells[ x ].reset();
|
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
for ( int y = cursor_row + 1; y < height; y++ ) {
|
for ( int y = fb.cursor_row + 1; y < fb.height; y++ ) {
|
||||||
for ( int x = 0; x < width; x++ ) {
|
for ( int x = 0; x < fb.width; x++ ) {
|
||||||
rows[ y ].cells[ x ].reset();
|
fb.rows[ y ].cells[ x ].reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,36 +53,35 @@ void Emulator::CSI_ED( void ) {
|
|||||||
|
|
||||||
void Emulator::CSI_cursormove( void )
|
void Emulator::CSI_cursormove( void )
|
||||||
{
|
{
|
||||||
parse_params();
|
int num = as.getparam( 0, 1 );
|
||||||
int num = getparam( 0, 1 );
|
|
||||||
|
|
||||||
switch ( dispatch_chars[ 0 ] ) {
|
switch ( as.dispatch_chars[ 0 ] ) {
|
||||||
case 'A':
|
case 'A':
|
||||||
cursor_row -= num;
|
fb.cursor_row -= num;
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
cursor_row += num;
|
fb.cursor_row += num;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
cursor_col += num;
|
fb.cursor_col += num;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
cursor_col -= num;
|
fb.cursor_col -= num;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
case 'f':
|
case 'f':
|
||||||
int x = getparam( 0, 1 );
|
int x = as.getparam( 0, 1 );
|
||||||
int y = getparam( 1, 1 );
|
int y = as.getparam( 1, 1 );
|
||||||
cursor_row = x - 1;
|
fb.cursor_row = x - 1;
|
||||||
cursor_col = y - 1;
|
fb.cursor_col = y - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cursor_row < 0 ) cursor_row = 0;
|
if ( fb.cursor_row < 0 ) fb.cursor_row = 0;
|
||||||
if ( cursor_row >= height ) cursor_row = height - 1;
|
if ( fb.cursor_row >= fb.height ) fb.cursor_row = fb.height - 1;
|
||||||
if ( cursor_col < 0 ) cursor_col = 0;
|
if ( fb.cursor_col < 0 ) fb.cursor_col = 0;
|
||||||
if ( cursor_col >= width ) cursor_col = width - 1;
|
if ( fb.cursor_col >= fb.width ) fb.cursor_col = fb.width - 1;
|
||||||
|
|
||||||
newgrapheme();
|
fb.newgrapheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::CSI_DA( void )
|
void Emulator::CSI_DA( void )
|
||||||
@@ -92,10 +91,10 @@ void Emulator::CSI_DA( void )
|
|||||||
|
|
||||||
void Emulator::Esc_DECALN( void )
|
void Emulator::Esc_DECALN( void )
|
||||||
{
|
{
|
||||||
for ( int y = 0; y < height; y++ ) {
|
for ( int y = 0; y < fb.height; y++ ) {
|
||||||
for ( int x = 0; x < width; x++ ) {
|
for ( int x = 0; x < fb.width; x++ ) {
|
||||||
rows[ y ].cells[ x ].reset();
|
fb.rows[ y ].cells[ x ].reset();
|
||||||
rows[ y ].cells[ x ].contents.push_back( L'E' );
|
fb.rows[ y ].cells[ x ].contents.push_back( L'E' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "terminalframebuffer.hpp"
|
#include "terminalframebuffer.hpp"
|
||||||
|
|
||||||
using namespace Terminal;
|
using namespace Terminal;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#ifndef TERMINALFB_HPP
|
#ifndef TERMINALFB_HPP
|
||||||
#define TERMINALFB_HPP
|
#define TERMINALFB_HPP
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
/* Terminal framebuffer */
|
/* Terminal framebuffer */
|
||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal {
|
||||||
|
|||||||
Reference in New Issue
Block a user