mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-22 18:56:00 +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; }
|
||||||
|
};
|
|
@ -1,23 +1,24 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var TextView = require('./text_view.js').TextView;
|
// ENiGMA½
|
||||||
var EditTextView = require('./edit_text_view.js').EditTextView;
|
const TextView = require('./text_view.js').TextView;
|
||||||
var ButtonView = require('./button_view.js').ButtonView;
|
const EditTextView = require('./edit_text_view.js').EditTextView;
|
||||||
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
const ButtonView = require('./button_view.js').ButtonView;
|
||||||
var HorizontalMenuView = require('./horizontal_menu_view.js').HorizontalMenuView;
|
const VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
||||||
var SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView;
|
const HorizontalMenuView = require('./horizontal_menu_view.js').HorizontalMenuView;
|
||||||
var ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView;
|
const SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView;
|
||||||
var MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView;
|
const ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView;
|
||||||
var StatusBarView = require('./status_bar_view.js').StatusBarView;
|
const MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView;
|
||||||
var MultiLineEditTextView = require('./multi_line_edit_text_view.js').MultiLineEditTextView;
|
//const StatusBarView = require('./status_bar_view.js').StatusBarView;
|
||||||
var getPredefinedMCIValue = require('./predefined_mci.js').getPredefinedMCIValue;
|
const KeyEntryView = require('./key_entry_view.js');
|
||||||
var ansi = require('./ansi_term.js');
|
const MultiLineEditTextView = require('./multi_line_edit_text_view.js').MultiLineEditTextView;
|
||||||
|
const getPredefinedMCIValue = require('./predefined_mci.js').getPredefinedMCIValue;
|
||||||
|
const ansi = require('./ansi_term.js');
|
||||||
|
|
||||||
var packageJson = require('../package.json');
|
// deps
|
||||||
|
const assert = require('assert');
|
||||||
var assert = require('assert');
|
const _ = require('lodash');
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
exports.MCIViewFactory = MCIViewFactory;
|
exports.MCIViewFactory = MCIViewFactory;
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ function MCIViewFactory(client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MCIViewFactory.UserViewCodes = [
|
MCIViewFactory.UserViewCodes = [
|
||||||
'TL', 'ET', 'ME', 'MT', 'PL', 'BT', 'VM', 'HM', 'SM', 'TM',
|
'TL', 'ET', 'ME', 'MT', 'PL', 'BT', 'VM', 'HM', 'SM', 'TM', 'KE',
|
||||||
|
|
||||||
//
|
//
|
||||||
// XY is a special MCI code that allows finding positions
|
// XY is a special MCI code that allows finding positions
|
||||||
|
@ -77,122 +78,126 @@ MCIViewFactory.prototype.createFromMCI = function(mci, cb) {
|
||||||
//
|
//
|
||||||
switch(mci.code) {
|
switch(mci.code) {
|
||||||
// Text Label (Text View)
|
// Text Label (Text View)
|
||||||
case 'TL' :
|
case 'TL' :
|
||||||
setOption(0, 'textStyle');
|
setOption(0, 'textStyle');
|
||||||
setOption(1, 'justify');
|
setOption(1, 'justify');
|
||||||
setWidth(2);
|
setWidth(2);
|
||||||
|
|
||||||
view = new TextView(options);
|
view = new TextView(options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Edit Text
|
// Edit Text
|
||||||
case 'ET' :
|
case 'ET' :
|
||||||
setWidth(0);
|
setWidth(0);
|
||||||
|
|
||||||
setOption(1, 'textStyle');
|
setOption(1, 'textStyle');
|
||||||
setFocusOption(0, 'focusTextStyle');
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
view = new EditTextView(options);
|
view = new EditTextView(options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Masked Edit Text
|
// Masked Edit Text
|
||||||
case 'ME' :
|
case 'ME' :
|
||||||
setOption(0, 'textStyle');
|
setOption(0, 'textStyle');
|
||||||
setFocusOption(0, 'focusTextStyle');
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
view = new MaskEditTextView(options);
|
view = new MaskEditTextView(options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Multi Line Edit Text
|
// Multi Line Edit Text
|
||||||
case 'MT' :
|
case 'MT' :
|
||||||
// :TODO: apply params
|
// :TODO: apply params
|
||||||
view = new MultiLineEditTextView(options);
|
view = new MultiLineEditTextView(options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Pre-defined Label (Text View)
|
// Pre-defined Label (Text View)
|
||||||
// :TODO: Currently no real point of PL -- @method replaces this pretty much... probably remove
|
// :TODO: Currently no real point of PL -- @method replaces this pretty much... probably remove
|
||||||
case 'PL' :
|
case 'PL' :
|
||||||
if(mci.args.length > 0) {
|
if(mci.args.length > 0) {
|
||||||
options.text = getPredefinedMCIValue(this.client, mci.args[0]);
|
options.text = getPredefinedMCIValue(this.client, mci.args[0]);
|
||||||
if(options.text) {
|
if(options.text) {
|
||||||
setOption(1, 'textStyle');
|
setOption(1, 'textStyle');
|
||||||
setOption(2, 'justify');
|
setOption(2, 'justify');
|
||||||
setWidth(3);
|
setWidth(3);
|
||||||
|
|
||||||
view = new TextView(options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Button
|
|
||||||
case 'BT' :
|
|
||||||
if(mci.args.length > 0) {
|
|
||||||
options.dimens = { width : parseInt(mci.args[0], 10) };
|
|
||||||
}
|
|
||||||
|
|
||||||
setOption(1, 'textStyle');
|
|
||||||
setOption(2, 'justify');
|
|
||||||
|
|
||||||
setFocusOption(0, 'focusTextStyle');
|
|
||||||
|
|
||||||
view = new ButtonView(options);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Vertial Menu
|
|
||||||
case 'VM' :
|
|
||||||
setOption(0, 'itemSpacing');
|
|
||||||
setOption(1, 'justify');
|
|
||||||
setOption(2, 'textStyle');
|
|
||||||
|
|
||||||
setFocusOption(0, 'focusTextStyle');
|
|
||||||
|
|
||||||
view = new VerticalMenuView(options);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Horizontal Menu
|
|
||||||
case 'HM' :
|
|
||||||
setOption(0, 'itemSpacing');
|
|
||||||
setOption(1, 'textStyle');
|
|
||||||
|
|
||||||
setFocusOption(0, 'focusTextStyle');
|
|
||||||
|
|
||||||
view = new HorizontalMenuView(options);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'SM' :
|
|
||||||
setOption(0, 'textStyle');
|
|
||||||
setOption(1, 'justify');
|
|
||||||
|
|
||||||
setFocusOption(0, 'focusTextStyle');
|
|
||||||
|
|
||||||
view = new SpinnerMenuView(options);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'TM' :
|
|
||||||
if(mci.args.length > 0) {
|
|
||||||
var styleSG1 = { fg : parseInt(mci.args[0], 10) };
|
|
||||||
if(mci.args.length > 1) {
|
|
||||||
styleSG1.bg = parseInt(mci.args[1], 10);
|
|
||||||
}
|
|
||||||
options.styleSG1 = ansi.getSGRFromGraphicRendition(styleSG1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
setFocusOption(0, 'focusTextStyle');
|
|
||||||
|
|
||||||
view = new ToggleMenuView(options);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default :
|
|
||||||
options.text = getPredefinedMCIValue(this.client, mci.code);
|
|
||||||
if(_.isString(options.text)) {
|
|
||||||
setWidth(0);
|
|
||||||
|
|
||||||
setOption(1, 'textStyle');
|
|
||||||
setOption(2, 'justify');
|
|
||||||
|
|
||||||
view = new TextView(options);
|
view = new TextView(options);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Button
|
||||||
|
case 'BT' :
|
||||||
|
if(mci.args.length > 0) {
|
||||||
|
options.dimens = { width : parseInt(mci.args[0], 10) };
|
||||||
|
}
|
||||||
|
|
||||||
|
setOption(1, 'textStyle');
|
||||||
|
setOption(2, 'justify');
|
||||||
|
|
||||||
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
|
view = new ButtonView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Vertial Menu
|
||||||
|
case 'VM' :
|
||||||
|
setOption(0, 'itemSpacing');
|
||||||
|
setOption(1, 'justify');
|
||||||
|
setOption(2, 'textStyle');
|
||||||
|
|
||||||
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
|
view = new VerticalMenuView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Horizontal Menu
|
||||||
|
case 'HM' :
|
||||||
|
setOption(0, 'itemSpacing');
|
||||||
|
setOption(1, 'textStyle');
|
||||||
|
|
||||||
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
|
view = new HorizontalMenuView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'SM' :
|
||||||
|
setOption(0, 'textStyle');
|
||||||
|
setOption(1, 'justify');
|
||||||
|
|
||||||
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
|
view = new SpinnerMenuView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'TM' :
|
||||||
|
if(mci.args.length > 0) {
|
||||||
|
var styleSG1 = { fg : parseInt(mci.args[0], 10) };
|
||||||
|
if(mci.args.length > 1) {
|
||||||
|
styleSG1.bg = parseInt(mci.args[1], 10);
|
||||||
|
}
|
||||||
|
options.styleSG1 = ansi.getSGRFromGraphicRendition(styleSG1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
|
view = new ToggleMenuView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'KE' :
|
||||||
|
view = new KeyEntryView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
options.text = getPredefinedMCIValue(this.client, mci.code);
|
||||||
|
if(_.isString(options.text)) {
|
||||||
|
setWidth(0);
|
||||||
|
|
||||||
|
setOption(1, 'textStyle');
|
||||||
|
setOption(2, 'justify');
|
||||||
|
|
||||||
|
view = new TextView(options);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue