American National Standards Institute (ANSI) 参与进来。坚持其通过可互操作性来支持商业的要求,ANSI 介入并发布了标准 X3.64:Additional Controls for Use with American National Standard Code for Information Interchange。这个文件定义了现在所知的 ANSI 终端类型。它对将光标移动到屏幕上的特定位置、在光标位置插入和删除字符都规定了标准的命令序列。
Cursor Control SequencesErase SequencesA Move cursor up n lines @ Insert n blank spaces B Move cursor down n lines J Erase display: after cursor (n=0), before cursor (n=1), or entirely (n=2). C Move cursor forward n spaces D Move cursor backward n spaces K Erase line: after cursor (n=0), before cursor (n=1), or entirely (n=2). G Move cursor to column xH Move cursor to column x, row yL Insert n new blank lines d Move cursor to row yM Delete n lines from cursor s Save current cursor position P Delete n characters from cursor u Return to saved cursor position
/**
* Appends the specified ascii byte to the output.
*/
public void receive( byte b )
{
// ignore nulls
if ( b == 0 ) return;
if ( state == PARAMS_STATE )
{
// if still receiving parameters
if ( b < 64 )
{
argbuf[0]++;
// grow if needed
if ( argbuf[0] == argbuf.length )
{
char[] tmp = new char[ argbuf.length * 2 ];
System.arraycopy(
argbuf, 0, tmp, 0, argbuf.length );
argbuf = tmp;
}
argbuf[ argbuf[0] ] = (char) b;
}
else // final byte: process the command
{
processCommand( b );
// reset for next command
argbuf[0] = 0;
state = NORMAL_STATE;
}
}
else
if ( state == ESCAPE_STATE )
{
// if a valid escape sequence
if ( b == '[' )
{
state = PARAMS_STATE;
}
else // not an escape sequence
{
// allow escape to pass through
state = NORMAL_STATE;
processData( (byte) 27 );
processData( b );
}
}
else // NORMAL_STATE
{
if ( b == 27 )
{
state = ESCAPE_STATE;
}
else
{
processData( b );
}
}
}