@@ -8,6 +8,7 @@ class InputHandler {
8
8
9
9
async getInput ( ) {
10
10
return new Promise ( ( resolve ) => {
11
+ let tabCounter = 0 ;
11
12
const onKeypress = ( char , key ) => {
12
13
if ( key . name === 'return' || key . name === 'enter' ) {
13
14
this . readline . input . removeListener ( 'keypress' , onKeypress ) ;
@@ -22,22 +23,33 @@ class InputHandler {
22
23
// Autocomplete if there's only one suggestion
23
24
this . inputBuffer = suggestions [ 0 ] + ' ' ;
24
25
this . readline . write ( null , { ctrl : true , name : 'u' } ) ; // Clear the current line
25
- this . readline . write ( this . inputBuffer ) ; // Write the autocompleted input
26
+ this . readline . write ( this . inputBuffer ) ;
26
27
} else if ( suggestions . length > 1 ) {
27
- console . log ( '\n' + suggestions . join ( ' ' ) ) ;
28
- this . readline . write ( null , { ctrl : true , name : 'u' } ) ;
29
- this . readline . prompt ( ) ;
30
- this . readline . write ( this . inputBuffer ) ; // Reprint the current input
28
+ if ( tabCounter === 0 ) {
29
+ // First <TAB> press: ring the bell
30
+ process . stdout . write ( '\x07' ) ;
31
+ this . readline . write ( null , { ctrl : true , name : 'u' } ) ;
32
+ this . readline . write ( this . inputBuffer ) ;
33
+ tabCounter ++ ;
34
+ } else {
35
+ // Second <TAB> press: display suggestions
36
+ console . log ( '\n' + suggestions . join ( ' ' ) ) ;
37
+ this . readline . write ( null , { ctrl : true , name : 'u' } ) ;
38
+ this . readline . prompt ( ) ;
39
+ this . readline . write ( this . inputBuffer ) ;
40
+ tabCounter = 0 ;
41
+ }
31
42
} else {
32
43
// No valid suggestions, ring the bell
33
44
process . stdout . write ( '\x07' ) ;
34
- this . readline . write ( null , { ctrl : true , name : 'u' } ) ; // Clear the current line
45
+ this . readline . write ( null , { ctrl : true , name : 'u' } ) ;
35
46
this . readline . write ( this . inputBuffer ) ;
47
+ tabCounter = 0 ;
36
48
}
37
49
} else if ( key . name === 'backspace' ) {
38
50
// Handle Backspace
39
51
this . inputBuffer = this . inputBuffer . slice ( 0 , - 1 ) ;
40
- this . readline . write ( null , { ctrl : true , name : 'u' } ) ; // Clear the current line
52
+ this . readline . write ( null , { ctrl : true , name : 'u' } ) ;
41
53
this . readline . write ( this . inputBuffer ) ;
42
54
} else {
43
55
// Add the normal character pressed, to the input buffer
0 commit comments