diff --git a/lib/blessed.js b/lib/blessed.js index 59ef82f..c3c1724 100644 --- a/lib/blessed.js +++ b/lib/blessed.js @@ -37,6 +37,11 @@ blessed.helpers = { tryRead: blessed.tput.tryRead }; +Object.keys(widget.helpers).forEach(function(key) { + blessed.helpers[key] = widget.helpers[key]; + blessed[key] = widget.helpers[key]; +}); + /** * Expose */ diff --git a/lib/widget.js b/lib/widget.js index 4df7bd7..f1198ef 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -6368,6 +6368,19 @@ var wideChars = new RegExp('([' + '\\uffe8-\\uffee' + '])', 'g'); +/** + * Helpers + */ + +var helpers = {}; + +// Escape text for tag-enabled elements. +helpers.escape = function(text) { + return text.replace(/[{}]/g, function(ch) { + return ch === '{' ? '{open}' : '{close}'; + }); +}; + /** * Expose */ @@ -6400,3 +6413,5 @@ exports.Loading = exports.loading = Loading; exports.Listbar = exports.listbar = Listbar; exports.DirManager = exports.dirmanager = DirManager; exports.Passbox = exports.passbox = Passbox; + +exports.helpers = helpers; diff --git a/test/widget-nowrap.js b/test/widget-nowrap.js index 53ab4e9..334588e 100644 --- a/test/widget-nowrap.js +++ b/test/widget-nowrap.js @@ -15,6 +15,7 @@ var box = blessed.box({ wrap: false, tags: true, content: fs.readFileSync(__filename, 'utf8') + // content: '{red-bg}' + blessed.escape('{{{{{}{bold}x{/bold}}') + '{/red-bg}' }); box.focus();