UNPKG

3.77 kBJavaScriptView Raw
1#!/usr/bin/env node
2/*
3 Terminal Kit
4
5 Copyright (c) 2009 - 2020 Cédric Ronvel
6
7 The MIT License (MIT)
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in all
17 copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 SOFTWARE.
26*/
27
28"use strict" ;
29
30
31
32/* jshint unused:false */
33
34
35
36//console.error( "\n\n\n\n\n\n\n\n" ) ;
37var termkit = require( '../../lib/termkit.js' ) ;
38var term = termkit.terminal ;
39
40
41
42term.clear() ;
43
44var document = term.createDocument( {
45// backgroundAttr: { bgColor: 'magenta' , dim: true } ,
46} ) ;
47
48var A = new termkit.Button( {
49 parent: document ,
50 content: '<A>' ,
51 value: 'A' ,
52 x: 0 ,
53 y: 0 ,
54} ) ;
55
56new termkit.Button( {
57 parent: A ,
58 content: '<1>' ,
59 value: '1' ,
60 x: 10 ,
61 y: 0 ,
62} ) ;
63
64new termkit.Button( {
65 parent: A ,
66 content: '<2>' ,
67 value: '2' ,
68 x: 10 ,
69 y: 2 ,
70} ) ;
71
72new termkit.Button( {
73 parent: A ,
74 content: '<3>' ,
75 value: '3' ,
76 x: 10 ,
77 y: 4 ,
78} ) ;
79
80var B = new termkit.Button( {
81 parent: document ,
82 content: '<B>' ,
83 value: 'B' ,
84 x: 0 ,
85 y: 6 ,
86} ) ;
87
88var sub = new termkit.Button( {
89 parent: B ,
90 content: '<1>' ,
91 value: '1' ,
92 x: 10 ,
93 y: 6 ,
94} ) ;
95
96 new termkit.Button( {
97 parent: sub ,
98 content: '<...>' ,
99 value: '...' ,
100 x: 20 ,
101 y: 6 ,
102 } ) ;
103
104 new termkit.Button( {
105 parent: sub ,
106 content: '<...>' ,
107 value: '...' ,
108 x: 30 ,
109 y: 6 ,
110 } ) ;
111
112 new termkit.Button( {
113 parent: sub ,
114 content: '<...>' ,
115 value: '...' ,
116 x: 40 ,
117 y: 6 ,
118 } ) ;
119
120new termkit.Button( {
121 parent: B ,
122 content: '<2>' ,
123 value: '2' ,
124 x: 10 ,
125 y: 8 ,
126} ) ;
127
128var sub2 = new termkit.Button( {
129 parent: B ,
130 content: '<3>' ,
131 value: '3' ,
132 x: 10 ,
133 y: 10 ,
134} ) ;
135
136 new termkit.Button( {
137 parent: sub2 ,
138 content: '<...>' ,
139 value: '...' ,
140 x: 20 ,
141 y: 10 ,
142 } ) ;
143
144 new termkit.Button( {
145 parent: sub2 ,
146 content: '<...>' ,
147 value: '...' ,
148 x: 30 ,
149 y: 10 ,
150 } ) ;
151
152 new termkit.Button( {
153 parent: sub2 ,
154 content: '<...>' ,
155 value: '...' ,
156 x: 40 ,
157 y: 10 ,
158 } ) ;
159
160var C = new termkit.Button( {
161 parent: document ,
162 content: '<C>' ,
163 value: 'C' ,
164 x: 0 ,
165 y: 12 ,
166} ) ;
167
168new termkit.Button( {
169 parent: C ,
170 content: '<1>' ,
171 value: '1' ,
172 x: 10 ,
173 y: 12 ,
174} ) ;
175
176new termkit.Button( {
177 parent: C ,
178 content: '<2>' ,
179 value: '2' ,
180 x: 10 ,
181 y: 14 ,
182} ) ;
183
184var sub3 = new termkit.Button( {
185 parent: C ,
186 content: '<3>' ,
187 value: '3' ,
188 x: 10 ,
189 y: 16 ,
190} ) ;
191
192 new termkit.Button( {
193 parent: sub3 ,
194 content: '<...>' ,
195 value: '...' ,
196 x: 20 ,
197 y: 16 ,
198 } ) ;
199
200 new termkit.Button( {
201 parent: sub3 ,
202 content: '<...>' ,
203 value: '...' ,
204 x: 30 ,
205 y: 16 ,
206 } ) ;
207
208 new termkit.Button( {
209 parent: sub3 ,
210 content: '<...>' ,
211 value: '...' ,
212 x: 40 ,
213 y: 16 ,
214 } ) ;
215
216
217term.on( 'key' , function( key ) {
218 switch( key )
219 {
220 case 'CTRL_C' :
221 term.grabInput( false ) ;
222 term.hideCursor( false ) ;
223 term.styleReset() ;
224 term.clear() ;
225 process.exit() ;
226 break ;
227 }
228} ) ;
229
230
231