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( 'shell> ' ) ;
|
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 | term.green( "\nYour command is: '%s'\n" , input ) ;
|
70 | process.exit() ;
|
71 | }
|
72 | ) ;
|