* Fix EtherTerm backspace key

* Better WIP apply art / module
* Better WIP 'enter' and 'leave' events from VC
This commit is contained in:
Bryan Ashby 2015-04-14 00:19:14 -06:00
parent b0103cb178
commit 77600d3dde
10 changed files with 150 additions and 60 deletions

View file

@ -14,6 +14,8 @@ var assert = require('assert');
var binary = require('binary');
var miscUtil = require('./misc_util.js');
exports.getFGColorValue = getFGColorValue;
exports.getBGColorValue = getBGColorValue;
exports.sgr = sgr;
exports.clearScreen = clearScreen;
exports.resetScreen = resetScreen;
@ -69,7 +71,7 @@ var CONTROL = {
// Select Graphics Rendition
// See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt
//
var SGR = {
var SGRValues = {
reset : 0,
bold : 1,
dim : 2,
@ -96,11 +98,21 @@ var SGR = {
greenBG : 42,
yellowBG : 43,
blueBG : 44,
magentaBG : 45,
cyanBG : 47,
whiteBG : 47,
};
function getFGColorValue(name) {
return SGRValues[name];
}
function getBGColorValue(name) {
return SGRValues[name + 'BG'];
}
// See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt
// :TODO: document
var SYNC_TERM_FONTS = [
@ -162,8 +174,8 @@ Object.keys(CONTROL).forEach(function onControlName(name) {
});
// Create various color methods such as white(), yellowBG(), reset(), ...
Object.keys(SGR).forEach(function onSgrName(name) {
var code = SGR[name];
Object.keys(SGRValues).forEach(function onSgrName(name) {
var code = SGRValues[name];
exports[name] = function() {
return ESC_CSI + code + 'm';
@ -173,7 +185,7 @@ Object.keys(SGR).forEach(function onSgrName(name) {
function sgr() {
//
// - Allow an single array or variable number of arguments
// - Each element can be either a integer or string found in SGR
// - Each element can be either a integer or string found in SGRValues
// which in turn maps to a integer
//
if(arguments.length <= 0) {
@ -187,11 +199,11 @@ function sgr() {
var args = Array.isArray(arguments[0]) ? arguments[0] : arguments;
for(var i = 0; i < args.length; i++) {
if(typeof args[i] === 'string') {
if(args[i] in SGR) {
if(args[i] in SGRValues) {
if(result.length > 0) {
result += ';';
}
result += SGR[args[i]];
result += SGRValues[args[i]];
}
} else if(typeof args[i] === 'number') {
if(result.length > 0) {

View file

@ -13,7 +13,7 @@ exports.VIEW_SPECIAL_KEY_MAP_DEFAULT = VIEW_SPECIAL_KEY_MAP_DEFAULT;
var VIEW_SPECIAL_KEY_MAP_DEFAULT = {
accept : [ 'enter' ],
exit : [ 'esc' ],
backspace : [ 'backspace' ],
backspace : [ 'backspace', 'del' ],
del : [ 'del' ],
next : [ 'tab' ],
up : [ 'up arrow' ],
@ -89,6 +89,10 @@ View.prototype.setId = function(id) {
this.id = id;
};
View.prototype.getId = function() {
return this.id;
};
View.prototype.setPosition = function(pos) {
//
// We allow [x, y], { x : x, y : y }, or (x, y)
@ -116,18 +120,35 @@ View.prototype.setPosition = function(pos) {
'Y position ' + this.position.y + ' out of terminal range ' + this.client.term.termWidth);
};
View.prototype.setColor = function(fg, bg, flags) {
if(fg) {
this.color.fg = fg;
View.prototype.setColor = function(color, bgColor, flags) {
if(_.isObject(color)) {
assert(_.has(color, 'fg'));
assert(_.has(color, 'bg'));
assert(_.has(color, 'flags'));
this.color = color;
} else {
if(color) {
this.color.fg = color;
}
if(bgColor) {
this.color.bg = bgColor;
}
if(_.isNumber(flags)) {
this.color.flags = flags;
}
}
if(bg) {
this.color.bg = bg;
// allow strings such as 'red', 'black', etc. to be passed
if(_.isString(this.color.fg)) {
this.color.fg = ansi.getFGColorValue(this.color.fg);
}
if('undefined' !== typeof flags) {
this.color.flags = flags;
}
if(_.isString(this.color.bg)) {
this.color.bg = ansi.getBGColorValue(this.color.bg);
}
};
View.prototype.getColor = function() {
@ -147,8 +168,6 @@ View.prototype.setFocus = function(focused) {
this.hasFocus = focused;
this.client.term.write('show' === this.cursor ? ansi.showCursor() : ansi.hideCursor());
this.emit(focused ? 'enter' : 'leave');
};
View.prototype.onKeyPress = function(key, isSpecial) {

View file

@ -15,14 +15,17 @@ var _ = require('lodash');
exports.ViewController = ViewController;
function ViewController(client, formId) {
function ViewController(options) {
assert(_.isObject(options));
assert(_.isObject(options.client));
events.EventEmitter.call(this);
var self = this;
this.client = client;
this.client = options.client;
this.views = {}; // map of ID -> view
this.formId = formId || 0;
this.formId = options.formId || 0;
this.onClientKeyPress = function(key, isSpecial) {
if(isSpecial) {
@ -95,6 +98,16 @@ function ViewController(client, formId) {
self.emit('submit', formData);
};
this.switchFocusEvent = function(event, view) {
if(self.emitSwitchFocus) {
return;
}
self.emitSwitchFocus = true;
self.emit(event, view);
self.emitSwitchFocus = false;
};
this.attachClientEvents();
}
@ -146,16 +159,17 @@ ViewController.prototype.getFocusedView = function() {
ViewController.prototype.switchFocus = function(id) {
if(this.focusedView && this.focusedView.acceptsFocus) {
this.switchFocusEvent('leave', this.focusedView);
this.focusedView.setFocus(false);
}
var view = this.getView(id);
if(view && view.acceptsFocus) {
this.switchFocusEvent('enter', view);
this.focusedView = view;
this.focusedView.setFocus(true);
}
// :TODO: Probably log here
};
ViewController.prototype.nextFocus = function() {
@ -234,7 +248,7 @@ ViewController.prototype.loadFromMCIMapAndConfig = function(options, cb) {
if(err) {
// :TODO: fix logging of err here:
Log.warn(
{ err : err, mci : Object.keys(options.mciMap), formIdKey : formIdKey } ,
{ err : err.toString(), mci : Object.keys(options.mciMap), formIdKey : formIdKey } ,
'Unable to load menu configuration');
}