UNPKG

2.99 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//console.error( "\n\n\n\n\n\n\n\n" ) ;
33var termkit = require( '../../lib/termkit.js' ) ;
34var term = termkit.terminal ;
35
36
37
38term.clear() ;
39
40var document = term.createDocument( {
41 // backgroundAttr: { bgColor: 'magenta' , dim: true } ,
42} ) ;
43
44var text = new termkit.Text( {
45 parent: document ,
46 content: 'Some text' ,
47 x: 40 ,
48 y: 2 ,
49} ) ;
50
51var button1 = new termkit.Button( {
52 parent: document ,
53 content: '> bob' ,
54 value: 'bob' ,
55 x: 10 ,
56 y: 10 ,
57} ) ;
58
59var button2 = new termkit.Button( {
60 parent: document ,
61 content: '> bill' ,
62 value: 'bill' ,
63 x: 13 ,
64 y: 12 ,
65} ) ;
66
67var textInput1 = new termkit.LabeledInput( {
68 parent: document ,
69 label: 'First name: ' ,
70 x: 5 ,
71 y: 16 ,
72 width: 30 ,
73} ) ;
74
75var textInput2 = new termkit.LabeledInput( {
76 parent: document ,
77 label: 'Last name: ' ,
78 x: 15 ,
79 y: 18 ,
80 width: 30 ,
81} ) ;
82
83var 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//container1.inputDst.fill( { char: ' ' , attr: { bgColor: 'yellow' } } ) ;
93
94var button3 = new termkit.Button( {
95 parent: container1 ,
96 content: '> jack' ,
97 value: 'jack' ,
98 x: 2 ,
99 y: 2 ,
100} ) ;
101
102//container1.draw() ;
103
104textInput2.on( 'submit' , onSubmit ) ;
105textInput1.on( 'submit' , onSubmit ) ;
106button3.on( 'submit' , onSubmit ) ;
107button2.on( 'submit' , onSubmit ) ;
108button1.on( 'submit' , onSubmit ) ;
109
110function onSubmit( value ) {
111 //console.error( 'Submitted: ' , value ) ;
112 term.saveCursor() ;
113 term.moveTo.styleReset.eraseLine( 1 , 22 , 'Submitted: %s\n' , value ) ;
114 term.restoreCursor() ;
115}
116
117
118
119document.focusNext() ;
120
121
122
123term.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