enigma-bbs/core/menu_view.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

/* jslint node: true */
'use strict';
var View = require('./view.js').View;
var ansi = require('./ansi_term.js');
var miscUtil = require('./misc_util.js');
var util = require('util');
var assert = require('assert');
exports.MenuView = MenuView;
function MenuView(client, options) {
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
2014-11-01 15:50:11 +00:00
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
View.call(this, client, options);
2014-11-01 15:50:11 +00:00
var self = this;
//// --- TESTING
options.items = [ 'Login', 'Apply', 'Logout' ];
//options.itemSpacing = 2;
//// --- TESTING
this.items = [];
if(this.options.items) {
this.options.items.forEach(function onItem(itemText) {
self.items.push({
text : itemText,
selected : false,
});
});
}
2014-11-01 15:50:11 +00:00
this.focusedItemIndex = this.options.focusedItemIndex || 0;
this.focusedItemIndex = this.items.length >= this.focusedItemIndex ? this.focusedItemIndex : 0;
this.itemSpacing = this.options.itemSpacing || 1;
this.itemSpacing = parseInt(this.itemSpacing, 10);
this.focusPrefix = this.options.focusPrefix || '';
this.focusSuffix = this.options.focusSuffix || '';
}
util.inherits(MenuView, View);