First pass formatting with Prettier
* Added .prettierrc.json * Added .prettierignore * Formatted
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
const MenuView = require('./menu_view.js').MenuView;
|
||||
const strUtil = require('./string_util.js');
|
||||
const MenuView = require('./menu_view.js').MenuView;
|
||||
const strUtil = require('./string_util.js');
|
||||
|
||||
const util = require('util');
|
||||
const assert = require('assert');
|
||||
const util = require('util');
|
||||
const assert = require('assert');
|
||||
|
||||
exports.ToggleMenuView = ToggleMenuView;
|
||||
exports.ToggleMenuView = ToggleMenuView;
|
||||
|
||||
function ToggleMenuView (options) {
|
||||
function ToggleMenuView(options) {
|
||||
options.cursor = options.cursor || 'hide';
|
||||
|
||||
MenuView.call(this, options);
|
||||
@@ -24,7 +24,7 @@ function ToggleMenuView (options) {
|
||||
};
|
||||
*/
|
||||
|
||||
this.updateSelection = function() {
|
||||
this.updateSelection = function () {
|
||||
assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length);
|
||||
self.redraw();
|
||||
};
|
||||
@@ -32,10 +32,10 @@ function ToggleMenuView (options) {
|
||||
|
||||
util.inherits(ToggleMenuView, MenuView);
|
||||
|
||||
ToggleMenuView.prototype.redraw = function() {
|
||||
ToggleMenuView.prototype.redraw = function () {
|
||||
ToggleMenuView.super_.prototype.redraw.call(this);
|
||||
|
||||
if(0 === this.items.length) {
|
||||
if (0 === this.items.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,12 +45,16 @@ ToggleMenuView.prototype.redraw = function() {
|
||||
|
||||
assert(this.items.length === 2, 'ToggleMenuView must contain exactly (2) items');
|
||||
|
||||
for(var i = 0; i < 2; i++) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var item = this.items[i];
|
||||
var text = strUtil.stylizeString(
|
||||
item.text, i === this.focusedItemIndex && this.hasFocus ? this.focusTextStyle : this.textStyle);
|
||||
item.text,
|
||||
i === this.focusedItemIndex && this.hasFocus
|
||||
? this.focusTextStyle
|
||||
: this.textStyle
|
||||
);
|
||||
|
||||
if(1 === i) {
|
||||
if (1 === i) {
|
||||
//console.log(this.styleColor1)
|
||||
//var sepColor = this.getANSIColor(this.styleColor1 || this.getColor());
|
||||
//console.log(sepColor.substr(1))
|
||||
@@ -60,25 +64,27 @@ ToggleMenuView.prototype.redraw = function() {
|
||||
//this.client.term.write(sepColor + ' / ');
|
||||
}
|
||||
|
||||
this.client.term.write(i === this.focusedItemIndex ? this.getFocusSGR() : this.getSGR());
|
||||
this.client.term.write(
|
||||
i === this.focusedItemIndex ? this.getFocusSGR() : this.getSGR()
|
||||
);
|
||||
this.client.term.write(text);
|
||||
}
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.setFocusItemIndex = function(index) {
|
||||
ToggleMenuView.super_.prototype.setFocusItemIndex.call(this, index); // sets this.focusedItemIndex
|
||||
ToggleMenuView.prototype.setFocusItemIndex = function (index) {
|
||||
ToggleMenuView.super_.prototype.setFocusItemIndex.call(this, index); // sets this.focusedItemIndex
|
||||
|
||||
this.updateSelection();
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.setFocus = function(focused) {
|
||||
ToggleMenuView.prototype.setFocus = function (focused) {
|
||||
ToggleMenuView.super_.prototype.setFocus.call(this, focused);
|
||||
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.focusNext = function() {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
ToggleMenuView.prototype.focusNext = function () {
|
||||
if (this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
} else {
|
||||
this.focusedItemIndex++;
|
||||
@@ -89,9 +95,8 @@ ToggleMenuView.prototype.focusNext = function() {
|
||||
ToggleMenuView.super_.prototype.focusNext.call(this);
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.focusPrevious = function() {
|
||||
|
||||
if(0 === this.focusedItemIndex) {
|
||||
ToggleMenuView.prototype.focusPrevious = function () {
|
||||
if (0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
} else {
|
||||
this.focusedItemIndex--;
|
||||
@@ -102,12 +107,14 @@ ToggleMenuView.prototype.focusPrevious = function() {
|
||||
ToggleMenuView.super_.prototype.focusPrevious.call(this);
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.onKeyPress = function(ch, key) {
|
||||
|
||||
if(key) {
|
||||
if(this.isKeyMapped('right', key.name) || this.isKeyMapped('down', key.name)) {
|
||||
ToggleMenuView.prototype.onKeyPress = function (ch, key) {
|
||||
if (key) {
|
||||
if (this.isKeyMapped('right', key.name) || this.isKeyMapped('down', key.name)) {
|
||||
this.focusNext();
|
||||
} else if(this.isKeyMapped('left', key.name) || this.isKeyMapped('up', key.name)) {
|
||||
} else if (
|
||||
this.isKeyMapped('left', key.name) ||
|
||||
this.isKeyMapped('up', key.name)
|
||||
) {
|
||||
this.focusPrevious();
|
||||
}
|
||||
}
|
||||
@@ -115,14 +122,14 @@ ToggleMenuView.prototype.onKeyPress = function(ch, key) {
|
||||
ToggleMenuView.super_.prototype.onKeyPress.call(this, ch, key);
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.getData = function() {
|
||||
ToggleMenuView.prototype.getData = function () {
|
||||
return this.focusedItemIndex;
|
||||
};
|
||||
|
||||
ToggleMenuView.prototype.setItems = function(items) {
|
||||
items = items.slice(0, 2); // switch/toggle only works with two elements
|
||||
ToggleMenuView.prototype.setItems = function (items) {
|
||||
items = items.slice(0, 2); // switch/toggle only works with two elements
|
||||
|
||||
ToggleMenuView.super_.prototype.setItems.call(this, items);
|
||||
|
||||
this.dimens.width = items.join(' / ').length; // :TODO: allow configurable seperator... string & color, e.g. styleColor1 (same as fillChar color)
|
||||
this.dimens.width = items.join(' / ').length; // :TODO: allow configurable seperator... string & color, e.g. styleColor1 (same as fillChar color)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user