sbbs/load/edit.js
2020-07-26 09:34:45 +10:00

118 lines
2.2 KiB
JavaScript

load('ansiedit.js');
load('frame.js');
load('tree.js');
load('scrollbar.js');
load('event-timer.js');
load('graphic.js');
var CONTROL_EDIT = '1';
function edit(fo) {
log(LOG_DEBUG,'+ Control EDIT loaded');
var complete = false;
Object.defineProperty(this,'getName', {
get: function() {
return 'Frame Edit';
}
});
Object.defineProperty(this,'isComplete', {
get: function() {
return complete;
}
});
log(LOG_DEBUG,' - Owner: '+JSON.stringify(fo.owner));
const frame = new Frame(1,1,console.screen_columns,console.screen_rows,BG_BLACK|LIGHTGRAY);
frame.gotoxy(1,1);
header = '\1n'+fo.pageownerlogo+' '.repeat(FRAME_HEADER-console.strlen(fo.pageownerlogo))+'\1n '+
'\1W\1H'+fo.page+' '.repeat(FRAME_PAGENUM-fo.page.length)+' '+
'\1G\1H'+' Edit';
frame.putmsg(header);
frame.open();
var editor = new ANSIEdit({
x: 1,
y: 2,
width: 80,
height: 23,
attr: WHITE,
//showPosition: true,
menuHeading: 'Frame Edit '+fo.page,
parentFrame: frame,
});
editor.open();
editor.menu.addItem('Properties',properties);
editor.menu.addItem('Exit',onexit);
editor.menu.addItem('Save & Exit',saveexit);
var x = new Graphic;
x.ANSI = fo.parse(base64_decode(fo.content));
log(LOG_DEBUG,' - Fields: '+JSON.stringify(fo.frame_fields));
const bin = x.BIN;
var o = 0; // offset into 'bin'
for (var yy = 0; yy < 22; yy++) {
for (var xx = 0; xx < 80; xx++) {
editor.putChar({
x : xx,
y : yy,
ch : bin.substr(o, 1),
attr : bin.substr(o + 1, 1).charCodeAt(0) || BG_BLACK
});
o = o + 2;
}
}
editor.cycle();
frame.cycle();
this.handle=function(read) {
if (! js.terminated && ascii(read) != 27) {
editor.getcmd(read);
editor.cycle();
frame.cycle();
if (! complete)
return '';
// Ignore esc
} else if (ascii(read) == 27) {
return '';
}
editor.close();
frame.close();
console.clear(LIGHTGRAY);
console.putmsg(fo.render());
return '';
}
function properties() {
log(LOG_DEBUG, '+ FrameEdit properties()');
}
function save() {
fo.content = base64_encode(editor.exportAnsi().join(''));
fo.save();
}
function onexit() {
complete = true;
}
function saveexit() {
save();
onexit();
}
}
this;