mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-30 22:46:17 +02:00
Add KeyEntryView (%KE)
This commit is contained in:
parent
8cd07d2af4
commit
9545cb620b
2 changed files with 190 additions and 122 deletions
63
core/key_entry_view.js
Normal file
63
core/key_entry_view.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
const View = require('./view.js').View;
|
||||
const valueWithDefault = require('./misc_util.js').valueWithDefault;
|
||||
const isPrintable = require('./string_util.js').isPrintable;
|
||||
const stylizeString = require('./string_util.js').stylizeString;
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = class KeyEntryView extends View {
|
||||
constructor(options) {
|
||||
options.acceptsFocus = valueWithDefault(options.acceptsFocus, true);
|
||||
options.acceptsInput = valueWithDefault(options.acceptsInput, true);
|
||||
|
||||
super(options);
|
||||
|
||||
this.eatTabKey = options.eatTabKey || true;
|
||||
this.caseInsensitive = options.caseInsensitive || true;
|
||||
|
||||
// :TODO: allow (by default) only supplied keys[] to even draw
|
||||
}
|
||||
|
||||
onKeyPress(ch, key) {
|
||||
if(ch && isPrintable(ch)) {
|
||||
this.redraw(); // sets position
|
||||
this.client.term.write(stylizeString(ch, this.textStyle));
|
||||
}
|
||||
|
||||
if(this.caseInsensitive) {
|
||||
ch = ch.toUpperCase();
|
||||
}
|
||||
|
||||
this.keyEntered = ch || key.name;
|
||||
|
||||
if(key && 'tab' === key.name && !this.eatTabKey) {
|
||||
return this.emit('action', 'next', key);
|
||||
}
|
||||
|
||||
this.emit('action', 'accept');
|
||||
// NOTE: we don't call super here. KeyEntryView is a special snowflake.
|
||||
}
|
||||
|
||||
setPropertyValue(propName, propValue) {
|
||||
switch(propName) {
|
||||
case 'eatTabKey' :
|
||||
if(_.isBoolean(propValue)) {
|
||||
this.eatTabKey = propValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'caseInsensitive' :
|
||||
if(_.isBoolean(propValue)) {
|
||||
this.caseInsensitive = propValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
super.setPropertyValue(propName, propValue);
|
||||
}
|
||||
|
||||
getData() { return this.keyEntered; }
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue