mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 06:34:41 +02:00
+ Initial source checkin
This commit is contained in:
parent
9804c93f2e
commit
9a7e90b9b2
31 changed files with 4361 additions and 0 deletions
64
core/line_editor.js
Normal file
64
core/line_editor.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
"use strict";
|
||||
|
||||
var assert = require('assert');
|
||||
var miscUtil = require('./misc_util.js');
|
||||
|
||||
exports.LineEditor = LineEditor;
|
||||
|
||||
var STANDARD_KEYSET = {
|
||||
refresh : [ 12 ],
|
||||
backspace : [ 8, 127 ],
|
||||
backword : [ 23 ],
|
||||
enter : [ 10 ],
|
||||
exit : [ 27 ],
|
||||
};
|
||||
|
||||
// :TODO: Rename to TextEdit
|
||||
// :TODO: TextEdit should be single or multi line
|
||||
|
||||
|
||||
function LineEditor(client, options) {
|
||||
var self = this;
|
||||
|
||||
self.client = client;
|
||||
self.valueText = '';
|
||||
|
||||
if(typeof options !== 'undefined') {
|
||||
self.options.keyset = miscUtil.valueWithDefault(options.keyset, STANDARD_KEYSET);
|
||||
} else {
|
||||
self.options = {
|
||||
keyset : STANDARD_KEYSET,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
this.client.on('data', function onData(data) {
|
||||
assert(1 === data.length);
|
||||
self.onCh(data);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
LineEditor.prototype.isKey = function(setName, ch) {
|
||||
return this.options.keyset[setName].indexOf(ch) > -1;
|
||||
}
|
||||
|
||||
LineEditor.prototype.onCh = function(ch) {
|
||||
if(this.isKey('refresh', ch)) {
|
||||
|
||||
} else if(this.isKey('backspace', ch)) {
|
||||
|
||||
} else if(this.isKey('backword', ch)) {
|
||||
|
||||
} else if(this.isKey('enter', ch)) {
|
||||
|
||||
} else if(this.isKey('exit', ch)) {
|
||||
|
||||
} else {
|
||||
|
||||
// :TODO: filter out chars
|
||||
// :TODO: check max width
|
||||
this.valueText += ch;
|
||||
this.client.term.write(ch);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue