First stab at modularizing (broken build)
This commit is contained in:
+6
-179
@@ -9,50 +9,9 @@
|
||||
|
||||
using namespace Terminal;
|
||||
|
||||
Cell::Cell()
|
||||
: overlapping_cell( NULL ),
|
||||
contents(),
|
||||
overlapped_cells(),
|
||||
fallback( false )
|
||||
{}
|
||||
|
||||
Cell::Cell( const Cell &x )
|
||||
: overlapping_cell( x.overlapping_cell ),
|
||||
contents( x.contents ),
|
||||
overlapped_cells( x.overlapped_cells ),
|
||||
fallback( x.fallback )
|
||||
{}
|
||||
|
||||
Cell & Cell::operator=( const Cell &x )
|
||||
{
|
||||
overlapping_cell = x.overlapping_cell;
|
||||
contents = x.contents;
|
||||
overlapped_cells = x.overlapped_cells;
|
||||
fallback = x.fallback;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Row::Row( size_t s_width )
|
||||
: cells( s_width )
|
||||
{}
|
||||
|
||||
Emulator::Emulator( size_t s_width, size_t s_height )
|
||||
: parser(),
|
||||
width( s_width ), height( s_height ),
|
||||
cursor_col( 0 ), cursor_row( 0 ),
|
||||
combining_char_col( 0 ), combining_char_row( 0 ),
|
||||
rows( height, Row( width ) ),
|
||||
params(), dispatch_chars(), terminal_to_host(),
|
||||
errors(), parsed_params()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Emulator::~Emulator()
|
||||
{
|
||||
|
||||
}
|
||||
: parser(), fb( s_height, s_width ), as(), terminal_to_host()
|
||||
{}
|
||||
|
||||
std::string Emulator::input( char c, int actfd )
|
||||
{
|
||||
@@ -67,56 +26,19 @@ std::string Emulator::input( char c, int actfd )
|
||||
|
||||
act->act_on_terminal( this );
|
||||
|
||||
/* print out debugging information */
|
||||
if ( (actfd > 0) && ( !act->handled ) ) {
|
||||
char actsum[ 64 ];
|
||||
char thechar[ 10 ] = { 0 };
|
||||
if ( act->char_present ) {
|
||||
if ( isprint( act->ch ) ) {
|
||||
snprintf( thechar, 10, "(%lc)", act->ch );
|
||||
} else {
|
||||
snprintf( thechar, 10, "(0x%x)", act->ch );
|
||||
}
|
||||
}
|
||||
snprintf( actsum, 64, "%s%s[disp=%s,param=%s] ",
|
||||
act->name().c_str(),
|
||||
thechar,
|
||||
dispatch_chars.c_str(),
|
||||
params.c_str() );
|
||||
|
||||
snprintf( actsum, 64, "%s%s ", act->str().c_str(), as.str().c_str() );
|
||||
swrite( actfd, actsum );
|
||||
}
|
||||
|
||||
delete act;
|
||||
}
|
||||
|
||||
/* the user is supposed to send this string to the host, as if typed */
|
||||
return terminal_to_host;
|
||||
}
|
||||
|
||||
void Emulator::scroll( int N )
|
||||
{
|
||||
assert( N >= 0 );
|
||||
|
||||
for ( int i = 0; i < N; i++ ) {
|
||||
rows.pop_front();
|
||||
rows.push_back( Row( width ) );
|
||||
cursor_row--;
|
||||
combining_char_row--;
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::newgrapheme( void )
|
||||
{
|
||||
combining_char_col = cursor_col;
|
||||
combining_char_row = cursor_row;
|
||||
}
|
||||
|
||||
void Emulator::autoscroll( void )
|
||||
{
|
||||
if ( cursor_row >= height ) { /* scroll */
|
||||
scroll( cursor_row - height + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::execute( Parser::Execute *act )
|
||||
{
|
||||
assert( act->char_present );
|
||||
@@ -171,13 +93,12 @@ void Emulator::print( Parser::Print *act )
|
||||
}
|
||||
|
||||
autoscroll();
|
||||
newgrapheme();
|
||||
|
||||
this_cell = &rows[ cursor_row ].cells[ cursor_col ];
|
||||
this_cell->reset();
|
||||
this_cell->contents.push_back( act->ch );
|
||||
|
||||
newgrapheme();
|
||||
|
||||
if ( (cursor_col < width - 1) && (chwidth == 2) ) {
|
||||
Cell *next_cell = &rows[ cursor_row ].cells[ cursor_col + 1 ];
|
||||
this_cell->overlapped_cells.push_back( next_cell );
|
||||
@@ -246,34 +167,6 @@ void Emulator::debug_printout( int fd )
|
||||
swrite( fd, screen.c_str() );
|
||||
}
|
||||
|
||||
void Emulator::param( Parser::Param *act )
|
||||
{
|
||||
assert( act->char_present );
|
||||
assert( (act->ch == ';') || ( (act->ch >= '0') && (act->ch <= '9') ) );
|
||||
if ( params.length() < 100 ) {
|
||||
/* enough for 16 five-char params plus 15 semicolons */
|
||||
params.push_back( act->ch );
|
||||
act->handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::collect( Parser::Collect *act )
|
||||
{
|
||||
assert( act->char_present );
|
||||
if ( ( dispatch_chars.length() < 8 ) /* never should need more than 2 */
|
||||
&& ( act->ch <= 255 ) ) { /* ignore non-8-bit */
|
||||
dispatch_chars.push_back( act->ch );
|
||||
act->handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::clear( Parser::Clear *act )
|
||||
{
|
||||
params.clear();
|
||||
dispatch_chars.clear();
|
||||
act->handled = true;
|
||||
}
|
||||
|
||||
void Emulator::CSI_dispatch( Parser::CSI_Dispatch *act )
|
||||
{
|
||||
/* add final char to dispatch key */
|
||||
@@ -317,69 +210,3 @@ void Emulator::Esc_dispatch( Parser::Esc_Dispatch *act )
|
||||
act->handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::parse_params( void )
|
||||
{
|
||||
parsed_params.clear();
|
||||
const char *str = params.c_str();
|
||||
const char *segment_begin = str;
|
||||
|
||||
while ( 1 ) {
|
||||
const char *segment_end = strchr( segment_begin, ';' );
|
||||
if ( segment_end == NULL ) {
|
||||
break;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
int val = strtol( segment_begin, &endptr, 10 );
|
||||
if ( endptr == segment_begin ) {
|
||||
val = -1;
|
||||
}
|
||||
if ( errno == 0 ) {
|
||||
parsed_params.push_back( val );
|
||||
}
|
||||
|
||||
segment_begin = segment_end + 1;
|
||||
}
|
||||
|
||||
/* get last param */
|
||||
errno = 0;
|
||||
char *endptr;
|
||||
int val = strtol( segment_begin, &endptr, 10 );
|
||||
if ( endptr == segment_begin ) {
|
||||
val = -1;
|
||||
}
|
||||
if ( errno == 0 ) {
|
||||
parsed_params.push_back( val );
|
||||
}
|
||||
}
|
||||
|
||||
int Emulator::getparam( size_t N, int defaultval )
|
||||
{
|
||||
int ret = defaultval;
|
||||
if ( parsed_params.size() > N ) {
|
||||
ret = parsed_params[ N ];
|
||||
}
|
||||
if ( ret < 1 ) ret = defaultval;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Cell::reset( void )
|
||||
{
|
||||
contents.clear();
|
||||
fallback = false;
|
||||
|
||||
if ( overlapping_cell ) {
|
||||
assert( overlapped_cells.size() == 0 );
|
||||
} else {
|
||||
for ( std::vector<Cell *>::iterator i = overlapped_cells.begin();
|
||||
i != overlapped_cells.end();
|
||||
i++ ) {
|
||||
(*i)->overlapping_cell = NULL;
|
||||
(*i)->reset();
|
||||
}
|
||||
overlapped_cells.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user