diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
commit | de98e0b232509d5f40c135d540a70e415272ff85 (patch) | |
tree | a79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/renderkid/lib/Layout.js | |
parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) | |
download | wallet-core-de98e0b232509d5f40c135d540a70e415272ff85.tar.xz |
node_modules
Diffstat (limited to 'node_modules/renderkid/lib/Layout.js')
-rw-r--r-- | node_modules/renderkid/lib/Layout.js | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/node_modules/renderkid/lib/Layout.js b/node_modules/renderkid/lib/Layout.js new file mode 100644 index 000000000..842945e29 --- /dev/null +++ b/node_modules/renderkid/lib/Layout.js @@ -0,0 +1,110 @@ +// Generated by CoffeeScript 1.9.3 +var Block, Layout, SpecialString, fn, i, len, object, prop, ref, terminalWidth; + +Block = require('./layout/Block'); + +object = require('utila').object; + +SpecialString = require('./layout/SpecialString'); + +terminalWidth = require('./tools').getCols(); + +module.exports = Layout = (function() { + var self; + + self = Layout; + + Layout._rootBlockDefaultConfig = { + linePrependor: { + options: { + amount: 0 + } + }, + lineAppendor: { + options: { + amount: 0 + } + }, + blockPrependor: { + options: { + amount: 0 + } + }, + blockAppendor: { + options: { + amount: 0 + } + } + }; + + Layout._defaultConfig = { + terminalWidth: terminalWidth + }; + + function Layout(config, rootBlockConfig) { + var rootConfig; + if (config == null) { + config = {}; + } + if (rootBlockConfig == null) { + rootBlockConfig = {}; + } + this._written = []; + this._activeBlock = null; + this._config = object.append(self._defaultConfig, config); + rootConfig = object.append(self._rootBlockDefaultConfig, rootBlockConfig); + this._root = new Block(this, null, rootConfig, '__root'); + this._root._open(); + } + + Layout.prototype.getRootBlock = function() { + return this._root; + }; + + Layout.prototype._append = function(text) { + return this._written.push(text); + }; + + Layout.prototype._appendLine = function(text) { + var s; + this._append(text); + s = SpecialString(text); + if (s.length < this._config.terminalWidth) { + this._append('<none>\n</none>'); + } + return this; + }; + + Layout.prototype.get = function() { + this._ensureClosed(); + if (this._written[this._written.length - 1] === '<none>\n</none>') { + this._written.pop(); + } + return this._written.join(""); + }; + + Layout.prototype._ensureClosed = function() { + if (this._activeBlock !== this._root) { + throw Error("Not all the blocks have been closed. Please call block.close() on all open blocks."); + } + if (this._root.isOpen()) { + this._root.close(); + } + }; + + return Layout; + +})(); + +ref = ['openBlock', 'write']; +fn = function() { + var method; + method = prop; + return Layout.prototype[method] = function() { + return this._root[method].apply(this._root, arguments); + }; +}; +for (i = 0, len = ref.length; i < len; i++) { + prop = ref[i]; + fn(); +} |