Abstract cursor movement
This commit is contained in:
+33
-47
@@ -4,49 +4,42 @@
|
||||
|
||||
using namespace Terminal;
|
||||
|
||||
static void clearline( Framebuffer *fb, int row, int start, int end )
|
||||
{
|
||||
for ( int col = start; col <= end; col++ ) {
|
||||
fb->get_cell( row, col )->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void Emulator::CSI_EL( void )
|
||||
{
|
||||
/* default: active position to end of line, inclusive */
|
||||
int start = fb.ds.get_cursor_col(), end = fb.ds.get_width() - 1;
|
||||
|
||||
if ( as.params == "1" ) { /* start of screen to active position, inclusive */
|
||||
for ( int x = 0; x <= fb.cursor_col; x++ ) {
|
||||
if ( x < fb.width ) {
|
||||
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||
}
|
||||
}
|
||||
start = 0;
|
||||
end = fb.ds.get_cursor_col();
|
||||
} else if ( as.params == "2" ) { /* all of line */
|
||||
fb.rows[ fb.cursor_row ] = Row( fb.width );
|
||||
} else { /* active position to end of line, inclusive */
|
||||
for ( int x = fb.cursor_col; x < fb.width; x++ ) {
|
||||
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||
}
|
||||
start = 0;
|
||||
}
|
||||
|
||||
clearline( &fb, -1, start, end );
|
||||
}
|
||||
|
||||
void Emulator::CSI_ED( void ) {
|
||||
if ( as.params == "1" ) { /* start of screen to active position, inclusive */
|
||||
for ( int y = 0; y < fb.cursor_row; y++ ) {
|
||||
for ( int x = 0; x < fb.width; x++ ) {
|
||||
fb.rows[ y ].cells[ x ].reset();
|
||||
}
|
||||
}
|
||||
for ( int x = 0; x <= fb.cursor_col; x++ ) {
|
||||
if ( x < fb.width ) {
|
||||
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||
}
|
||||
for ( int y = 0; y < fb.ds.get_cursor_row(); y++ ) {
|
||||
clearline( &fb, y, 0, fb.ds.get_width() - 1 );
|
||||
}
|
||||
clearline( &fb, -1, 0, fb.ds.get_cursor_col() );
|
||||
} else if ( as.params == "2" ) { /* entire screen */
|
||||
for ( int y = 0; y < fb.height; y++ ) {
|
||||
for ( int x = 0; x < fb.width; x++ ) {
|
||||
fb.rows[ y ].cells[ x ].reset();
|
||||
}
|
||||
for ( int y = 0; y < fb.ds.get_height(); y++ ) {
|
||||
clearline( &fb, y, 0, fb.ds.get_width() - 1 );
|
||||
}
|
||||
} else { /* active position to end of screen, inclusive */
|
||||
for ( int x = fb.cursor_col; x < fb.width; x++ ) {
|
||||
fb.rows[ fb.cursor_row ].cells[ x ].reset();
|
||||
}
|
||||
for ( int y = fb.cursor_row + 1; y < fb.height; y++ ) {
|
||||
for ( int x = 0; x < fb.width; x++ ) {
|
||||
fb.rows[ y ].cells[ x ].reset();
|
||||
}
|
||||
clearline( &fb, -1, fb.ds.get_cursor_col(), fb.ds.get_width() - 1 );
|
||||
for ( int y = fb.ds.get_cursor_row() + 1; y < fb.ds.get_height(); y++ ) {
|
||||
clearline( &fb, y, 0, fb.ds.get_width() - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,31 +50,24 @@ void Emulator::CSI_cursormove( void )
|
||||
|
||||
switch ( as.dispatch_chars[ 0 ] ) {
|
||||
case 'A':
|
||||
fb.cursor_row -= num;
|
||||
fb.ds.move_row( -num, true );
|
||||
break;
|
||||
case 'B':
|
||||
fb.cursor_row += num;
|
||||
fb.ds.move_row( num, true );
|
||||
break;
|
||||
case 'C':
|
||||
fb.cursor_col += num;
|
||||
fb.ds.move_col( num, true );
|
||||
break;
|
||||
case 'D':
|
||||
fb.cursor_col -= num;
|
||||
fb.ds.move_col( -num, true );
|
||||
break;
|
||||
case 'H':
|
||||
case 'f':
|
||||
int x = as.getparam( 0, 1 );
|
||||
int y = as.getparam( 1, 1 );
|
||||
fb.cursor_row = x - 1;
|
||||
fb.cursor_col = y - 1;
|
||||
fb.ds.move_row( x - 1 );
|
||||
fb.ds.move_col( y - 1 );
|
||||
}
|
||||
|
||||
if ( fb.cursor_row < 0 ) fb.cursor_row = 0;
|
||||
if ( fb.cursor_row >= fb.height ) fb.cursor_row = fb.height - 1;
|
||||
if ( fb.cursor_col < 0 ) fb.cursor_col = 0;
|
||||
if ( fb.cursor_col >= fb.width ) fb.cursor_col = fb.width - 1;
|
||||
|
||||
fb.newgrapheme();
|
||||
}
|
||||
|
||||
void Emulator::CSI_DA( void )
|
||||
@@ -91,10 +77,10 @@ void Emulator::CSI_DA( void )
|
||||
|
||||
void Emulator::Esc_DECALN( void )
|
||||
{
|
||||
for ( int y = 0; y < fb.height; y++ ) {
|
||||
for ( int x = 0; x < fb.width; x++ ) {
|
||||
fb.rows[ y ].cells[ x ].reset();
|
||||
fb.rows[ y ].cells[ x ].contents.push_back( L'E' );
|
||||
for ( int y = 0; y < fb.ds.get_height(); y++ ) {
|
||||
for ( int x = 0; x < fb.ds.get_width(); x++ ) {
|
||||
fb.get_cell( y, x )->reset();
|
||||
fb.get_cell( y, x )->contents.push_back( L'E' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user