2014-10-23 05:41:00 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2015-05-16 20:39:14 +00:00
|
|
|
var TextView = require('./text_view.js').TextView;
|
|
|
|
var EditTextView = require('./edit_text_view.js').EditTextView;
|
|
|
|
var ButtonView = require('./button_view.js').ButtonView;
|
|
|
|
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
|
|
|
var SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView;
|
|
|
|
var ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView;
|
|
|
|
var MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView;
|
|
|
|
var MultiLineEditTextView = require('./multi_line_edit_text_view.js').MultiLineEditTextView;
|
|
|
|
|
|
|
|
var Config = require('./config.js').config;
|
|
|
|
var ansi = require('./ansi_term.js');
|
|
|
|
|
|
|
|
var packageJson = require('../package.json');
|
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
var os = require('os');
|
|
|
|
var _ = require('lodash');
|
2014-10-23 05:41:00 +00:00
|
|
|
|
|
|
|
exports.MCIViewFactory = MCIViewFactory;
|
|
|
|
|
|
|
|
function MCIViewFactory(client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
|
2014-10-28 03:58:34 +00:00
|
|
|
|
2015-05-15 05:01:00 +00:00
|
|
|
return {
|
|
|
|
BN : Config.general.boardName,
|
|
|
|
VL : 'ENiGMA½ v' + packageJson.version,
|
|
|
|
VN : packageJson.version,
|
|
|
|
|
|
|
|
UN : this.client.user.username,
|
|
|
|
UI : this.client.user.userId,
|
|
|
|
UG : _.values(this.client.user.groups).join(', '),
|
|
|
|
UR : this.client.user.properties.real_name,
|
|
|
|
LO : this.client.user.properties.location,
|
|
|
|
UA : this.client.user.properties.age,
|
|
|
|
US : this.client.user.properties.sex,
|
|
|
|
UE : this.client.user.properties.email_address,
|
|
|
|
UW : this.client.user.properties.web_address,
|
|
|
|
UF : this.client.user.properties.affiliation,
|
|
|
|
UT : this.client.user.properties.theme_id,
|
|
|
|
|
|
|
|
OS : {
|
|
|
|
linux : 'Linux',
|
|
|
|
darwin : 'Mac OS X',
|
|
|
|
win32 : 'Windows',
|
|
|
|
sunos : 'SunOS',
|
|
|
|
freebsd : 'FreeBSD',
|
|
|
|
}[os.platform()] || os.type(),
|
|
|
|
|
|
|
|
OA : os.arch(),
|
|
|
|
SC : os.cpus()[0].model,
|
|
|
|
|
|
|
|
IP : this.client.address().address,
|
|
|
|
}[code];
|
2014-10-28 03:58:34 +00:00
|
|
|
};
|
|
|
|
|
2014-10-23 05:41:00 +00:00
|
|
|
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|
|
|
assert(mci.code);
|
|
|
|
assert(mci.id > 0);
|
|
|
|
assert(mci.position);
|
|
|
|
|
|
|
|
var view;
|
|
|
|
var options = {
|
2015-04-30 20:39:03 +00:00
|
|
|
client : this.client,
|
|
|
|
id : mci.id,
|
|
|
|
ansiSGR : mci.SGR,
|
|
|
|
ansiFocusSGR : mci.focusSGR,
|
2015-05-18 17:31:35 +00:00
|
|
|
position : { row : mci.position[0], col : mci.position[1] },
|
2014-10-23 05:41:00 +00:00
|
|
|
};
|
|
|
|
|
2014-10-31 22:25:11 +00:00
|
|
|
function setOption(pos, name) {
|
|
|
|
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
|
|
|
options[name] = mci.args[pos];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-27 02:46:16 +00:00
|
|
|
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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
function setFocusOption(pos, name) {
|
|
|
|
if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) {
|
|
|
|
options[name] = mci.focusArgs[pos];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:41:00 +00:00
|
|
|
switch(mci.code) {
|
2015-04-16 04:46:45 +00:00
|
|
|
// Text Label (Text View)
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'TL' :
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setOption(1, 'justify');
|
2015-04-27 02:46:16 +00:00
|
|
|
setWidth(2);
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new TextView(options);
|
2014-10-28 03:58:34 +00:00
|
|
|
break;
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Edit Text
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'ET' :
|
2015-04-27 02:46:16 +00:00
|
|
|
setWidth(0);
|
2014-10-23 05:41:00 +00:00
|
|
|
|
2015-04-27 02:46:16 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2014-11-03 23:49:15 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new EditTextView(options);
|
2014-10-23 05:41:00 +00:00
|
|
|
break;
|
2014-10-24 04:18:38 +00:00
|
|
|
|
2015-05-15 05:01:00 +00:00
|
|
|
// Masked Edit Text
|
|
|
|
case 'ME' :
|
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
|
|
|
|
|
|
|
view = new MaskEditTextView(options);
|
|
|
|
break;
|
|
|
|
|
2015-05-16 20:39:14 +00:00
|
|
|
// Multi Line Edit Text
|
|
|
|
case 'MT' :
|
|
|
|
// :TODO: apply params
|
|
|
|
view = new MultiLineEditTextView(options);
|
|
|
|
break;
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Pre-defined Label (Text View)
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'PL' :
|
|
|
|
if(mci.args.length > 0) {
|
|
|
|
options.text = this.getPredefinedViewLabel(mci.args[0]);
|
|
|
|
if(options.text) {
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setOption(2, 'justify');
|
2015-04-27 02:46:16 +00:00
|
|
|
setWidth(3);
|
2014-10-28 03:58:34 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new TextView(options);
|
2014-10-28 03:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Button
|
|
|
|
case 'BT' :
|
2014-10-24 04:18:38 +00:00
|
|
|
if(mci.args.length > 0) {
|
2014-11-03 23:49:15 +00:00
|
|
|
options.dimens = { width : parseInt(mci.args[0], 10) };
|
2014-10-24 04:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setOption(2, 'justify');
|
|
|
|
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new ButtonView(options);
|
2014-10-24 04:18:38 +00:00
|
|
|
break;
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Vertial Menu
|
2014-10-31 22:25:11 +00:00
|
|
|
case 'VM' :
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(0, 'itemSpacing');
|
|
|
|
setOption(1, 'justify');
|
|
|
|
setOption(2, 'textStyle');
|
|
|
|
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new VerticalMenuView(options);
|
2014-10-31 22:25:11 +00:00
|
|
|
break;
|
2015-04-16 04:46:45 +00:00
|
|
|
|
2015-04-27 03:57:23 +00:00
|
|
|
case 'SM' :
|
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setOption(1, 'justify');
|
|
|
|
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
|
|
|
|
|
|
|
view = new SpinnerMenuView(options);
|
|
|
|
break;
|
|
|
|
|
2015-04-27 22:04:41 +00:00
|
|
|
case 'TM' :
|
2015-04-29 04:42:22 +00:00
|
|
|
if(mci.args.length > 0) {
|
2015-04-30 22:41:43 +00:00
|
|
|
var styleSG1 = { fg : parseInt(mci.args[0], 10) };
|
2015-04-29 04:42:22 +00:00
|
|
|
if(mci.args.length > 1) {
|
2015-04-30 22:41:43 +00:00
|
|
|
styleSG1.bg = parseInt(mci.args[1], 10);
|
2015-04-29 04:42:22 +00:00
|
|
|
}
|
2015-04-30 22:41:43 +00:00
|
|
|
options.styleSG1 = ansi.getSGRFromGraphicRendition(styleSG1, true);
|
2015-04-29 04:42:22 +00:00
|
|
|
}
|
2015-04-27 22:04:41 +00:00
|
|
|
|
2015-04-29 04:42:22 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2015-04-27 22:04:41 +00:00
|
|
|
|
|
|
|
view = new ToggleMenuView(options);
|
|
|
|
break;
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
default :
|
|
|
|
options.text = this.getPredefinedViewLabel(mci.code);
|
|
|
|
if(options.text) {
|
|
|
|
view = new TextView(options);
|
|
|
|
}
|
|
|
|
break;
|
2014-10-23 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
};
|