Better fillChar handling, specialKeyMapOverride()

This commit is contained in:
Bryan Ashby 2018-03-04 13:35:36 -07:00
parent e7fb569466
commit cac3e0ceae
1 changed files with 15 additions and 6 deletions

View File

@ -2,11 +2,12 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
const events = require('events'); const events = require('events');
const util = require('util'); const util = require('util');
const ansi = require('./ansi_term.js'); const ansi = require('./ansi_term.js');
const colorCodes = require('./color_codes.js'); const colorCodes = require('./color_codes.js');
const enigAssert = require('./enigma_assert.js'); const enigAssert = require('./enigma_assert.js');
const { renderSubstr } = require('./string_util.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -85,6 +86,10 @@ function View(options) {
if(this.acceptsInput) { if(this.acceptsInput) {
this.specialKeyMap = options.specialKeyMap || VIEW_SPECIAL_KEY_MAP_DEFAULT; this.specialKeyMap = options.specialKeyMap || VIEW_SPECIAL_KEY_MAP_DEFAULT;
if(_.isObject(options.specialKeyMapOverride)) {
this.setSpecialKeyMapOverride(options.specialKeyMapOverride);
}
} }
this.isKeyMapped = function(keySet, keyName) { this.isKeyMapped = function(keySet, keyName) {
@ -177,6 +182,10 @@ View.prototype.getFocusSGR = function() {
return this.ansiFocusSGR; return this.ansiFocusSGR;
}; };
View.prototype.setSpecialKeyMapOverride = function(specialKeyMapOverride) {
this.specialKeyMap = Object.assign(this.specialKeyMap, specialKeyMapOverride);
};
View.prototype.setPropertyValue = function(propName, value) { View.prototype.setPropertyValue = function(propName, value) {
switch(propName) { switch(propName) {
case 'height' : this.setHeight(value); break; case 'height' : this.setHeight(value); break;
@ -199,7 +208,7 @@ View.prototype.setPropertyValue = function(propName, value) {
if(_.isNumber(value)) { if(_.isNumber(value)) {
this.fillChar = String.fromCharCode(value); this.fillChar = String.fromCharCode(value);
} else if(_.isString(value)) { } else if(_.isString(value)) {
this.fillChar = value.substr(0, 1); this.fillChar = renderSubstr(value, 0, 1);
} }
} }
break; break;