1 | import * as components from '@pres/components';
|
2 | export { ANSIImage, BarChart, BigText, Box, Button, Canvas, Carousel, Checkbox, DataTable, DonutChart, FileManager, Form, Gauge, GaugeList, Grid, Image, Input, LCD, Layout, Line, LineChart, List, ListBar, ListTable, Loading, Log, LogList, Map, Markdown, Message, Node, OverlayImage, Picture, ProgressBar, Prompt, Question, RadioButton, RadioSet, Screen, ScrollableBox, ScrollableText, Sparkline, StackedBarChart, Table, Terminal, Text, Textarea, Textbox, Tree, Video } from '@pres/components';
|
3 | import { Program } from '@pres/program';
|
4 | import { Tput } from '@pres/terminfo-parser';
|
5 | import * as colors from '@pres/util-blessed-colors';
|
6 | import * as helpers from '@pres/util-helpers';
|
7 | import * as unicode from '@pres/util-unicode';
|
8 | import url from 'url';
|
9 |
|
10 | /**
|
11 | // chart
|
12 | * @property {function(Object?):BarChart} barChart
|
13 | * @property {function(Object?):DonutChart} donutChart
|
14 | * @property {function(Object?):Gauge} gauge
|
15 | * @property {function(Object?):GaugeList} gaugeList
|
16 | * @property {function(Object?):LineChart} lineChart
|
17 | * @property {function(Object?):Sparkline} sparkline
|
18 | * @property {function(Object?):StackedBarChart} stackedBarChart
|
19 | // core
|
20 | * @property {function(Object?):Box} box
|
21 | * @property {function(Object?):Element} element
|
22 | * @property {function(Object?):Node} node
|
23 | * @property {function(Object?):Screen} screen
|
24 | * @property {function(Object?):Layout} layout
|
25 | * @property {function(Object?):Line} line
|
26 | * @property {function(Object?):Log} log
|
27 | * @property {function(Object?):ScrollableBox} scrollableBox
|
28 | * @property {function(Object?):ScrollableText} scrollableText
|
29 | * @property {function(Object?):Terminal} terminal
|
30 | // data
|
31 | * @property {function(Object?):DataTable} dataTable
|
32 | * @property {function(Object?):List} list
|
33 | * @property {function(Object?):ListBar} listBar
|
34 | * @property {function(Object?):ListTable} listTable
|
35 | * @property {function(Object?):Table} table
|
36 | * @property {function(Object?):Tree} tree
|
37 | // form
|
38 | * @property {function(Object?):Button} button
|
39 | * @property {function(Object?):Checkbox} checkbox
|
40 | * @property {function(Object?):FileManager} fileManager
|
41 | * @property {function(Object?):Form} form
|
42 | * @property {function(Object?):Input} input
|
43 | * @property {function(Object?):Prompt} prompt
|
44 | * @property {function(Object?):Question} question
|
45 | * @property {function(Object?):RadioButton} radioButton
|
46 | * @property {function(Object?):RadioSet} radioSet
|
47 | * @property {function(Object?):Textbox} textbox
|
48 | * @property {function(Object?):Textarea} textarea
|
49 | // geo
|
50 | * @property {function(Object?):Map} map
|
51 | // inform
|
52 | * @property {function(Object?):LCD} lcd
|
53 | * @property {function(Object?):Loading} loading
|
54 | * @property {function(Object?):Message} message
|
55 | * @property {function(Object?):ProgressBar} progressBar
|
56 | // layout
|
57 | * @property {function(Object?):Canvas} canvas
|
58 | * @property {function(Object?):Carousel} carousel
|
59 | * @property {function(Object?):Grid} grid
|
60 | // text
|
61 | * @property {function(Object?):LogList} logList
|
62 | * @property {function(Object?):Markdown} markdown
|
63 | * @property {function(Object?):Text} text
|
64 | // visual
|
65 | * @property {function(Object?):ANSIImage} ansiImage
|
66 | * @property {function(Object?):BigText} bigText
|
67 | * @property {function(Object?):Image} image
|
68 | * @property {function(Object?):OverlayImage} overlayImage
|
69 | * @property {function(Object?):Picture} picture
|
70 | * @property {function(Object?):PNG} png
|
71 | * @property {function(Object?):Video} video
|
72 | */
|
73 |
|
74 | class TI {}
|
75 | TI.program = Program.build;
|
76 | TI.build = Program.build;
|
77 | TI.helpers = helpers;
|
78 | TI.unicode = unicode;
|
79 | TI.colors = colors;
|
80 | TI.Tput = Tput;
|
81 | Object.assign(TI, components); // // chart
|
82 | // static barChart = barChart
|
83 | // static donutChart = donutChart
|
84 | // static gauge = gauge
|
85 | // static gaugeList = gaugeList
|
86 | // static lineChart = lineChart
|
87 | // static sparkline = sparkline
|
88 | // static stackedBarChart = stackedBarChart
|
89 | // // core
|
90 | // static box = box
|
91 | // static element = element
|
92 | // static node = node
|
93 | // static screen = screen
|
94 | // static layout = layout
|
95 | // static line = line
|
96 | // static log = log
|
97 | // static scrollableBox = scrollableBox
|
98 | // static scrollableText = scrollableText
|
99 | // static terminal = terminal
|
100 | // // data
|
101 | // static dataTable = dataTable
|
102 | // static list = list
|
103 | // static listBar = listBar
|
104 | // static listTable = listTable
|
105 | // static table = table
|
106 | // static tree = tree
|
107 | // // form
|
108 | // static button = button
|
109 | // static checkbox = checkbox
|
110 | // static fileManager = fileManager
|
111 | // static form = form
|
112 | // static input = input
|
113 | // static prompt = prompt
|
114 | // static question = question
|
115 | // static radioButton = radioButton
|
116 | // static radioSet = radioSet
|
117 | // static textbox = textbox
|
118 | // static textarea = textarea
|
119 | // // geo
|
120 | // static map = map
|
121 | // // inform
|
122 | // static lcd = lcd
|
123 | // static loading = loading
|
124 | // static message = message
|
125 | // static progressBar = progressBar
|
126 | // // layout
|
127 | // static canvas = canvas
|
128 | // static carousel = carousel
|
129 | // static grid = grid
|
130 | // // text
|
131 | // static logList = logList
|
132 | // static markdown = markdown
|
133 | // static text = text
|
134 | // // visual
|
135 | // static ansiImage = ansiImage
|
136 | // static bigText = bigText
|
137 | // static image = image
|
138 | // static overlayImage = overlayImage
|
139 | // static picture = picture
|
140 | // static png = png
|
141 | // static video = video
|
142 |
|
143 | function OutputBuffer(options) {
|
144 | this.isTTY = true;
|
145 | this.columns = options.cols;
|
146 | this.rows = options.rows;
|
147 |
|
148 | this.write = function (s) {
|
149 | s = s.replace('\x1b8', ''); //not clear from where in TI this code comes from. It forces the terminal to clear and loose existing content.
|
150 |
|
151 | options.res.write(s);
|
152 | };
|
153 |
|
154 | this.on = function () {};
|
155 | }
|
156 |
|
157 | function InputBuffer() {
|
158 | this.isTTY = true;
|
159 | this.isRaw = true;
|
160 |
|
161 | this.emit = function () {};
|
162 |
|
163 | this.setRawMode = function () {};
|
164 |
|
165 | this.resume = function () {};
|
166 |
|
167 | this.pause = function () {};
|
168 |
|
169 | this.on = function () {};
|
170 | }
|
171 |
|
172 | function serverError(req, res, err) {
|
173 | setTimeout(function () {
|
174 | if (!res.headersSent) res.writeHead(500, {
|
175 | 'Content-Type': 'text/plain'
|
176 | });
|
177 | res.write('\r\n\r\n' + err + '\r\n\r\n'); //restore cursor
|
178 |
|
179 | res.end('\u001b[?25h');
|
180 | }, 0);
|
181 | return true;
|
182 | }
|
183 |
|
184 | function createScreen(req, res) {
|
185 | const query = url.parse(req.url, true).query;
|
186 | const cols = query.cols || 250;
|
187 | const rows = query.rows || 50;
|
188 |
|
189 | if (cols <= 35 || cols >= 500 || rows <= 5 || rows >= 300) {
|
190 | serverError(req, res, 'cols must be bigger than 35 and rows must be bigger than 5');
|
191 | return null;
|
192 | }
|
193 |
|
194 | res.writeHead(200, {
|
195 | 'Content-Type': 'text/plain'
|
196 | });
|
197 | const output = new OutputBuffer({
|
198 | res: res,
|
199 | cols: cols,
|
200 | rows: rows
|
201 | });
|
202 | const input = new InputBuffer(); //required to run under forever since it replaces stdin to non-tty
|
203 |
|
204 | const program = TI.program({
|
205 | output: output,
|
206 | input: input
|
207 | });
|
208 | if (query.terminal) program.terminal = query.terminal;
|
209 | if (query.isOSX) program.isOSXTerm = query.isOSX;
|
210 | if (query.isiTerm2) program.isiTerm2 = query.isiTerm2;
|
211 | return TI.screen({
|
212 | program: program
|
213 | });
|
214 | }
|
215 |
|
216 | export { InputBuffer, OutputBuffer, TI as Pres, TI, TI as TerminalInterface, TI as blessed, TI as contrib, createScreen, serverError };
|