From 096869d82e7739bade4fdf52078eebb3c369006d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 24 Apr 2015 01:37:00 -0700 Subject: [PATCH] fix ritems handling. debug. --- lib/widget.js | 34 ++++++++++++++++++---------------- test/widget.js | 3 ++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 2a86d40..5ef443f 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -486,17 +486,12 @@ Screen.prototype.postEnter = function() { top: 'center', width: '30%', height: '30%', - border: 'bg', + border: 'line', label: ' {bold}Debug Log{/bold} ', tags: true, keys: true, vi: true, mouse: true, - style: { - border: { - bg: 'red' - } - }, scrollbar: { ch: ' ', track: { @@ -5382,18 +5377,18 @@ List.prototype.fuzzyFind = function(search, back) { } if (!back) { - for (var i = start; i < this.items.length; i++){ - if (test(this.items[i].getText())) return i; + for (var i = start; i < this.ritems.length; i++){ + if (test(helpers.cleanTags(this.ritems[i]))) return i; } for (var i = 0; i < start; i++){ - if (test(this.items[i].getText())) return i; + if (test(helpers.cleanTags(this.ritems[i]))) return i; } } else { for (var i = start; i >= 0; i--){ - if (test(this.items[i].getText())) return i; + if (test(helpers.cleanTags(this.ritems[i]))) return i; } - for (var i = this.items.length - 1; i > start; i--){ - if (test(this.items[i].getText())) return i; + for (var i = this.ritems.length - 1; i > start; i--){ + if (test(helpers.cleanTags(this.ritems[i]))) return i; } } @@ -5406,8 +5401,8 @@ List.prototype.getItemIndex = function(child) { } else if (typeof child === 'string') { var i = this.ritems.indexOf(child); if (~i) return i; - for (i = 0; i < this.items.length; i++) { - if (this.items[i].getText() === child) { + for (i = 0; i < this.ritems.length; i++) { + if (helpers.cleanTags(this.ritems[i]) === child) { return i; } } @@ -5497,7 +5492,7 @@ List.prototype.select = function(index) { this._listInitialized = true; this.selected = index; - this.value = this.items[this.selected].getText(); + this.value = helpers.cleanTags(this.ritems[this.selected]); if (!this.parent) return; this.scrollTo(this.selected); }; @@ -5545,7 +5540,7 @@ List.prototype.pick = function(label, callback) { self.hide(); self.screen.render(); if (!el) return callback(); - return callback(null, self.items[selected].getText()); + return callback(null, helpers.cleanTags(self.items[selected])); }); }; @@ -9120,6 +9115,13 @@ helpers.attrToBinary = function(style, element) { return Element.prototype.sattr.call(element || {}, style); }; +helpers.cleanTags = function(text) { + return text + .replace(/{(\/?)([\w\-,;!#]*)}/g, '') + .replace(/\x1b\[[\d;]*m/g, '') + .trim(); +}; + helpers.merge = merge; helpers.asort = asort; helpers.findFile = findFile; diff --git a/test/widget.js b/test/widget.js index 1c8ce5a..4b029b0 100644 --- a/test/widget.js +++ b/test/widget.js @@ -18,7 +18,7 @@ screen = blessed.screen({ screen.debugLog.parseTags = true; var logs = ''; require('./tail')(__dirname + '/logs/widget.log').on('line', function(line) { - if (!screen.debugLog.hidden) return; + // if (!screen.debugLog.hidden) return; logs += line + '\n'; }); screen.debugLog.on('show', function() { @@ -26,6 +26,7 @@ screen.debugLog.on('show', function() { screen.debug(logs); logs = ''; } + screen.render(); }); screen.append(blessed.text({