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 | "use strict" ;
|
28 |
|
29 | var term = require( 'terminal-kit' ).terminal ;
|
30 |
|
31 | term( '> ' ) ;
|
32 |
|
33 | var autoComplete = [
|
34 | 'dnf install' ,
|
35 | 'dnf install nodejs' ,
|
36 | 'dnf search' ,
|
37 | 'sudo' ,
|
38 | 'sudo dnf install' ,
|
39 | 'sudo dnf install nodejs' ,
|
40 | 'sudo dnf search' ,
|
41 | ] ;
|
42 |
|
43 | term.inputField(
|
44 | {
|
45 | autoComplete: autoComplete ,
|
46 | autoCompleteHint: true ,
|
47 | autoCompleteMenu: true ,
|
48 | tokenHook: function( token , isEndOfInput , previousTokens , term , config ) {
|
49 | var previousText = previousTokens.join( ' ' ) ;
|
50 |
|
51 | switch ( token )
|
52 | {
|
53 | case 'sudo' :
|
54 | config.style = term.red ;
|
55 | return previousTokens.length ? null : term.bold.red ;
|
56 | case 'dnf' :
|
57 | return previousText === '' || previousText === 'sudo' ? term.brightMagenta : null ;
|
58 | case 'install' :
|
59 | config.style = term.brightBlue ;
|
60 | config.hintStyle = term.brightBlack.italic ;
|
61 | return previousText === 'dnf' || previousText === 'sudo dnf' ? term.brightYellow : null ;
|
62 | case 'search' :
|
63 | config.style = term.brightBlue ;
|
64 | return previousText === 'dnf' || previousText === 'sudo dnf' ? term.brightCyan : null ;
|
65 | }
|
66 | }
|
67 | } ,
|
68 | function( error , input ) {
|
69 |
|
70 | term.green( "\nYour command is: '%s'\n" , input ) ;
|
71 | process.exit() ;
|
72 | }
|
73 | ) ;
|
74 |
|
75 |
|
76 |
|
77 | term.on( 'key' , function( key ) {
|
78 | if ( key === 'CTRL_C' )
|
79 | {
|
80 | term.green( 'CTRL-C detected...\n' ) ;
|
81 | terminate() ;
|
82 | }
|
83 | } ) ;
|
84 |
|
85 |
|
86 |
|
87 | function terminate()
|
88 | {
|
89 | term.grabInput( false ) ;
|
90 |
|
91 | setTimeout( function() { process.exit() ; } , 100 ) ;
|
92 | }
|
93 |
|