Move more functions that are ansi specific to ANSIFrame

This commit is contained in:
Deon George
2020-07-30 00:15:48 +10:00
parent 17f2265249
commit d57311e935
4 changed files with 138 additions and 119 deletions

View File

@@ -1,11 +1,26 @@
var FRAME_ANSI=(1<<1);
var ANSI_FRAME_LENGTH =22; /* Length of a frame */
var ANSI_FRAME_WIDTH =80; /* Width of a frame */
var ANSI_FRAME_WIDTH =80; /* Width of a frame */
var ANSI_FRAME_HEADER =56; /* Size of page owner (length) */
var ANSI_FRAME_PAGENUM =12; /* Size of page number (length with a-z) */
var ANSI_FRAME_COST = 9; /* Size of cost (length without unit) */
var ANSI_MSG_SENDORNOT ='\1n\1h\1GKEY 1 TO SEND, 2 NOT TO SEND';
var ANSI_MSG_LOGON ='\1n\1h\1GKEY 1 TO LOGON, 2 TO RETURN';
var ANSI_MSG_SENT ='\1n\1h\1GMESSAGE SENT - KEY # TO CONTINUE';
var ANSI_MSG_NOTSENT ='\1n\1h\1GMESSAGE NOT SENT - KEY # TO CONTINUE';
var ANSI_ERR_NO_PARENT ='\1n\1h\1RPARENT FRAME DOESNT EXIST';
var ANSI_ERR_NOT_IMPLEMENTED ='\1n\1h\1RNOT IMPLEMENTED YET?';
var ANSI_ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
var ANSI_ERR_METHOD_NOT_EXIST ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
var ANSI_ACCESS_DENIED ='\1n\1h\1RACCESS DENIED. \1RMISTAKE? TRY AGAIN OR TELL US *08';
var ANSI_ALREADY_MEMBER ='\1n\1h\1RALREADY MEMBER OF CUG'
var ANSI_INACTIVITY ='\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...';
var ANSI_INACTIVE ='\1n\1h\1RINACTIVITY DISCONNECT';
var ANSI_NOACTION ='\1n\1h\1RNO ACTION PERFORMED';
var ANSI_BASESTAR ='\1N\1G\1H*';
// Our frame object
function ANSIFrame() {
this.version=1; // The version of this frame - in case we update functionality and we need to be
@@ -34,17 +49,31 @@ function ANSIFrame() {
this.type = FRAME_TYPE_INFO; // The frame type - see FRAME_TYPES above
this.key=[ null,null,null,null,null,null,null,null,null,null ]; // Key actions [0-9]
/**
* Turn off the cursor
*/
this.cursorOff=function() {
ansi.send('ext_mode','clear','cursor');
console.gotoxy(0,24);
}
this.cursorOn=function(x,y) {
ansi.send('ext_mode','set','cursor');
console.gotoxy(x,y);
}
// Render the frame to the user
this.render=function(withHeader) {
log(LOG_DEBUG,'- ANSI FRAME');
owner = base64_decode(this.owner);
header = '\n\r';
log(LOG_DEBUG,'- FRAME User: ['+JSON.stringify(user)+']');
log(LOG_DEBUG,' - FRAME User: ['+JSON.stringify(user)+']');
// Dont show the page number on system login page
if (user.number || (this.type != FRAME_TYPE_LOGIN && NO_HISTORY_FRAMES.indexOf(this.page) == -1)) {
log(LOG_DEBUG,'- Owner: ['+this.pageowner+']');
log(LOG_DEBUG,' - Owner: ['+this.pageowner+']');
cost = (this.isAccessible ? this.cost+FRAME_COSTUNIT : ' -')
@@ -54,10 +83,12 @@ function ANSIFrame() {
(console.screen_columns > 80 ? '\n\r' : '');
}
console.clear();
if ((this.type == FRAME_TYPE_LOGIN) || (this.type == FRAME_TYPE_RESPONSE)) {
return header+this.parse(base64_decode(this.content));
return console.putmsg(header+this.parse(base64_decode(this.content)));
} else {
return header+base64_decode(this.content);
return console.putmsg(header+base64_decode(this.content));
}
};
@@ -75,7 +106,7 @@ function ANSIFrame() {
// Load a frame from disk (.tex file)
this.load = function(filename) {
log(LOG_DEBUG,'Loading frame from: '+filename);
log(LOG_DEBUG,'Loading ANSI frame from: '+filename);
f = new File(system.mods_dir+'ansitex/text/'+filename+'.tex');
if (! f.exists || ! f.open('r')) {
@@ -349,6 +380,35 @@ function ANSIFrame() {
log(LOG_DEBUG,'Saved file: '+this.page+'.tex');
}
/**
* Send a message to the baseline.
*
* @param text
* @param reposition
*/
this.sendBaseline=function(text,reposition) {
eval('var msg = ANSI_'+text+';');
console.pushxy();
console.gotoxy(0,24);
console.print(msg);
console.cleartoeol();
if (! reposition) {
console.popxy();
}
}
this.clearBaseline=function(reposition) {
console.pushxy();
console.gotoxy(0,24);
console.print('');
console.cleartoeol();
if (! reposition) {
console.popxy();
}
}
Object.defineProperty(this,'accessible',{
get: function() {
log(LOG_DEBUG,'- Checking if user can access frame: '+this.page);

View File

@@ -29,19 +29,6 @@ var FRAME_TYPE_RESPONSE ='r'; // Response frame, input fields are embedded in t
// response will be submitted to the Service Provider, or to a method
var FRAME_TYPE_LOGIN ='l'; // Login frame, enables the user to authenticate to the system, or to a CUG
var MSG_SENDORNOT ='\1n\1h\1GKEY 1 TO SEND, 2 NOT TO SEND';
var MSG_LOGON ='\1n\1h\1GKEY 1 TO LOGON, 2 TO RETURN';
var MSG_SENT ='\1n\1h\1GMESSAGE SENT - KEY # TO CONTINUE';
var MSG_NOTSENT ='\1n\1h\1GMESSAGE NOT SENT - KEY # TO CONTINUE';
var ERR_NO_PARENT ='\1n\1h\1RPARENT FRAME DOESNT EXIST';
var ERR_NOT_IMPLEMENTED ='\1n\1h\1RNOT IMPLEMENTED YET?';
var ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
var ERR_METHOD_NOT_EXIST ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
var ACCESS_DENIED ='\1n\1h\1RACCESS DENIED. \1RMISTAKE? TRY AGAIN OR TELL US *08';
var ALREADY_MEMBER ='\1n\1h\1RALREADY MEMBER OF CUG'
var INACTIVITY ='\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...';
var INACTIVE ='\1n\1h\1RINACTIVITY DISCONNECT';
var NO_HISTORY_FRAMES =['980a','98b','981a'];
var SYSTEM_OWNER =9;
var INKEY_TIMEOUT =10000;

View File

@@ -44,14 +44,6 @@ if (!String.prototype.repeat) {
};
}
/**
* Turn off the cursor
*/
function cursorOff() {
ansi.send('ext_mode','clear','cursor');
console.gotoxy(0,24);
}
/**
* Find a message base by code
*
@@ -102,14 +94,14 @@ function getPageOwners() {
if (f.open("r")) {
var logo = f.iniGetValue('prefix','logo');
var users = f.iniGetValue('prefix','user');
log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users));
//log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users));
pageowners.push({prefix: 0,logo: logo,user:users});
f.iniGetSections('prefix:').forEach(function (prefix) {
var p = parseInt(prefix.substr(7));
var logo = f.iniGetValue(prefix,'logo','');
var users = f.iniGetValue(prefix,'user','');
log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users));
//log(LOG_DEBUG,'+ pageOwner: users='+JSON.stringify(users));
pageowners.push({prefix: p,logo: logo,user: users});
});
}
@@ -119,7 +111,7 @@ function getPageOwners() {
// Sort the pageowners ascending
pageowners.sort(compare);
log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners));
//log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners));
}
return pageowners;
@@ -193,7 +185,7 @@ function pageOwner(page) {
if (e !== BreakException) throw e;
}
log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o));
//log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(o));
return o;
}
@@ -236,21 +228,4 @@ function compare(a,b) {
return (a.prefix < b.prefix) ? 1 : ((b.prefix < a.prefix) ? -1 : 0);
}
/**
* Send a message to the baseline.
*
* @param text
* @param reposition
*/
function sendBaseline(text,reposition) {
console.pushxy();
console.gotoxy(0,24);
console.print(text);
console.cleartoeol();
if (! reposition) {
console.popxy();
}
}
this;