From a2f7687335eb7121e23a76cc9a9f81d6e57be337 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 28 Jan 2019 18:10:01 +0300 Subject: [PATCH] added a text renderer for general testing and tweaking... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/widget/browse2.js | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/ui (gen4)/lib/widget/browse2.js b/ui (gen4)/lib/widget/browse2.js index 0462e0b0..0878c600 100755 --- a/ui (gen4)/lib/widget/browse2.js +++ b/ui (gen4)/lib/widget/browse2.js @@ -485,6 +485,54 @@ object.makeConstructor('Browser', +//--------------------------------------------------------------------- +// Text tree renderer... +// +// This is mainly designed for testing. +// +// XXX how the header item and it's sublist should be linked??? + +var TextBrowserClassPrototype = { + __proto__: BaseBrowser, +} + +var TextBrowserPrototype = { + __proto__: BaseBrowser.prototype, + + options: { + renderIndent: '\t', + }, + + renderList: function(items, options){ + var that = this + return this.renderSubList(items, null, options) + .join('\n') }, + renderSubList: function(sublist, item, options){ + var that = this + return sublist + .flat() + .map(function(e){ + return e instanceof Array ? + e.map(function(e){ return (that.options.renderIndent || ' ') + e }) + : e }) + .flat() }, + //renderGroup: function(items, options){ + // return items }, + renderItem: function(item, i, options){ + var value = item.value || item + return item.current ? + `[ ${value} ]` + : value }, +} + + +var TextBrowser = +module.TextBrowser = +object.makeConstructor('TextBrowser', + TextBrowserClassPrototype, + TextBrowserPrototype) + + /********************************************************************** * vim:set ts=4 sw=4 : */ return module })