* Most everything converted to new 'key press' system. Still WIP, some cleanup & probably a few keys to add for various BBS style terminals

This commit is contained in:
Bryan Ashby 2015-06-05 16:20:26 -06:00
parent dd0568f207
commit 8a17ca694e
13 changed files with 329 additions and 189 deletions

View File

@ -458,6 +458,7 @@ function display(options, cb) {
parser.on('row update', function rowUpdate(row) { parser.on('row update', function rowUpdate(row) {
if(row >= nextPauseTermHeight) { if(row >= nextPauseTermHeight) {
if(!continous && 'termHeight' === options.pause) { if(!continous && 'termHeight' === options.pause) {
// :TODO: Must use new key type (ch, key)
options.client.waitForKeyPress(function kp(k) { options.client.waitForKeyPress(function kp(k) {
// :TODO: Allow for configurable key(s) here; or none // :TODO: Allow for configurable key(s) here; or none
if('C' === k || 'c' == k) { if('C' === k || 'c' == k) {

View File

@ -110,8 +110,7 @@ function getIntArgArray(array) {
return array; return array;
} }
var RE_DSR_RESPONSE = /(?:\u001b\[)([0-9\;]+)([R])/; var RE_DSR_RESPONSE_ANYWHERE = /(?:\u001b\[)([0-9\;]+)([R])/;
var RE_META_KEYCODE_ANYWHERE = /(?:\u001b)([a-zA-Z0-9])/; var RE_META_KEYCODE_ANYWHERE = /(?:\u001b)([a-zA-Z0-9])/;
var RE_META_KEYCODE = new RegExp('^' + RE_META_KEYCODE_ANYWHERE.source + '$'); var RE_META_KEYCODE = new RegExp('^' + RE_META_KEYCODE_ANYWHERE.source + '$');
var RE_FUNCTION_KEYCODE_ANYWHERE = new RegExp('(?:\u001b+)(O|N|\\[|\\[\\[)(?:' + [ var RE_FUNCTION_KEYCODE_ANYWHERE = new RegExp('(?:\u001b+)(O|N|\\[|\\[\\[)(?:' + [
@ -124,11 +123,21 @@ var RE_FUNCTION_KEYCODE = new RegExp('^' + RE_FUNCTION_KEYCODE_ANYWHERE.sourc
var RE_ESC_CODE_ANYWHERE = new RegExp( [ var RE_ESC_CODE_ANYWHERE = new RegExp( [
RE_FUNCTION_KEYCODE_ANYWHERE.source, RE_FUNCTION_KEYCODE_ANYWHERE.source,
RE_META_KEYCODE_ANYWHERE.source, RE_META_KEYCODE_ANYWHERE.source,
RE_DSR_RESPONSE.source, RE_DSR_RESPONSE_ANYWHERE.source,
/\u001b./.source /\u001b./.source
].join('|')); ].join('|'));
/*
Convert names to eg 'ctrl-x', 'shift-x',...
https://github.com/chjj/blessed/blob/master/lib/program.js
Look at blessed DSR stuff, etc
Also cursor shape
Key filtering here: https://github.com/chjj/blessed/blob/master/lib/widgets/textarea.js
*/
function Client(input, output) { function Client(input, output) {
stream.call(this); stream.call(this);
@ -149,11 +158,8 @@ function Client(input, output) {
// //
// References: // References:
// * http://www.ansi-bbs.org/ansi-bbs-core-server.html // * http://www.ansi-bbs.org/ansi-bbs-core-server.html
// * Christopher Jeffrey's Blessed library @ https://github.com/chjj/blessed/
// //
// Implementation inspired from Christopher Jeffrey's Blessing library:
// https://github.com/chjj/blessed/blob/master/lib/keys.js
//
// :TODO: this is a WIP v2 of onData()
this.isMouseInput = function(data) { this.isMouseInput = function(data) {
return /\x1b\[M/.test(data) || return /\x1b\[M/.test(data) ||
/\u001b\[M([\x00\u0020-\uffff]{3})/.test(data) || /\u001b\[M([\x00\u0020-\uffff]{3})/.test(data) ||
@ -257,13 +263,15 @@ function Client(input, output) {
'[7^' : { name : 'home', ctrl : true }, '[7^' : { name : 'home', ctrl : true },
'[8^' : { name : 'end', ctrl : true }, '[8^' : { name : 'end', ctrl : true },
// SyncTERM
'[K' : { name : 'end' },
// other // other
'[Z' : { name : 'tab', shift : true }, '[Z' : { name : 'tab', shift : true },
}[code]; }[code];
}; };
this.on('data', function clientData(data) { this.on('data', function clientData(data) {
// create a uniform format that can be parsed below // create a uniform format that can be parsed below
if(data[0] > 127 && undefined === data[1]) { if(data[0] > 127 && undefined === data[1]) {
data[0] -= 128; data[0] -= 128;
@ -297,7 +305,7 @@ function Client(input, output) {
var parts; var parts;
if((parts = RE_DSR_RESPONSE.exec(s))) { if((parts = RE_DSR_RESPONSE_ANYWHERE.exec(s))) {
if('R' === parts[2]) { if('R' === parts[2]) {
var cprArgs = getIntArgArray(parts[1].split(';')); var cprArgs = getIntArgArray(parts[1].split(';'));
if(2 === cprArgs.length) { if(2 === cprArgs.length) {
@ -360,6 +368,15 @@ function Client(input, output) {
if(_.isUndefined(key.name)) { if(_.isUndefined(key.name)) {
key = undefined; key = undefined;
} else {
//
// Adjust name for CTRL/Shift/Meta modifiers
//
key.name =
(key.ctrl ? 'ctrl + ' : '') +
(key.meta ? 'meta + ' : '') +
(key.shift ? 'shift + ' : '') +
key.name;
} }
if(key || ch) { if(key || ch) {
@ -470,8 +487,8 @@ Client.prototype.destroySoon = function () {
}; };
Client.prototype.waitForKeyPress = function(cb) { Client.prototype.waitForKeyPress = function(cb) {
this.once('key press', function onKeyPress(kp) { this.once('key press', function kp(ch, key) {
cb(kp); cb(ch, key);
}); });
}; };

View File

@ -30,6 +30,57 @@ function EditTextView(options) {
require('util').inherits(EditTextView, TextView); require('util').inherits(EditTextView, TextView);
EditTextView.prototype.onKeyPress = function(ch, key) {
if(key) {
if(this.isSpecialKeyMapped('backspace', key.name)) {
if(this.text.length > 0) {
this.text = this.text.substr(0, this.text.length - 1);
if(this.text.length >= this.dimens.width) {
this.redraw();
} else {
this.cursorPos.row -= 1;
if(this.cursorPos.row >= 0) {
this.clientBackspace();
}
}
}
return;
} else if(this.isSpecialKeyMapped('clearLine', key.name)) {
this.text = '';
this.cursorPos.row = 0;
this.setFocus(true); // resetting focus will redraw & adjust cursor
return;
}
}
if(ch && strUtil.isPrintable(ch)) {
if(this.text.length < this.maxLength) {
ch = strUtil.stylizeString(ch, this.textStyle);
this.text += ch;
if(this.text.length > this.dimens.width) {
// no shortcuts - redraw the view
this.redraw();
} else {
this.cursorPos.row += 1;
if(this.textMaskChar) {
this.client.term.write(this.textMaskChar);
} else {
this.client.term.write(ch);
}
}
}
}
EditTextView.super_.prototype.onKeyPress.call(this, ch, key);
};
/*
EditTextView.prototype.onKeyPress = function(key, isSpecial) { EditTextView.prototype.onKeyPress = function(key, isSpecial) {
if(isSpecial) { if(isSpecial) {
return; return;
@ -82,3 +133,4 @@ EditTextView.prototype.onSpecialKeyPress = function(keyName) {
EditTextView.super_.prototype.onSpecialKeyPress.call(this, keyName); EditTextView.super_.prototype.onSpecialKeyPress.call(this, keyName);
}; };
*/

View File

@ -104,39 +104,9 @@ MaskEditTextView.prototype.setMaskPattern = function(pattern) {
this.buildPattern(); this.buildPattern();
}; };
MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) { MaskEditTextView.prototype.onKeyPress = function(ch, key) {
if(isSpecial) { if(key) {
return; if(this.isSpecialKeyMapped('backspace', key.name)) {
}
assert(1 === key.length);
if(this.text.length < this.maxLength) {
key = strUtil.stylizeString(key, this.textStyle);
if(!key.match(this.patternArray[this.patternArrayPos])) {
return;
}
this.text += key;
this.patternArrayPos++;
while(this.patternArrayPos < this.patternArray.length &&
!_.isRegExp(this.patternArray[this.patternArrayPos]))
{
this.patternArrayPos++;
}
this.redraw();
this.client.term.write(ansi.goto(this.position.row, this.getEndOfTextColumn()));
}
MaskEditTextView.super_.prototype.onKeyPress.call(this, key, isSpecial);
};
MaskEditTextView.prototype.onSpecialKeyPress = function(keyName) {
if(this.isSpecialKeyMapped('backspace', keyName)) {
if(this.text.length > 0) { if(this.text.length > 0) {
this.patternArrayPos--; this.patternArrayPos--;
assert(this.patternArrayPos >= 0); assert(this.patternArrayPos >= 0);
@ -156,11 +126,38 @@ MaskEditTextView.prototype.onSpecialKeyPress = function(keyName) {
} }
} }
} }
} else if(this.isSpecialKeyMapped('clearLine', keyName)) {
return;
} else if(this.isSpecialKeyMapped('clearLine', key.name)) {
this.text = ''; this.text = '';
this.patternArrayPos = 0; this.patternArrayPos = 0;
this.setFocus(true); // redraw + adjust cursor this.setFocus(true); // redraw + adjust cursor
return;
}
} }
MaskEditTextView.super_.prototype.onSpecialKeyPress.call(this, keyName); if(ch && strUtil.isPrintable(ch)) {
if(this.text.length < this.maxLength) {
ch = strUtil.stylizeString(ch, this.textStyle);
if(!ch.match(this.patternArray[this.patternArrayPos])) {
return;
}
this.text += ch;
this.patternArrayPos++;
while(this.patternArrayPos < this.patternArray.length &&
!_.isRegExp(this.patternArray[this.patternArrayPos]))
{
this.patternArrayPos++;
}
this.redraw();
this.client.term.write(ansi.goto(this.position.row, this.getEndOfTextColumn()));
}
}
MaskEditTextView.super_.prototype.onKeyPress.call(this, ch, key);
}; };

View File

@ -10,6 +10,24 @@ var ansi = require('./ansi_term.js');
var assert = require('assert'); var assert = require('assert');
var _ = require('lodash'); var _ = require('lodash');
// :TODO: Determine CTRL-* keys for various things
// See http://www.bbsdocumentary.com/library/PROGRAMS/GRAPHICS/ANSI/bansi.txt
// http://wiki.synchro.net/howto:editor:slyedit#edit_mode
// http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/keyboard_shortcuts_win.html
/* Mystic
[^B] Reformat Paragraph [^O] Show this help file
[^I] Insert tab space [^Q] Enter quote mode
[^K] Cut current line of text [^V] Toggle insert/overwrite
[^U] Paste previously cut text [^Y] Delete current line
BASIC MOVEMENT COMMANDS
UP/^E LEFT/^S PGUP/^R HOME/^F
DOWN/^X RIGHT/^D PGDN/^C END/^G
*/
var SPECIAL_KEY_MAP_DEFAULT = { var SPECIAL_KEY_MAP_DEFAULT = {
lineFeed : [ 'return' ], lineFeed : [ 'return' ],
exit : [ 'esc' ], exit : [ 'esc' ],
@ -22,7 +40,7 @@ var SPECIAL_KEY_MAP_DEFAULT = {
home : [ 'home' ], home : [ 'home' ],
left : [ 'left arrow' ], left : [ 'left arrow' ],
right : [ 'right arrow' ], right : [ 'right arrow' ],
clearLine : [ 'end of medium' ], clearLine : [ 'ctrl + y' ],
pageUp : [ 'page up' ], pageUp : [ 'page up' ],
pageDown : [ 'page down' ], pageDown : [ 'page down' ],
}; };
@ -416,6 +434,36 @@ MultiLineEditTextView2.prototype.setText = function(text) {
this.overtypeMode = true; // :TODO: remove... testing this.overtypeMode = true; // :TODO: remove... testing
}; };
var HANDLED_SPECIAL_KEYS = [
'up', 'down', 'left', 'right',
'home', 'end',
'pageUp', 'pageDown',
'lineFeed',
];
MultiLineEditTextView2.prototype.onKeyPress = function(ch, key) {
var self = this;
var handled;
if(key) {
HANDLED_SPECIAL_KEYS.forEach(function aKey(specialKey) {
if(self.isSpecialKeyMapped(specialKey, key.name)) {
self[_.camelCase('keyPress ' + specialKey)]();
handled = true;
}
});
}
if(ch && strUtil.isPrintable(ch)) {
this.keyPressCharacter(ch);
}
if(!handled) {
MultiLineEditTextView2.super_.prototype.onSpecialKeyPress.call(this, key.name);
}
};
/*
MultiLineEditTextView2.prototype.onKeyPress = function(key, isSpecial) { MultiLineEditTextView2.prototype.onKeyPress = function(key, isSpecial) {
if(isSpecial) { if(isSpecial) {
return; return;
@ -426,12 +474,7 @@ MultiLineEditTextView2.prototype.onKeyPress = function(key, isSpecial) {
MultiLineEditTextView2.super_.prototype.onKeyPress.call(this, key, isSpecial); MultiLineEditTextView2.super_.prototype.onKeyPress.call(this, key, isSpecial);
}; };
var HANDLED_SPECIAL_KEYS = [
'up', 'down', 'left', 'right',
'home', 'end',
'pageUp', 'pageDown',
'lineFeed',
];
MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) { MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) {
@ -439,23 +482,7 @@ MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) {
console.log(keyName); console.log(keyName);
// :TODO: Determine CTRL-* keys for various things
// See http://www.bbsdocumentary.com/library/PROGRAMS/GRAPHICS/ANSI/bansi.txt
// http://wiki.synchro.net/howto:editor:slyedit#edit_mode
// http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/keyboard_shortcuts_win.html
/* Mystic
[^B] Reformat Paragraph [^O] Show this help file
[^I] Insert tab space [^Q] Enter quote mode
[^K] Cut current line of text [^V] Toggle insert/overwrite
[^U] Paste previously cut text [^Y] Delete current line
BASIC MOVEMENT COMMANDS
UP/^E LEFT/^S PGUP/^R HOME/^F
DOWN/^X RIGHT/^D PGDN/^C END/^G
*/
var handled = false; var handled = false;
HANDLED_SPECIAL_KEYS.forEach(function key(arrowKey) { HANDLED_SPECIAL_KEYS.forEach(function key(arrowKey) {
if(self.isSpecialKeyMapped(arrowKey, keyName)) { if(self.isSpecialKeyMapped(arrowKey, keyName)) {
@ -468,3 +495,4 @@ MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) {
MultiLineEditTextView2.super_.prototype.onSpecialKeyPress.call(this, keyName); MultiLineEditTextView2.super_.prototype.onSpecialKeyPress.call(this, keyName);
} }
}; };
*/

View File

@ -62,25 +62,30 @@ SpinnerMenuView.prototype.setFocus = function(focused) {
this.redraw(); this.redraw();
}; };
SpinnerMenuView.prototype.onSpecialKeyPress = function(keyName) { SpinnerMenuView.prototype.onKeyPress = function(ch, key) {
if(key) {
if(this.isSpecialKeyMapped('up', keyName)) { if(this.isSpecialKeyMapped('up', key.name)) {
if(0 === this.focusedItemIndex) { if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1; this.focusedItemIndex = this.items.length - 1;
} else { } else {
this.focusedItemIndex--; this.focusedItemIndex--;
} }
} else if(this.isSpecialKeyMapped('down', keyName)) {
this.updateSelection();
return;
} else if(this.isSpecialKeyMapped('down', key.name)) {
if(this.items.length - 1 === this.focusedItemIndex) { if(this.items.length - 1 === this.focusedItemIndex) {
this.focusedItemIndex = 0; this.focusedItemIndex = 0;
} else { } else {
this.focusedItemIndex++; this.focusedItemIndex++;
} }
}
this.updateSelection(); this.updateSelection();
return;
}
}
SpinnerMenuView.super_.prototype.onSpecialKeyPress.call(this, keyName); SpinnerMenuView.super_.prototype.onKeyPress.call(this, ch, key);
}; };
SpinnerMenuView.prototype.getData = function() { SpinnerMenuView.prototype.getData = function() {

View File

@ -7,6 +7,7 @@ var miscUtil = require('./misc_util.js');
exports.stylizeString = stylizeString; exports.stylizeString = stylizeString;
exports.pad = pad; exports.pad = pad;
exports.replaceAt = replaceAt; exports.replaceAt = replaceAt;
exports.isPrintable = isPrintable;
// :TODO: create Unicode verison of this // :TODO: create Unicode verison of this
var VOWELS = [ 'a', 'e', 'i', 'o', 'u' ]; var VOWELS = [ 'a', 'e', 'i', 'o', 'u' ];
@ -150,3 +151,21 @@ function pad(s, len, padChar, dir, stringSGR, padSGR) {
function replaceAt(s, n, t) { function replaceAt(s, n, t) {
return s.substring(0, n) + t + s.substring(n + 1); return s.substring(0, n) + t + s.substring(n + 1);
} }
var RE_NON_PRINTABLE = /[\0-\x1F\x7F-\x9F\xAD\u0378\u0379\u037F-\u0383\u038B\u038D\u03A2\u0528-\u0530\u0557\u0558\u0560\u0588\u058B-\u058E\u0590\u05C8-\u05CF\u05EB-\u05EF\u05F5-\u0605\u061C\u061D\u06DD\u070E\u070F\u074B\u074C\u07B2-\u07BF\u07FB-\u07FF\u082E\u082F\u083F\u085C\u085D\u085F-\u089F\u08A1\u08AD-\u08E3\u08FF\u0978\u0980\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FC-\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B55\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0C00\u0C04\u0C0D\u0C11\u0C29\u0C34\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5A-\u0C5F\u0C64\u0C65\u0C70-\u0C77\u0C80\u0C81\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0D01\u0D04\u0D0D\u0D11\u0D3B\u0D3C\u0D45\u0D49\u0D4F-\u0D56\u0D58-\u0D5F\u0D64\u0D65\u0D76-\u0D78\u0D80\u0D81\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E86\u0E89\u0E8B\u0E8C\u0E8E-\u0E93\u0E98\u0EA0\u0EA4\u0EA6\u0EA8\u0EA9\u0EAC\u0EBA\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F5-\u13FF\u169D-\u169F\u16F1-\u16FF\u170D\u1715-\u171F\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u180F\u181A-\u181F\u1878-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191D-\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE-\u1AFF\u1B4C-\u1B4F\u1B7D-\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C80-\u1CBF\u1CC8-\u1CCF\u1CF7-\u1CFF\u1DE7-\u1DFB\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u200B-\u200F\u202A-\u202E\u2060-\u206F\u2072\u2073\u208F\u209D-\u209F\u20BB-\u20CF\u20F1-\u20FF\u218A-\u218F\u23F4-\u23FF\u2427-\u243F\u244B-\u245F\u2700\u2B4D-\u2B4F\u2B5A-\u2BFF\u2C2F\u2C5F\u2CF4-\u2CF8\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D71-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E3C-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3040\u3097\u3098\u3100-\u3104\u312E-\u3130\u318F\u31BB-\u31BF\u31E4-\u31EF\u321F\u32FF\u4DB6-\u4DBF\u9FCD-\u9FFF\uA48D-\uA48F\uA4C7-\uA4CF\uA62C-\uA63F\uA698-\uA69E\uA6F8-\uA6FF\uA78F\uA794-\uA79F\uA7AB-\uA7F7\uA82C-\uA82F\uA83A-\uA83F\uA878-\uA87F\uA8C5-\uA8CD\uA8DA-\uA8DF\uA8FC-\uA8FF\uA954-\uA95E\uA97D-\uA97F\uA9CE\uA9DA-\uA9DD\uA9E0-\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A\uAA5B\uAA7C-\uAA7F\uAAC3-\uAADA\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F-\uABBF\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBC2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFE\uFDFF\uFE1A-\uFE1F\uFE27-\uFE2F\uFE53\uFE67\uFE6C-\uFE6F\uFE75\uFEFD-\uFF00\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]/;
function isPrintable(s) {
//
// See the following:
// https://mathiasbynens.be/notes/javascript-unicode
// http://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript
// http://stackoverflow.com/questions/12052825/regular-expression-for-all-printable-characters-in-javascript
//
// :TODO: Probably need somthing better here.
return !RE_NON_PRINTABLE.test(s);
}
function stringLength(s) {
// :TODO: See https://mathiasbynens.be/notes/javascript-unicode
return s.length;
}

View File

@ -66,41 +66,40 @@ ToggleMenuView.prototype.setFocus = function(focused) {
this.redraw(); this.redraw();
}; };
ToggleMenuView.prototype.onKeyPress = function(key, isSpecial) { ToggleMenuView.prototype.onKeyPress = function(ch, key) {
if(isSpecial || !this.hotKeys) { if(key) {
return; var needsUpdate;
} if(this.isSpecialKeyMapped('right', key.name) || this.isSpecialKeyMapped('down', key.name)) {
assert(1 === key.length);
var keyIndex = this.hotKeys[this.caseInsensitiveHotKeys ? key.toLowerCase() : key];
if(!_.isUndefined(keyIndex)) {
this.focusedItemIndex = keyIndex;
this.updateSelection();
}
ToggleMenuView.super_.prototype.onKeyPress.call(this, key, isSpecial);
};
ToggleMenuView.prototype.onSpecialKeyPress = function(keyName) {
if(this.isSpecialKeyMapped('right', keyName) || this.isSpecialKeyMapped('down', keyName)) {
if(this.items.length - 1 === this.focusedItemIndex) { if(this.items.length - 1 === this.focusedItemIndex) {
this.focusedItemIndex = 0; this.focusedItemIndex = 0;
} else { } else {
this.focusedItemIndex++; this.focusedItemIndex++;
} }
} else if(this.isSpecialKeyMapped('left', keyName) || this.isSpecialKeyMapped('up', keyName)) { needsUpdate = true;
} else if(this.isSpecialKeyMapped('left', key.name) || this.isSpecialKeyMapped('up', key.name)) {
if(0 === this.focusedItemIndex) { if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1; this.focusedItemIndex = this.items.length - 1;
} else { } else {
this.focusedItemIndex--; this.focusedItemIndex--;
} }
needsUpdate = true;
} }
if(needsUpdate) {
this.updateSelection(); this.updateSelection();
return;
}
}
ToggleMenuView.super_.prototype.onSpecialKeyPress.call(this, keyName); if(ch && this.hotKeys) {
var keyIndex = this.hotKeys[this.caseInsensitiveHotKeys ? ch.toLowerCase() : ch];
if(!_.isUndefined(keyIndex)) {
this.focusedItemIndex = keyIndex;
this.updateSelection();
}
}
ToggleMenuView.super_.prototype.onKeyPress.call(this, ch, key);
}; };
ToggleMenuView.prototype.getData = function() { ToggleMenuView.prototype.getData = function() {

View File

@ -81,11 +81,12 @@ VerticalMenuView.prototype.setFocus = function(focused) {
this.redraw(); this.redraw();
}; };
VerticalMenuView.prototype.onSpecialKeyPress = function(keyName) { VerticalMenuView.prototype.onKeyPress = function(ch, key) {
if(key) {
var prevFocusedItemIndex = this.focusedItemIndex; var prevFocusedItemIndex = this.focusedItemIndex;
if(this.isSpecialKeyMapped('up', keyName)) { if(this.isSpecialKeyMapped('up', key.name)) {
if(0 === this.focusedItemIndex) { if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1; this.focusedItemIndex = this.items.length - 1;
@ -101,7 +102,7 @@ VerticalMenuView.prototype.onSpecialKeyPress = function(keyName) {
this.viewWindow.bottom--; this.viewWindow.bottom--;
} }
} }
} else if(this.isSpecialKeyMapped('down', keyName)) { } else if(this.isSpecialKeyMapped('down', key.name)) {
if(this.items.length - 1 === this.focusedItemIndex) { if(this.items.length - 1 === this.focusedItemIndex) {
this.focusedItemIndex = 0; this.focusedItemIndex = 0;
@ -122,8 +123,9 @@ VerticalMenuView.prototype.onSpecialKeyPress = function(keyName) {
if(prevFocusedItemIndex !== this.focusedItemIndex) { if(prevFocusedItemIndex !== this.focusedItemIndex) {
this.redraw(); this.redraw();
} }
}
VerticalMenuView.super_.prototype.onSpecialKeyPress.call(this, keyName); VerticalMenuView.super_.prototype.onKeyPress.call(this, ch, key);
}; };
VerticalMenuView.prototype.getData = function() { VerticalMenuView.prototype.getData = function() {

View File

@ -22,7 +22,7 @@ var VIEW_SPECIAL_KEY_MAP_DEFAULT = {
home : [ 'home' ], home : [ 'home' ],
left : [ 'left arrow' ], left : [ 'left arrow' ],
right : [ 'right arrow' ], right : [ 'right arrow' ],
clearLine : [ 'end of medium' ], clearLine : [ 'ctrl + y' ],
}; };
function View(options) { function View(options) {
@ -177,7 +177,7 @@ View.prototype.setFocus = function(focused) {
this.hasFocus = focused; this.hasFocus = focused;
this.restoreCursor(); this.restoreCursor();
}; };
/*
View.prototype.onKeyPress = function(key, isSpecial) { View.prototype.onKeyPress = function(key, isSpecial) {
assert(this.hasFocus, 'View does not have focus'); assert(this.hasFocus, 'View does not have focus');
assert(this.acceptsInput, 'View does not accept input'); assert(this.acceptsInput, 'View does not accept input');
@ -195,6 +195,26 @@ View.prototype.onSpecialKeyPress = function(keyName) {
this.emit('action', 'next'); this.emit('action', 'next');
} }
}; };
*/
View.prototype.onKeyPress = function(ch, key) {
assert(this.hasFocus, 'View does not have focus');
assert(this.acceptsInput, 'View does not accept input');
if(key) {
assert(this.specialKeyMap, 'No special key map defined');
if(this.isSpecialKeyMapped('accept', key.name)) {
this.emit('action', 'accept');
} else if(this.isSpecialKeyMapped('next', key.name)) {
this.emit('action', 'next');
}
}
if(ch) {
assert(1 === ch.length);
}
};
View.prototype.getData = function() { View.prototype.getData = function() {
}; };

View File

@ -35,26 +35,25 @@ function ViewController(options) {
this.mciViewFactory = new MCIViewFactory(this.client); this.mciViewFactory = new MCIViewFactory(this.client);
this.submitKeyMap = {}; this.submitKeyMap = {};
this.clientKeyPressHandler = function(ch, specialKey) { this.clientKeyPressHandler = function(ch, key) {
console.log('ch=' + ch + ' / ' + JSON.stringify(specialKey)); //
// :TODO: pass actual key object along here // Process key presses treating form submit mapped
if(specialKey) { // keys special. Everything else is forwarded on to
var submitViewId = self.submitKeyMap[specialKey.name]; // the focused View, if any. //
console.log('ch=' + ch + ' / ' + JSON.stringify(key));
if(key) {
var submitViewId = self.submitKeyMap[key.name];
if(submitViewId) { if(submitViewId) {
self.switchFocus(submitViewId); self.switchFocus(submitViewId);
self.submitForm(); self.submitForm();
} else { return;
// :TODO: pass actual key here
if(self.focusedView && self.focusedView.acceptsInput) {
self.focusedView.onSpecialKeyPress(specialKey.name);
} }
} }
} else {
assert(_.isString(ch));
if(self.focusedView && self.focusedView.acceptsInput) { if(self.focusedView && self.focusedView.acceptsInput) {
self.focusedView.onKeyPress(ch); self.focusedView.onKeyPress(ch, key);
}
} }
}; };
@ -223,6 +222,7 @@ function ViewController(options) {
// styleSGRx: 1..25 // styleSGRx: 1..25
// //
for(var i = 1; i <= 25; i++) { for(var i = 1; i <= 25; i++) {
// :TODO: fix function in loop
setViewProp('styleSGR' + i, function(v) { setViewProp('styleSGR' + i, function(v) {
if(_.isObject(v)) { if(_.isObject(v)) {
view['styleSGR' + i] = ansi.getSGRFromGraphicRendition(v, true); view['styleSGR' + i] = ansi.getSGRFromGraphicRendition(v, true);

View File

@ -313,7 +313,7 @@
"TM3" : { "TM3" : {
"items" : [ "Yarly", "Nowaii" ], "items" : [ "Yarly", "Nowaii" ],
"styleSGR1" : "|00|30|01", "styleSGR1" : "|00|30|01",
"hotkeys" : { "Y" : 0, "N" : 1 } "hotKeys" : { "Y" : 0, "N" : 1 }
}, },
"BT8" : { "BT8" : {
"text" : "< Back", "text" : "< Back",