1 | "use strict";
|
---|
2 |
|
---|
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
---|
4 |
|
---|
5 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
6 |
|
---|
7 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
---|
8 |
|
---|
9 | // Generated by CoffeeScript 2.5.1
|
---|
10 | var Block, Layout, SpecialString, cloneAndMergeDeep, i, len, prop, ref, terminalWidth;
|
---|
11 | Block = require('./layout/Block');
|
---|
12 |
|
---|
13 | var _require = require('./tools');
|
---|
14 |
|
---|
15 | cloneAndMergeDeep = _require.cloneAndMergeDeep;
|
---|
16 | SpecialString = require('./layout/SpecialString');
|
---|
17 | terminalWidth = require('./tools').getCols();
|
---|
18 |
|
---|
19 | module.exports = Layout = function () {
|
---|
20 | var self;
|
---|
21 |
|
---|
22 | var Layout = /*#__PURE__*/function () {
|
---|
23 | function Layout() {
|
---|
24 | var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
---|
25 | var rootBlockConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
---|
26 |
|
---|
27 | _classCallCheck(this, Layout);
|
---|
28 |
|
---|
29 | var rootConfig;
|
---|
30 | this._written = [];
|
---|
31 | this._activeBlock = null;
|
---|
32 | this._config = cloneAndMergeDeep(self._defaultConfig, config); // Every layout has a root block
|
---|
33 |
|
---|
34 | rootConfig = cloneAndMergeDeep(self._rootBlockDefaultConfig, rootBlockConfig);
|
---|
35 | this._root = new Block(this, null, rootConfig, '__root');
|
---|
36 |
|
---|
37 | this._root._open();
|
---|
38 | }
|
---|
39 |
|
---|
40 | _createClass(Layout, [{
|
---|
41 | key: "getRootBlock",
|
---|
42 | value: function getRootBlock() {
|
---|
43 | return this._root;
|
---|
44 | }
|
---|
45 | }, {
|
---|
46 | key: "_append",
|
---|
47 | value: function _append(text) {
|
---|
48 | return this._written.push(text);
|
---|
49 | }
|
---|
50 | }, {
|
---|
51 | key: "_appendLine",
|
---|
52 | value: function _appendLine(text) {
|
---|
53 | var s;
|
---|
54 |
|
---|
55 | this._append(text);
|
---|
56 |
|
---|
57 | s = new SpecialString(text);
|
---|
58 |
|
---|
59 | if (s.length < this._config.terminalWidth) {
|
---|
60 | this._append('<none>\n</none>');
|
---|
61 | }
|
---|
62 |
|
---|
63 | return this;
|
---|
64 | }
|
---|
65 | }, {
|
---|
66 | key: "get",
|
---|
67 | value: function get() {
|
---|
68 | this._ensureClosed();
|
---|
69 |
|
---|
70 | if (this._written[this._written.length - 1] === '<none>\n</none>') {
|
---|
71 | this._written.pop();
|
---|
72 | }
|
---|
73 |
|
---|
74 | return this._written.join("");
|
---|
75 | }
|
---|
76 | }, {
|
---|
77 | key: "_ensureClosed",
|
---|
78 | value: function _ensureClosed() {
|
---|
79 | if (this._activeBlock !== this._root) {
|
---|
80 | throw Error("Not all the blocks have been closed. Please call block.close() on all open blocks.");
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (this._root.isOpen()) {
|
---|
84 | this._root.close();
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }]);
|
---|
88 |
|
---|
89 | return Layout;
|
---|
90 | }();
|
---|
91 |
|
---|
92 | ;
|
---|
93 | self = Layout;
|
---|
94 | Layout._rootBlockDefaultConfig = {
|
---|
95 | linePrependor: {
|
---|
96 | options: {
|
---|
97 | amount: 0
|
---|
98 | }
|
---|
99 | },
|
---|
100 | lineAppendor: {
|
---|
101 | options: {
|
---|
102 | amount: 0
|
---|
103 | }
|
---|
104 | },
|
---|
105 | blockPrependor: {
|
---|
106 | options: {
|
---|
107 | amount: 0
|
---|
108 | }
|
---|
109 | },
|
---|
110 | blockAppendor: {
|
---|
111 | options: {
|
---|
112 | amount: 0
|
---|
113 | }
|
---|
114 | }
|
---|
115 | };
|
---|
116 | Layout._defaultConfig = {
|
---|
117 | terminalWidth: terminalWidth
|
---|
118 | };
|
---|
119 | return Layout;
|
---|
120 | }.call(void 0);
|
---|
121 |
|
---|
122 | ref = ['openBlock', 'write'];
|
---|
123 |
|
---|
124 | for (i = 0, len = ref.length; i < len; i++) {
|
---|
125 | prop = ref[i];
|
---|
126 |
|
---|
127 | (function () {
|
---|
128 | var method;
|
---|
129 | method = prop;
|
---|
130 | return Layout.prototype[method] = function () {
|
---|
131 | return this._root[method].apply(this._root, arguments);
|
---|
132 | };
|
---|
133 | })();
|
---|
134 | } |
---|