more refactoring of helpers.

This commit is contained in:
Christopher Jeffrey 2015-05-01 00:32:44 -07:00
parent 8eb57e919e
commit 3e8083d5a1

View File

@ -564,7 +564,7 @@ Screen.prototype._listenMouse = function(el) {
if (self.lockKeys) return; if (self.lockKeys) return;
if (self._needsClickableSort) { if (self._needsClickableSort) {
self.clickable = hsort(self.clickable); self.clickable = helpers.hsort(self.clickable);
self._needsClickableSort = false; self._needsClickableSort = false;
} }
@ -6540,8 +6540,8 @@ FileManager.prototype.refresh = function(cwd, callback) {
} }
}); });
dirs = asort(dirs); dirs = helpers.asort(dirs);
files = asort(files); files = helpers.asort(files);
list = dirs.concat(files).map(function(data) { list = dirs.concat(files).map(function(data) {
return data.text; return data.text;
@ -7306,7 +7306,7 @@ Listbar.prototype.appendItem = function(item, callback) {
cmd.prefix = cmd.keys[0]; cmd.prefix = cmd.keys[0];
} }
var t = generateTags(this.style.prefix || { fg: 'lightblack' }); var t = helpers.generateTags(this.style.prefix || { fg: 'lightblack' });
title = (cmd.prefix != null ? t.open + cmd.prefix + t.close + ':' : '') + cmd.text; title = (cmd.prefix != null ? t.open + cmd.prefix + t.close + ':' : '') + cmd.text;
@ -7323,7 +7323,7 @@ Listbar.prototype.appendItem = function(item, callback) {
autoFocus: false, autoFocus: false,
tags: true, tags: true,
mouse: true, mouse: true,
style: merge({}, this.style.item), style: helpers.merge({}, this.style.item),
noOverflow: true noOverflow: true
}; };
@ -8483,9 +8483,9 @@ function Image(options) {
if (fs.existsSync(Image.w3mdisplay)) { if (fs.existsSync(Image.w3mdisplay)) {
Image.hasW3MDisplay = true; Image.hasW3MDisplay = true;
} else if (options.search !== false) { } else if (options.search !== false) {
var file = findFile('/usr', 'w3mimgdisplay') var file = helpers.findFile('/usr', 'w3mimgdisplay')
|| findFile('/lib', 'w3mimgdisplay') || helpers.findFile('/lib', 'w3mimgdisplay')
|| findFile('/bin', 'w3mimgdisplay'); || helpers.findFile('/bin', 'w3mimgdisplay');
if (file) { if (file) {
Image.hasW3MDisplay = true; Image.hasW3MDisplay = true;
Image.w3mdisplay = file; Image.w3mdisplay = file;
@ -9049,12 +9049,13 @@ function blend(attr, attr2) {
blend._cache = {}; blend._cache = {};
/** /**
* Helpers * Helpers
*/ */
function generateTags(style, text) { var helpers = {};
helpers.generateTags = function(style, text) {
var open = '' var open = ''
, close = ''; , close = '';
@ -9080,16 +9081,16 @@ function generateTags(style, text) {
open: open, open: open,
close: close close: close
}; };
} };
function merge(a, b) { helpers.merge = function(a, b) {
Object.keys(b).forEach(function(key) { Object.keys(b).forEach(function(key) {
a[key] = b[key]; a[key] = b[key];
}); });
return a; return a;
} };
function asort(obj) { helpers.asort = function(obj) {
return obj.sort(function(a, b) { return obj.sort(function(a, b) {
a = a.name.toLowerCase(); a = a.name.toLowerCase();
b = b.name.toLowerCase(); b = b.name.toLowerCase();
@ -9104,15 +9105,15 @@ function asort(obj) {
return a > b ? 1 : (a < b ? -1 : 0); return a > b ? 1 : (a < b ? -1 : 0);
}); });
} };
function hsort(obj) { helpers.hsort = function(obj) {
return obj.sort(function(a, b) { return obj.sort(function(a, b) {
return b.index - a.index; return b.index - a.index;
}); });
} };
function findFile(start, target) { helpers.findFile = function(start, target) {
return (function read(dir) { return (function read(dir) {
var files, file, stat, out; var files, file, stat, out;
@ -9148,13 +9149,7 @@ function findFile(start, target) {
return null; return null;
})(start); })(start);
} };
/**
* Helpers
*/
var helpers = {};
// Escape text for tag-enabled elements. // Escape text for tag-enabled elements.
helpers.escape = function(text) { helpers.escape = function(text) {
@ -9168,8 +9163,6 @@ helpers.parseTags = function(text) {
{ parseTags: true, screen: Screen.global }, text); { parseTags: true, screen: Screen.global }, text);
}; };
helpers.generateTags = generateTags;
helpers.attrToBinary = function(style, element) { helpers.attrToBinary = function(style, element) {
return Element.prototype.sattr.call(element || {}, style); return Element.prototype.sattr.call(element || {}, style);
}; };
@ -9193,10 +9186,6 @@ helpers.dropUnicode = function(text) {
.replace(unicode.chars.surrogate, '?'); .replace(unicode.chars.surrogate, '?');
}; };
helpers.merge = merge;
helpers.asort = asort;
helpers.findFile = findFile;
/** /**
* Expose * Expose
*/ */