2014-10-23 05:41:00 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const TextView = require('./text_view.js').TextView;
|
|
|
|
const EditTextView = require('./edit_text_view.js').EditTextView;
|
|
|
|
const ButtonView = require('./button_view.js').ButtonView;
|
|
|
|
const VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
|
|
|
const HorizontalMenuView = require('./horizontal_menu_view.js').HorizontalMenuView;
|
|
|
|
const SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView;
|
|
|
|
const ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView;
|
|
|
|
const MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView;
|
|
|
|
const KeyEntryView = require('./key_entry_view.js');
|
|
|
|
const MultiLineEditTextView = require('./multi_line_edit_text_view.js').MultiLineEditTextView;
|
|
|
|
const getPredefinedMCIValue = require('./predefined_mci.js').getPredefinedMCIValue;
|
|
|
|
const ansi = require('./ansi_term.js');
|
|
|
|
|
|
|
|
// deps
|
|
|
|
const assert = require('assert');
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
exports.MCIViewFactory = MCIViewFactory;
|
2014-10-23 05:41:00 +00:00
|
|
|
|
|
|
|
function MCIViewFactory(client) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.client = client;
|
2014-10-23 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 00:50:40 +00:00
|
|
|
MCIViewFactory.UserViewCodes = [
|
2018-06-22 05:15:04 +00:00
|
|
|
'TL', 'ET', 'ME', 'MT', 'PL', 'BT', 'VM', 'HM', 'SM', 'TM', 'KE',
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// XY is a special MCI code that allows finding positions
|
|
|
|
// and counts for key lookup, but does not explicitly
|
|
|
|
// represent a visible View on it's own
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
'XY',
|
2015-08-20 00:50:40 +00:00
|
|
|
];
|
|
|
|
|
2018-01-15 19:22:11 +00:00
|
|
|
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
2018-06-22 05:15:04 +00:00
|
|
|
assert(mci.code);
|
|
|
|
assert(mci.id > 0);
|
|
|
|
assert(mci.position);
|
|
|
|
|
|
|
|
var view;
|
|
|
|
var options = {
|
2018-06-23 03:26:46 +00:00
|
|
|
client : this.client,
|
|
|
|
id : mci.id,
|
|
|
|
ansiSGR : mci.SGR,
|
|
|
|
ansiFocusSGR : mci.focusSGR,
|
|
|
|
position : { row : mci.position[0], col : mci.position[1] },
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: These should use setPropertyValue()!
|
2018-06-22 05:15:04 +00:00
|
|
|
function setOption(pos, name) {
|
|
|
|
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
|
|
|
options[name] = mci.args[pos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setWidth(pos) {
|
|
|
|
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
|
|
|
if(!_.isObject(options.dimens)) {
|
|
|
|
options.dimens = {};
|
|
|
|
}
|
|
|
|
options.dimens.width = parseInt(mci.args[pos], 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFocusOption(pos, name) {
|
|
|
|
if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) {
|
|
|
|
options[name] = mci.focusArgs[pos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Note: Keep this in sync with UserViewCodes above!
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
switch(mci.code) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// Text Label (Text View)
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'TL' :
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setOption(1, 'justify');
|
2018-06-22 05:15:04 +00:00
|
|
|
setWidth(2);
|
|
|
|
|
|
|
|
view = new TextView(options);
|
|
|
|
break;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Edit Text
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'ET' :
|
|
|
|
setWidth(0);
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
view = new EditTextView(options);
|
|
|
|
break;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Masked Edit Text
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'ME' :
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
view = new MaskEditTextView(options);
|
|
|
|
break;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Multi Line Edit Text
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'MT' :
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: apply params
|
2018-06-22 05:15:04 +00:00
|
|
|
view = new MultiLineEditTextView(options);
|
|
|
|
break;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Pre-defined Label (Text View)
|
|
|
|
// :TODO: Currently no real point of PL -- @method replaces this pretty much... probably remove
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'PL' :
|
|
|
|
if(mci.args.length > 0) {
|
|
|
|
options.text = getPredefinedMCIValue(this.client, mci.args[0]);
|
|
|
|
if(options.text) {
|
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setOption(2, 'justify');
|
|
|
|
setWidth(3);
|
|
|
|
|
|
|
|
view = new TextView(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Button
|
2018-06-22 05:15:04 +00:00
|
|
|
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;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Vertial Menu
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'VM' :
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(0, 'itemSpacing');
|
|
|
|
setOption(1, 'justify');
|
|
|
|
setOption(2, 'textStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
view = new VerticalMenuView(options);
|
|
|
|
break;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Horizontal Menu
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'HM' :
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(0, 'itemSpacing');
|
|
|
|
setOption(1, 'textStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
view = new HorizontalMenuView(options);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'SM' :
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setOption(1, 'justify');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2015-04-27 22:04:41 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
view = new ToggleMenuView(options);
|
|
|
|
break;
|
2015-04-27 22:04:41 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
case 'KE' :
|
|
|
|
view = new KeyEntryView(options);
|
|
|
|
break;
|
2015-07-23 03:35:35 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
default :
|
|
|
|
options.text = getPredefinedMCIValue(this.client, mci.code);
|
|
|
|
if(_.isString(options.text)) {
|
|
|
|
setWidth(0);
|
2015-07-23 03:35:35 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setOption(2, 'justify');
|
2016-07-21 04:11:57 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
view = new TextView(options);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-10-23 05:41:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(view) {
|
|
|
|
view.mciCode = mci.code;
|
|
|
|
}
|
2018-02-01 05:38:02 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return view;
|
2014-10-23 05:41:00 +00:00
|
|
|
};
|