Skip to content

Commit e012787

Browse files
delaneyjabiosoft
authored andcommitted
copy changes from #102 (#103)
1 parent 3651a08 commit e012787

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

actions.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
8897
func (s *shellActionsImpl) ReadPassword() string {
8998
return s.reader.readPassword()
9099
}

reader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type (
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)

0 commit comments

Comments
 (0)