Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new InputWithExit api to indicate when an exit was requested #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added new InputWithExit api to indicate when an exit was requested
Philip Stefou committed Nov 26, 2022
commit 989f64499a160fca15e2bb2d9185d21330e7dab6
11 changes: 9 additions & 2 deletions prompt.go
Original file line number Diff line number Diff line change
@@ -231,6 +231,13 @@ func (p *Prompt) handleASCIICodeBinding(b []byte) bool {

// Input just returns user input text.
func (p *Prompt) Input() string {
input, _ := p.InputWithExit()

return input
}

// InputWithExit returns user input text along with a signal indicating if an exit was requested.
func (p *Prompt) InputWithExit() (string, bool) {
defer debug.Teardown()
debug.Log("start prompt")
p.setUp()
@@ -251,11 +258,11 @@ func (p *Prompt) Input() string {
if shouldExit, e := p.feed(b); shouldExit {
p.renderer.BreakLine(p.buf)
stopReadBufCh <- struct{}{}
return ""
return "", shouldExit
} else if e != nil {
// Stop goroutine to run readBuffer function
stopReadBufCh <- struct{}{}
return e.input
return e.input, false
} else {
p.completion.Update(*p.buf.Document())
p.renderer.Render(p.buf, p.completion)