File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ type Actions interface {
14
14
ReadLine () string
15
15
// ReadLineErr is ReadLine but returns error as well
16
16
ReadLineErr () (string , error )
17
+ // ReadLineWithDefault reads a line from standard input with default value.
18
+ ReadLineWithDefault (string ) string
17
19
// ReadPassword reads password from standard input without echoing the characters.
18
20
// Note that this only works as expected when the standard input is a terminal.
19
21
ReadPassword () string
@@ -85,6 +87,13 @@ func (s *shellActionsImpl) ReadLineErr() (string, error) {
85
87
return s .readLine ()
86
88
}
87
89
90
+ func (s * shellActionsImpl ) ReadLineWithDefault (defaultValue string ) string {
91
+ s .reader .defaultValue = defaultValue
92
+ line , _ := s .readLine ()
93
+ s .reader .defaultValue = ""
94
+ return line
95
+ }
96
+
88
97
func (s * shellActionsImpl ) ReadPassword () string {
89
98
return s .reader .readPassword ()
90
99
}
Original file line number Diff line number Diff line change 25
25
showPrompt bool
26
26
completer readline.AutoCompleter
27
27
sync.Mutex
28
+ defaultValue string
28
29
}
29
30
)
30
31
@@ -87,7 +88,7 @@ func (s *shellReader) readLine(consumer chan lineString) {
87
88
// use printed statement as prompt
88
89
s .scanner .SetPrompt (prompt )
89
90
90
- line , err := s .scanner .Readline ( )
91
+ line , err := s .scanner .ReadlineWithDefault ( s . defaultValue )
91
92
92
93
// reset prompt
93
94
s .scanner .SetPrompt (shellPrompt )
You can’t perform that action at this time.
0 commit comments