* Mostly code cleanup & minor refactors

This commit is contained in:
Bryan Ashby 2015-04-27 22:40:05 -06:00
parent cb5fc13da5
commit 99fb3b34c7
6 changed files with 68 additions and 184 deletions

View File

@ -267,96 +267,6 @@ function setCursorStyle(cursorStyle) {
}
/*
var FONT_MAP = {
// Codepage 437 English
'cp437' : 0,
'ibmpc' : 0,
'ibm_pc' : 0,
'ibm_vga' : 0,
'pc' : 0,
'cp437_art' : 0,
'ibmpcart' : 0,
'ibmpc_art' : 0,
'ibm_pc_art' : 0,
'msdos_art' : 0,
'msdosart' : 0,
'pc_art' : 0,
'pcart' : 0,
// Codepage 1251 Cyrillic, (swiss)
'cp1251-swiss' : 1,
// Russian koi8-r
'koi8_r' : 2,
'koi8-r' : 2,
'koi8r' : 2,
// ISO-8859-2 Central European
'iso8859_2' : 3,
'iso8859-2' : 3,
// ISO-8859-4 Baltic wide (VGA 9bit mapped)
'iso8859_4-baltic9b' : 4,
// Codepage 866 (c) Russian
'cp866-c' : 5,
'iso8859_9' : 6,
'haik8' : 7,
'iso8859_8' : 8,
'koi8_u' : 9,
'iso8859_15-thin' : 10,
'iso8859_4' : 11,
'koi8_r_b' : 12,
'iso8859_4-baltic-wide' : 13,
'iso8859_5' : 14,
'ARMSCII_8' : 15,
'iso8859_15' : 16,
'cp850' : 17,
'cp850-thin' : 18,
'cp885-thin' : 19,
'cp1251' : 20,
'iso8859_7' : 21,
'koi8-r_c' : 22,
'iso8859_4-baltic' : 23,
'iso8859_1' : 24,
'cp866' : 25,
'cp437-thin' : 26,
'cp866-b' : 27,
'cp885' : 28,
'cp866_u' : 29,
'iso8859_1-thin' : 30,
'cp1131' : 31,
'c64_upper' : 32,
'c64_lower' : 33,
'c128_upper' : 34,
'c128_lower' : 35,
'atari' : 36,
'atarist' : 36,
'pot_noodle' : 37,
'p0tnoodle' : 37,
'mo_soul' : 38,
'mosoul' : 38,
'mO\'sOul' : 38,
'microknight_plus' : 39,
'topaz_plus' : 40,
'topazplus' : 40,
'amiga_topaz_2+' : 40,
'topaz2plus' : 40,
'microknight' : 41,
'topaz' : 42,
};
*/
// Create methods such as up(), nextLine(),...
Object.keys(CONTROL).forEach(function onControlName(name) {
var code = CONTROL[name];
@ -422,7 +332,7 @@ function clearScreen() {
}
function resetScreen() {
return exports.goHome() + exports.reset() + exports.eraseData(2);
return exports.reset() + exports.eraseData(2) + exports.goHome();
}
function normal() {
@ -440,26 +350,6 @@ function disableVT100LineWrapping() {
return ESC_CSI + '7l';
}
//
// See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt
//
/*
function setFont(name, fontPage) {
name = name.toLowerCase().replace(/ /g, '_'); // conform to map
var p1 = miscUtil.valueWithDefault(fontPage, 0);
assert(p1 >= 0 && p1 <= 3);
var p2 = FONT_MAP[name];
if(_.isNumber(p2)) {
return ESC_CSI + p1 + ';' + p2 + ' D';
}
return '';
}
*/
// Also add:
// * fromRenegade(): |<0-23>
// * fromCelerity(): |<case sensitive letter>

View File

@ -100,8 +100,6 @@ function Client(input, output) {
var c;
var name;
console.log(data)
if(1 === len) {
c = data[0];

View File

@ -42,7 +42,6 @@ function TextView(options) {
// |ABCDEFG| ^_ this.text.length
// ^-- this.dimens.width
//
console.log(this.position.x)
var textToDraw = _.isString(this.textMaskChar) ?
new Array(s.length + 1).join(this.textMaskChar) :
strUtil.stylizeString(s, this.hasFocus ? this.focusTextStyle : this.textStyle);

View File

@ -7,6 +7,7 @@ var menuUtil = require('./menu_util.js');
var Log = require('./logger.js').log;
var Config = require('./config.js').config;
var asset = require('./asset.js');
var ansi = require('./ansi_term.js');
var events = require('events');
var util = require('util');
@ -160,65 +161,55 @@ function ViewController(options) {
});
};
// :TODO: move this elsewhere
this.setViewPropertiesFromMCIConf = function(view, conf) {
function getViewProp(propName) {
function setViewProp(propName, setter) {
if(conf[propName]) {
return asset.resolveConfigAsset(conf[propName]);
}
}
function setSimpleViewProp(propName) {
var propValue = getViewProp(propName);
var propValue = asset.resolveConfigAsset(conf[propName]);
if(propValue) {
if(setter) {
setter(propValue);
} else {
view[propName] = propValue;
}
}
var value;
value = getViewProp('items');
if(value) {
view.setItems(value);
}
}
value = getViewProp('text');
if(value) {
view.setText(value);
setViewProp('items', function(v) { view.setItems(v); });
setViewProp('text', function(v) { view.setText(v); });
setViewProp('textStyle');
setViewProp('focusTextStyle');
setViewProp('maxLength');
setViewProp('width', function(v) { view.dimens.width = parseInt(v, 10); });
setViewProp('fillChar', function(v) {
if(_.isNumber(v)) {
view.fillChar = String.fromCharCode(v);
} else if(_.isString(v)) {
view.fillChar = v.substr(0, 1);
}
});
setSimpleViewProp('textStyle');
setSimpleViewProp('focusTextStyle');
setSimpleViewProp('fillChar');
setSimpleViewProp('maxLength');
value = getViewProp('textMaskChar');
if(_.isString(value)) {
view.textMaskChar = value.substr(0, 1);
} else if(value && true === value) {
//
// Option that should normally be used in order to
// get the password character from Config/theme
//
setViewProp('password', function(v) {
if(true === v) {
view.textMaskChar = self.client.currentThemeInfo.getPasswordChar();
}
});
value = getViewProp('hotkeys');
if(_.isObject(value)) {
view.setHotKeys(value);
}
setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); });
setViewProp('hotKeys', function(v) { view.setHotKeys(v); });
value = getViewProp('submit');
if(_.isBoolean(value)) {
view.submit = value;
setViewProp('submit', function(v) {
if(_.isBoolean(v)) {
view.submit = v;
} else {
view.submit = _.isArray(value) && value.length > 0;
view.submit = _.isArray(v) && v.length > 0;
}
});
if(_.isString(conf.argName)) {
view.submitArgName = conf.argName;
}
setViewProp('argName', function(v) { view.submitArgName = v; });
};
this.applyViewConfig = function(config, cb) {
@ -372,24 +363,6 @@ ViewController.prototype.setViewOrder = function(order) {
}
};
/*
ViewController.prototype.loadFromMCIMap = function(mciMap) {
var factory = new MCIViewFactory(this.client);
var self = this;
Object.keys(mciMap).forEach(function onMciEntry(name) {
var mci = mciMap[name];
var view = factory.createFromMCI(mci);
if(view) {
view.on('action', self.viewActionListener);
self.addView(view);
view.redraw(); // :TODO: This can result in double redraw() if we set focus on this item after
}
});
};
*/
ViewController.prototype.loadFromPromptConfig = function(options, cb) {
assert(_.isObject(options));
assert(_.isObject(options.mciMap));
@ -422,6 +395,8 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) {
callback(null);
},
function drawAllViews(callback) {
self.client.term.write(ansi.hideCursor());
for(var id in self.views) {
if(initialFocusId === id) {
continue; // will draw @ focus
@ -557,6 +532,8 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
callback(null);
},
function drawAllViews(callback) {
self.client.term.write(ansi.hideCursor());
for(var id in self.views) {
if(initialFocusId === id) {
continue; // will draw @ focus

Binary file not shown.

View File

@ -204,19 +204,29 @@
"options" : { "cls" : true },
"form" : {
"0" : {
"BT4ET1ET2ET3" : {
"BT5ET1ET2ET3ET4" : {
"mci" : {
"ET1" : {
"width" : 20,
"maxLength" : 20
},
"ET2" : {
"maxLength" : 20
"width" : 20,
"maxLength" : 40
},
"ET3" : {
"fillChar" : " ",
"width" : 20,
"fillChar" : "-",
// :TODO: fillColor
"maxLength" : 20
},
"BT4" : {
"ET4" : {
"width" : 20,
"maxLength" : 20,
"password" : true
},
"BT5" : {
"width" : 8,
"text" : "Back",
"submit" : true
}
@ -234,6 +244,16 @@
}
}
/*
:TODO: conceptual simplified menus -- actions/etc. without forms
"thing" : {
"mci" : {
"ET1" : {
"action" : "@menu:stuff"
}
}
}
*/
/*
"demoEditTextView" : {
"art" : "demo_edit_text_view.ans",
"options" : { "cls" : true },