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 | const termkit = require( '../../lib/termkit.js' ) ;
|
33 | const term = termkit.terminal ;
|
34 |
|
35 |
|
36 |
|
37 | term.clear() ;
|
38 |
|
39 | var document = term.createDocument() ;
|
40 |
|
41 | var inlineInput = new termkit.InlineInput( {
|
42 | parent: document ,
|
43 | textAttr: { bgColor: 'blue' } ,
|
44 | voidAttr: { bgColor: 'blue' } ,
|
45 | placeholder: 'Your name here' ,
|
46 | x: 0 ,
|
47 | y: 10 ,
|
48 | prompt: {
|
49 | textAttr: { bgColor: 'blue' } ,
|
50 | content: '^R^+a big ^Gbig ^Ybig ^Rprompt> ' ,
|
51 | contentHasMarkup: true
|
52 | } ,
|
53 |
|
54 | width: 36 ,
|
55 | cancelable: true ,
|
56 | history: [ 'Bob' , 'Bill' , 'Jack' , 'Some entry string' ] ,
|
57 | autoComplete: [ 'Barack Obama' , 'George W. Bush' , 'Bill Clinton' , 'George Bush' , 'Ronald W. Reagan' , 'Jimmy Carter' , 'Gerald Ford' , 'Richard Nixon' , 'Lyndon Johnson' , 'John F. Kennedy' , 'Dwight Eisenhower' , 'Harry Truman' , 'Franklin Roosevelt' ] ,
|
58 | autoCompleteMenu: true ,
|
59 | autoCompleteHint: true ,
|
60 | } ) ;
|
61 |
|
62 | inlineInput.on( 'submit' , onSubmit ) ;
|
63 |
|
64 | function onSubmit( value ) {
|
65 |
|
66 | term.saveCursor() ;
|
67 | term.moveTo.styleReset.eraseLine( 1 , 22 , "Submitted: '%s'\n" , value ) ;
|
68 | term.restoreCursor() ;
|
69 | }
|
70 |
|
71 | inlineInput.on( 'cancel' , onCancel ) ;
|
72 |
|
73 | function onCancel() {
|
74 |
|
75 | term.saveCursor() ;
|
76 | term.moveTo.styleReset.eraseLine( 1 , 22 , 'Canceled\n' ) ;
|
77 | term.restoreCursor() ;
|
78 | }
|
79 |
|
80 | document.focusNext() ;
|
81 |
|
82 |
|
83 |
|
84 | term.on( 'key' , function( key ) {
|
85 | switch( key ) {
|
86 | case 'CTRL_C' :
|
87 | term.grabInput( false ) ;
|
88 | term.hideCursor( false ) ;
|
89 | term.styleReset() ;
|
90 | term.clear() ;
|
91 | process.exit() ;
|
92 | break ;
|
93 | }
|
94 | } ) ;
|
95 |
|