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 {
1414 ReadLine () string
1515 // ReadLineErr is ReadLine but returns error as well
1616 ReadLineErr () (string , error )
17+ // ReadLineWithDefault reads a line from standard input with default value.
18+ ReadLineWithDefault (string ) string
1719 // ReadPassword reads password from standard input without echoing the characters.
1820 // Note that this only works as expected when the standard input is a terminal.
1921 ReadPassword () string
@@ -85,6 +87,13 @@ func (s *shellActionsImpl) ReadLineErr() (string, error) {
8587 return s .readLine ()
8688}
8789
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+
8897func (s * shellActionsImpl ) ReadPassword () string {
8998 return s .reader .readPassword ()
9099}
Original file line number Diff line number Diff line change 2525 showPrompt bool
2626 completer readline.AutoCompleter
2727 sync.Mutex
28+ defaultValue string
2829 }
2930)
3031
@@ -87,7 +88,7 @@ func (s *shellReader) readLine(consumer chan lineString) {
8788 // use printed statement as prompt
8889 s .scanner .SetPrompt (prompt )
8990
90- line , err := s .scanner .Readline ( )
91+ line , err := s .scanner .ReadlineWithDefault ( s . defaultValue )
9192
9293 // reset prompt
9394 s .scanner .SetPrompt (shellPrompt )
You can’t perform that action at this time.
0 commit comments