Optimised Frame::parse()
This commit is contained in:
41
load/defs.js
41
load/defs.js
@@ -44,6 +44,7 @@ function Frame() {
|
||||
this.key=[ null,null,null,null,null,null,null,null,null,null ];
|
||||
|
||||
// Initialise frame array
|
||||
/*
|
||||
this.frame_data = {};
|
||||
this.frame_content = {};
|
||||
for(x=0;x<FRAME_LENGTH;x++)
|
||||
@@ -51,6 +52,7 @@ function Frame() {
|
||||
this.frame_data[x] = {};
|
||||
this.frame_content[x] = {};
|
||||
}
|
||||
*/
|
||||
this.frame_fields = [];
|
||||
|
||||
this.raw=function() {
|
||||
@@ -128,7 +130,6 @@ Frame.prototype.load = function(filename) {
|
||||
* Additionally, for response frames, if the cursor is moved to a field, its to determine what attributes (eg: color)
|
||||
* should apply for that field.
|
||||
*
|
||||
* @todo This function could be advanced by looking for the next KEY_ESC char, instead of progressing 1 char at a time
|
||||
* @param text
|
||||
*/
|
||||
Frame.prototype.parse = function(text) {
|
||||
@@ -142,6 +143,21 @@ Frame.prototype.parse = function(text) {
|
||||
i = 0;
|
||||
|
||||
for(p=0;p<text.length;p++) {
|
||||
// Look for a special character until the end of the frame width
|
||||
cte = (r*FRAME_WIDTH - ((r-1)*FRAME_WIDTH+c));
|
||||
match = text.substr(p,cte).match(/[\r\n\x1b]/);
|
||||
log(LOG_DEBUG,'SPECIAL CHAR ['+r+'x'+c+'] ['+p+'-'+cte+'] for: '+match);
|
||||
|
||||
if (match == null || match.index) {
|
||||
advance = match ? match.index : cte;
|
||||
log(LOG_DEBUG,'INCLUDE: '+text.substr(p,advance));
|
||||
|
||||
output += text.substr(p,advance);
|
||||
p += advance;
|
||||
c += advance;
|
||||
advance = 0;
|
||||
}
|
||||
|
||||
// If the frame is not big enough, fill it with spaces.
|
||||
byte = text.charAt(p);
|
||||
advance = 0;
|
||||
@@ -173,8 +189,8 @@ Frame.prototype.parse = function(text) {
|
||||
chars = '';
|
||||
|
||||
// Find our end CSI param in the next 50 chars
|
||||
matches = text.substring(p+advance,p+advance+50).match(/([0-9]+[;]?)+([a-zA-Z])/);
|
||||
log(LOG_DEBUG,'CSI ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', STRING: '+text.substring(p+advance,p+advance+50));
|
||||
matches = text.substr(p+advance,50).match(/([0-9]+[;]?)+([a-zA-Z])/);
|
||||
log(LOG_DEBUG,'CSI ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', STRING: '+text.substr(p+advance,50));
|
||||
|
||||
if (! matches) {
|
||||
chars += nextbyte;
|
||||
@@ -235,8 +251,8 @@ Frame.prototype.parse = function(text) {
|
||||
advance++;
|
||||
|
||||
// Find our end ST param in the next 50 chars
|
||||
matches = text.substring(p+advance,p+advance+50).match(/(([A-Z]+;[0-9a-z]+)([;]?.+)?)\x1b\\/);
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', LENGTH: '+matches[0].length+', STRING: '+text.substring(p+advance,p+advance+50));
|
||||
matches = text.substr(p+advance,50).match(/(([A-Z]+;[0-9a-z]+)([;]?.+)?)\x1b\\/);
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', LENGTH: '+matches[0].length+', STRING: '+text.substr(p+advance,50));
|
||||
|
||||
if (! matches) {
|
||||
chars += nextbyte;
|
||||
@@ -291,13 +307,14 @@ Frame.prototype.parse = function(text) {
|
||||
byte = '';
|
||||
|
||||
this.frame_fields.push({
|
||||
'type': fieldtype,
|
||||
'length': fieldlen,
|
||||
'r': r,
|
||||
'c': c,
|
||||
type: fieldtype,
|
||||
length: fieldlen,
|
||||
r: r,
|
||||
c: c,
|
||||
attribute: {i:i,f:f,b:b},
|
||||
});
|
||||
|
||||
log(LOG_DEBUG,'SOS Field found at ['+r+'x'+(c-1)+'], Type: '+fieldtype+', Length: '+fieldlen);
|
||||
log(LOG_DEBUG,'SOS Field found at ['+r+'x'+(c-1)+'], Type: '+fieldtype+', Length: '+fieldlen+', Attrs: '+JSON.stringify({i:i,f:f,b:b}));
|
||||
|
||||
break;
|
||||
|
||||
@@ -308,8 +325,8 @@ Frame.prototype.parse = function(text) {
|
||||
break;
|
||||
|
||||
default:
|
||||
this.frame_data[r][c] = {i:i,f:f,b:b};
|
||||
this.frame_content[r][c] = byte;
|
||||
//this.frame_data[r][c] = {i:i,f:f,b:b};
|
||||
//this.frame_content[r][c] = byte;
|
||||
log(LOG_DEBUG,'ADD OUTPUT ['+r+'x'+c+'] for: '+byte);
|
||||
c++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user