Handle cursor position (CUP)

This commit is contained in:
Keith Winstein
2011-01-22 05:10:18 -05:00
parent cfd279fa25
commit 96bf1d211b
3 changed files with 26 additions and 6 deletions
+19 -2
View File
@@ -256,7 +256,10 @@ void Emulator::parse_params( void )
errno = 0; errno = 0;
char *endptr; char *endptr;
int val = strtol( segment_begin, &endptr, 10 ); int val = strtol( segment_begin, &endptr, 10 );
if ( (errno == 0) && (endptr != segment_begin) ) { if ( endptr == segment_begin ) {
val = -1;
}
if ( errno == 0 ) {
parsed_params.push_back( val ); parsed_params.push_back( val );
} }
@@ -267,7 +270,21 @@ void Emulator::parse_params( void )
errno = 0; errno = 0;
char *endptr; char *endptr;
int val = strtol( segment_begin, &endptr, 10 ); int val = strtol( segment_begin, &endptr, 10 );
if ( (errno == 0) && (endptr != segment_begin) ) { if ( endptr == segment_begin ) {
val = -1;
}
if ( errno == 0 ) {
parsed_params.push_back( val ); 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;
}
+1
View File
@@ -62,6 +62,7 @@ namespace Terminal {
void parse_params( void ); void parse_params( void );
std::vector<int> parsed_params; std::vector<int> parsed_params;
int getparam( size_t N, int defaultval );
/* CSI methods */ /* CSI methods */
void CSI_EL( void ); void CSI_EL( void );
+6 -4
View File
@@ -22,10 +22,7 @@ void Emulator::CSI_EL( void )
void Emulator::CSI_cursormove( void ) void Emulator::CSI_cursormove( void )
{ {
parse_params(); parse_params();
int num = 1; int num = getparam( 0, 1 );
if ( parsed_params.size() >= 1 ) {
num = parsed_params[ 0 ];
}
switch ( dispatch_chars[ 0 ] ) { switch ( dispatch_chars[ 0 ] ) {
case 'A': case 'A':
@@ -40,6 +37,11 @@ void Emulator::CSI_cursormove( void )
case 'D': case 'D':
cursor_col -= num; cursor_col -= num;
break; break;
case 'H':
int x = getparam( 0, 1 );
int y = getparam( 1, 1 );
cursor_row = x - 1;
cursor_col = y - 1;
} }
if ( cursor_row < 0 ) cursor_row = 0; if ( cursor_row < 0 ) cursor_row = 0;