1 |
|
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 | ;
|
29 |
|
30 |
|
31 |
|
32 | //console.error( "\n\n\n\n\n\n\n\n" ) ;
|
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 | palette: new termkit.Palette()
|
42 | // backgroundAttr: { bgColor: 'magenta' , dim: true } ,
|
43 | } ) ;
|
44 |
|
45 | var textBox = new termkit.TextBox( {
|
46 | parent: document ,
|
47 | //content: '^#^MHe^:^bll^#^Ro!' ,
|
48 | content: '^[fg:*royal-blue]royal!' ,
|
49 | //content: 'royal!' ,
|
50 | contentHasMarkup: true ,
|
51 | //attr: { color: 'magenta' } ,
|
52 | //attr: { color: 241 } ,
|
53 | //attr: { color: '*royal-blue' } ,
|
54 | //hidden: true ,
|
55 | scrollable: true ,
|
56 | vScrollBar: true ,
|
57 | x: 10 ,
|
58 | y: 2 ,
|
59 | width: 30 ,
|
60 | height: 10
|
61 | } ) ;
|
62 |
|
63 |
|
64 | term.on( 'key' , function( key ) {
|
65 |
|
66 | switch( key ) {
|
67 | case 'CTRL_C' :
|
68 | term.grabInput( false ) ;
|
69 | term.hideCursor( false ) ;
|
70 | term.styleReset() ;
|
71 | term.clear() ;
|
72 | process.exit() ;
|
73 | break ;
|
74 |
|
75 | case 'ENTER' :
|
76 | case 'KP_ENTER' :
|
77 | textBox.setContent( textBox.getContent() + '\n' ) ;
|
78 | break ;
|
79 |
|
80 | case 'BACKSPACE' :
|
81 | case 'DELETE' :
|
82 | textBox.setContent( textBox.getContent().split( '\n' ).slice( 0 , -1 ).join( '\n' ) ) ;
|
83 | break ;
|
84 |
|
85 | case 'PAGE_DOWN' :
|
86 | case 'PAGE_UP' :
|
87 | case 'CTRL_O' :
|
88 | break ;
|
89 |
|
90 | default :
|
91 | textBox.setContent( textBox.getContent() + key ) ;
|
92 | break ;
|
93 | }
|
94 | } ) ;
|
95 |
|