UNPKG

14 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var components = require('@pres/components');
6var program = require('@pres/program');
7var terminfoParser = require('@pres/terminfo-parser');
8var colors = require('@pres/util-blessed-colors');
9var helpers = require('@pres/util-helpers');
10var unicode = require('@pres/util-unicode');
11var url = require('url');
12
13function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
15function _interopNamespace(e) {
16 if (e && e.__esModule) return e;
17 var n = Object.create(null);
18 if (e) {
19 Object.keys(e).forEach(function (k) {
20 if (k !== 'default') {
21 var d = Object.getOwnPropertyDescriptor(e, k);
22 Object.defineProperty(n, k, d.get ? d : {
23 enumerable: true,
24 get: function () {
25 return e[k];
26 }
27 });
28 }
29 });
30 }
31 n['default'] = e;
32 return Object.freeze(n);
33}
34
35var components__namespace = /*#__PURE__*/_interopNamespace(components);
36var colors__namespace = /*#__PURE__*/_interopNamespace(colors);
37var helpers__namespace = /*#__PURE__*/_interopNamespace(helpers);
38var unicode__namespace = /*#__PURE__*/_interopNamespace(unicode);
39var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
40
41/**
42 // chart
43 * @property {function(Object?):BarChart} barChart
44 * @property {function(Object?):DonutChart} donutChart
45 * @property {function(Object?):Gauge} gauge
46 * @property {function(Object?):GaugeList} gaugeList
47 * @property {function(Object?):LineChart} lineChart
48 * @property {function(Object?):Sparkline} sparkline
49 * @property {function(Object?):StackedBarChart} stackedBarChart
50 // core
51 * @property {function(Object?):Box} box
52 * @property {function(Object?):Element} element
53 * @property {function(Object?):Node} node
54 * @property {function(Object?):Screen} screen
55 * @property {function(Object?):Layout} layout
56 * @property {function(Object?):Line} line
57 * @property {function(Object?):Log} log
58 * @property {function(Object?):ScrollableBox} scrollableBox
59 * @property {function(Object?):ScrollableText} scrollableText
60 * @property {function(Object?):Terminal} terminal
61 // data
62 * @property {function(Object?):DataTable} dataTable
63 * @property {function(Object?):List} list
64 * @property {function(Object?):ListBar} listBar
65 * @property {function(Object?):ListTable} listTable
66 * @property {function(Object?):Table} table
67 * @property {function(Object?):Tree} tree
68 // form
69 * @property {function(Object?):Button} button
70 * @property {function(Object?):Checkbox} checkbox
71 * @property {function(Object?):FileManager} fileManager
72 * @property {function(Object?):Form} form
73 * @property {function(Object?):Input} input
74 * @property {function(Object?):Prompt} prompt
75 * @property {function(Object?):Question} question
76 * @property {function(Object?):RadioButton} radioButton
77 * @property {function(Object?):RadioSet} radioSet
78 * @property {function(Object?):Textbox} textbox
79 * @property {function(Object?):Textarea} textarea
80 // geo
81 * @property {function(Object?):Map} map
82 // inform
83 * @property {function(Object?):LCD} lcd
84 * @property {function(Object?):Loading} loading
85 * @property {function(Object?):Message} message
86 * @property {function(Object?):ProgressBar} progressBar
87 // layout
88 * @property {function(Object?):Canvas} canvas
89 * @property {function(Object?):Carousel} carousel
90 * @property {function(Object?):Grid} grid
91 // text
92 * @property {function(Object?):LogList} logList
93 * @property {function(Object?):Markdown} markdown
94 * @property {function(Object?):Text} text
95 // visual
96 * @property {function(Object?):ANSIImage} ansiImage
97 * @property {function(Object?):BigText} bigText
98 * @property {function(Object?):Image} image
99 * @property {function(Object?):OverlayImage} overlayImage
100 * @property {function(Object?):Picture} picture
101 * @property {function(Object?):PNG} png
102 * @property {function(Object?):Video} video
103 */
104
105class TI {}
106TI.program = program.Program.build;
107TI.build = program.Program.build;
108TI.helpers = helpers__namespace;
109TI.unicode = unicode__namespace;
110TI.colors = colors__namespace;
111TI.Tput = terminfoParser.Tput;
112Object.assign(TI, components__namespace); // // chart
113// static barChart = barChart
114// static donutChart = donutChart
115// static gauge = gauge
116// static gaugeList = gaugeList
117// static lineChart = lineChart
118// static sparkline = sparkline
119// static stackedBarChart = stackedBarChart
120// // core
121// static box = box
122// static element = element
123// static node = node
124// static screen = screen
125// static layout = layout
126// static line = line
127// static log = log
128// static scrollableBox = scrollableBox
129// static scrollableText = scrollableText
130// static terminal = terminal
131// // data
132// static dataTable = dataTable
133// static list = list
134// static listBar = listBar
135// static listTable = listTable
136// static table = table
137// static tree = tree
138// // form
139// static button = button
140// static checkbox = checkbox
141// static fileManager = fileManager
142// static form = form
143// static input = input
144// static prompt = prompt
145// static question = question
146// static radioButton = radioButton
147// static radioSet = radioSet
148// static textbox = textbox
149// static textarea = textarea
150// // geo
151// static map = map
152// // inform
153// static lcd = lcd
154// static loading = loading
155// static message = message
156// static progressBar = progressBar
157// // layout
158// static canvas = canvas
159// static carousel = carousel
160// static grid = grid
161// // text
162// static logList = logList
163// static markdown = markdown
164// static text = text
165// // visual
166// static ansiImage = ansiImage
167// static bigText = bigText
168// static image = image
169// static overlayImage = overlayImage
170// static picture = picture
171// static png = png
172// static video = video
173
174function OutputBuffer(options) {
175 this.isTTY = true;
176 this.columns = options.cols;
177 this.rows = options.rows;
178
179 this.write = function (s) {
180 s = s.replace('\x1b8', ''); //not clear from where in TI this code comes from. It forces the terminal to clear and loose existing content.
181
182 options.res.write(s);
183 };
184
185 this.on = function () {};
186}
187
188function InputBuffer() {
189 this.isTTY = true;
190 this.isRaw = true;
191
192 this.emit = function () {};
193
194 this.setRawMode = function () {};
195
196 this.resume = function () {};
197
198 this.pause = function () {};
199
200 this.on = function () {};
201}
202
203function serverError(req, res, err) {
204 setTimeout(function () {
205 if (!res.headersSent) res.writeHead(500, {
206 'Content-Type': 'text/plain'
207 });
208 res.write('\r\n\r\n' + err + '\r\n\r\n'); //restore cursor
209
210 res.end('\u001b[?25h');
211 }, 0);
212 return true;
213}
214
215function createScreen(req, res) {
216 const query = url__default['default'].parse(req.url, true).query;
217 const cols = query.cols || 250;
218 const rows = query.rows || 50;
219
220 if (cols <= 35 || cols >= 500 || rows <= 5 || rows >= 300) {
221 serverError(req, res, 'cols must be bigger than 35 and rows must be bigger than 5');
222 return null;
223 }
224
225 res.writeHead(200, {
226 'Content-Type': 'text/plain'
227 });
228 const output = new OutputBuffer({
229 res: res,
230 cols: cols,
231 rows: rows
232 });
233 const input = new InputBuffer(); //required to run under forever since it replaces stdin to non-tty
234
235 const program = TI.program({
236 output: output,
237 input: input
238 });
239 if (query.terminal) program.terminal = query.terminal;
240 if (query.isOSX) program.isOSXTerm = query.isOSX;
241 if (query.isiTerm2) program.isiTerm2 = query.isiTerm2;
242 return TI.screen({
243 program: program
244 });
245}
246
247Object.defineProperty(exports, 'ANSIImage', {
248 enumerable: true,
249 get: function () {
250 return components.ANSIImage;
251 }
252});
253Object.defineProperty(exports, 'BarChart', {
254 enumerable: true,
255 get: function () {
256 return components.BarChart;
257 }
258});
259Object.defineProperty(exports, 'BigText', {
260 enumerable: true,
261 get: function () {
262 return components.BigText;
263 }
264});
265Object.defineProperty(exports, 'Box', {
266 enumerable: true,
267 get: function () {
268 return components.Box;
269 }
270});
271Object.defineProperty(exports, 'Button', {
272 enumerable: true,
273 get: function () {
274 return components.Button;
275 }
276});
277Object.defineProperty(exports, 'Canvas', {
278 enumerable: true,
279 get: function () {
280 return components.Canvas;
281 }
282});
283Object.defineProperty(exports, 'Carousel', {
284 enumerable: true,
285 get: function () {
286 return components.Carousel;
287 }
288});
289Object.defineProperty(exports, 'Checkbox', {
290 enumerable: true,
291 get: function () {
292 return components.Checkbox;
293 }
294});
295Object.defineProperty(exports, 'DataTable', {
296 enumerable: true,
297 get: function () {
298 return components.DataTable;
299 }
300});
301Object.defineProperty(exports, 'DonutChart', {
302 enumerable: true,
303 get: function () {
304 return components.DonutChart;
305 }
306});
307Object.defineProperty(exports, 'FileManager', {
308 enumerable: true,
309 get: function () {
310 return components.FileManager;
311 }
312});
313Object.defineProperty(exports, 'Form', {
314 enumerable: true,
315 get: function () {
316 return components.Form;
317 }
318});
319Object.defineProperty(exports, 'Gauge', {
320 enumerable: true,
321 get: function () {
322 return components.Gauge;
323 }
324});
325Object.defineProperty(exports, 'GaugeList', {
326 enumerable: true,
327 get: function () {
328 return components.GaugeList;
329 }
330});
331Object.defineProperty(exports, 'Grid', {
332 enumerable: true,
333 get: function () {
334 return components.Grid;
335 }
336});
337Object.defineProperty(exports, 'Image', {
338 enumerable: true,
339 get: function () {
340 return components.Image;
341 }
342});
343Object.defineProperty(exports, 'Input', {
344 enumerable: true,
345 get: function () {
346 return components.Input;
347 }
348});
349Object.defineProperty(exports, 'LCD', {
350 enumerable: true,
351 get: function () {
352 return components.LCD;
353 }
354});
355Object.defineProperty(exports, 'Layout', {
356 enumerable: true,
357 get: function () {
358 return components.Layout;
359 }
360});
361Object.defineProperty(exports, 'Line', {
362 enumerable: true,
363 get: function () {
364 return components.Line;
365 }
366});
367Object.defineProperty(exports, 'LineChart', {
368 enumerable: true,
369 get: function () {
370 return components.LineChart;
371 }
372});
373Object.defineProperty(exports, 'List', {
374 enumerable: true,
375 get: function () {
376 return components.List;
377 }
378});
379Object.defineProperty(exports, 'ListBar', {
380 enumerable: true,
381 get: function () {
382 return components.ListBar;
383 }
384});
385Object.defineProperty(exports, 'ListTable', {
386 enumerable: true,
387 get: function () {
388 return components.ListTable;
389 }
390});
391Object.defineProperty(exports, 'Loading', {
392 enumerable: true,
393 get: function () {
394 return components.Loading;
395 }
396});
397Object.defineProperty(exports, 'Log', {
398 enumerable: true,
399 get: function () {
400 return components.Log;
401 }
402});
403Object.defineProperty(exports, 'LogList', {
404 enumerable: true,
405 get: function () {
406 return components.LogList;
407 }
408});
409Object.defineProperty(exports, 'Map', {
410 enumerable: true,
411 get: function () {
412 return components.Map;
413 }
414});
415Object.defineProperty(exports, 'Markdown', {
416 enumerable: true,
417 get: function () {
418 return components.Markdown;
419 }
420});
421Object.defineProperty(exports, 'Message', {
422 enumerable: true,
423 get: function () {
424 return components.Message;
425 }
426});
427Object.defineProperty(exports, 'Node', {
428 enumerable: true,
429 get: function () {
430 return components.Node;
431 }
432});
433Object.defineProperty(exports, 'OverlayImage', {
434 enumerable: true,
435 get: function () {
436 return components.OverlayImage;
437 }
438});
439Object.defineProperty(exports, 'Picture', {
440 enumerable: true,
441 get: function () {
442 return components.Picture;
443 }
444});
445Object.defineProperty(exports, 'ProgressBar', {
446 enumerable: true,
447 get: function () {
448 return components.ProgressBar;
449 }
450});
451Object.defineProperty(exports, 'Prompt', {
452 enumerable: true,
453 get: function () {
454 return components.Prompt;
455 }
456});
457Object.defineProperty(exports, 'Question', {
458 enumerable: true,
459 get: function () {
460 return components.Question;
461 }
462});
463Object.defineProperty(exports, 'RadioButton', {
464 enumerable: true,
465 get: function () {
466 return components.RadioButton;
467 }
468});
469Object.defineProperty(exports, 'RadioSet', {
470 enumerable: true,
471 get: function () {
472 return components.RadioSet;
473 }
474});
475Object.defineProperty(exports, 'Screen', {
476 enumerable: true,
477 get: function () {
478 return components.Screen;
479 }
480});
481Object.defineProperty(exports, 'ScrollableBox', {
482 enumerable: true,
483 get: function () {
484 return components.ScrollableBox;
485 }
486});
487Object.defineProperty(exports, 'ScrollableText', {
488 enumerable: true,
489 get: function () {
490 return components.ScrollableText;
491 }
492});
493Object.defineProperty(exports, 'Sparkline', {
494 enumerable: true,
495 get: function () {
496 return components.Sparkline;
497 }
498});
499Object.defineProperty(exports, 'StackedBarChart', {
500 enumerable: true,
501 get: function () {
502 return components.StackedBarChart;
503 }
504});
505Object.defineProperty(exports, 'Table', {
506 enumerable: true,
507 get: function () {
508 return components.Table;
509 }
510});
511Object.defineProperty(exports, 'Terminal', {
512 enumerable: true,
513 get: function () {
514 return components.Terminal;
515 }
516});
517Object.defineProperty(exports, 'Text', {
518 enumerable: true,
519 get: function () {
520 return components.Text;
521 }
522});
523Object.defineProperty(exports, 'Textarea', {
524 enumerable: true,
525 get: function () {
526 return components.Textarea;
527 }
528});
529Object.defineProperty(exports, 'Textbox', {
530 enumerable: true,
531 get: function () {
532 return components.Textbox;
533 }
534});
535Object.defineProperty(exports, 'Tree', {
536 enumerable: true,
537 get: function () {
538 return components.Tree;
539 }
540});
541Object.defineProperty(exports, 'Video', {
542 enumerable: true,
543 get: function () {
544 return components.Video;
545 }
546});
547exports.InputBuffer = InputBuffer;
548exports.OutputBuffer = OutputBuffer;
549exports.Pres = TI;
550exports.TI = TI;
551exports.TerminalInterface = TI;
552exports.blessed = TI;
553exports.contrib = TI;
554exports.createScreen = createScreen;
555exports.serverError = serverError;