1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | "use strict" ;
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var termkit = require( '../../lib/termkit.js' ) ;
|
34 | var term = termkit.terminal ;
|
35 |
|
36 |
|
37 |
|
38 | term.clear() ;
|
39 |
|
40 | var document = term.createDocument( {
|
41 |
|
42 | } ) ;
|
43 |
|
44 | var text = new termkit.Text( {
|
45 | parent: document ,
|
46 | content: 'Some text' ,
|
47 | x: 40 ,
|
48 | y: 2 ,
|
49 | } ) ;
|
50 |
|
51 | var button1 = new termkit.Button( {
|
52 | parent: document ,
|
53 | content: '> bob' ,
|
54 | value: 'bob' ,
|
55 | x: 10 ,
|
56 | y: 10 ,
|
57 | } ) ;
|
58 |
|
59 | var button2 = new termkit.Button( {
|
60 | parent: document ,
|
61 | content: '> bill' ,
|
62 | value: 'bill' ,
|
63 | x: 13 ,
|
64 | y: 12 ,
|
65 | } ) ;
|
66 |
|
67 | var textInput1 = new termkit.LabeledInput( {
|
68 | parent: document ,
|
69 | label: 'First name: ' ,
|
70 | x: 5 ,
|
71 | y: 16 ,
|
72 | width: 30 ,
|
73 | } ) ;
|
74 |
|
75 | var textInput2 = new termkit.LabeledInput( {
|
76 | parent: document ,
|
77 | label: 'Last name: ' ,
|
78 | x: 15 ,
|
79 | y: 18 ,
|
80 | width: 30 ,
|
81 | } ) ;
|
82 |
|
83 | var container1 = new termkit.Container( {
|
84 | parent: document ,
|
85 | x: 50 ,
|
86 | y: 8 ,
|
87 | width: 30 ,
|
88 | height: 10 ,
|
89 | backgroundAttr: { bgColor: 'yellow' } ,
|
90 | } ) ;
|
91 |
|
92 |
|
93 |
|
94 | var button3 = new termkit.Button( {
|
95 | parent: container1 ,
|
96 | content: '> jack' ,
|
97 | value: 'jack' ,
|
98 | x: 2 ,
|
99 | y: 2 ,
|
100 | } ) ;
|
101 |
|
102 |
|
103 |
|
104 | textInput2.on( 'submit' , onSubmit ) ;
|
105 | textInput1.on( 'submit' , onSubmit ) ;
|
106 | button3.on( 'submit' , onSubmit ) ;
|
107 | button2.on( 'submit' , onSubmit ) ;
|
108 | button1.on( 'submit' , onSubmit ) ;
|
109 |
|
110 | function onSubmit( value ) {
|
111 |
|
112 | term.saveCursor() ;
|
113 | term.moveTo.styleReset.eraseLine( 1 , 22 , 'Submitted: %s\n' , value ) ;
|
114 | term.restoreCursor() ;
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 | document.focusNext() ;
|
120 |
|
121 |
|
122 |
|
123 | term.on( 'key' , function( key ) {
|
124 | switch( key )
|
125 | {
|
126 | case 'CTRL_C' :
|
127 | term.grabInput( false ) ;
|
128 | term.hideCursor( false ) ;
|
129 | term.styleReset() ;
|
130 | term.clear() ;
|
131 | process.exit() ;
|
132 | break ;
|
133 | }
|
134 | } ) ;
|
135 |
|