Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"strings"
"sync"
"text/template"

"github.com/chzyer/readline"
Expand Down Expand Up @@ -157,10 +158,14 @@ func (p *Prompt) Run() (string, error) {
}
eraseDefault := input != "" && !p.AllowEdit
cur := NewCursor(input, p.Pointer, eraseDefault)
var curLock sync.Mutex

listen := func(input []rune, pos int, key rune) ([]rune, int, bool) {
defer curLock.Unlock()
curLock.Lock()
_, _, keepOn := cur.Listen(input, pos, key)
err := validFn(cur.Get())

var prompt []byte

if err != nil {
Expand Down Expand Up @@ -193,7 +198,10 @@ func (p *Prompt) Run() (string, error) {

for {
_, err = rl.Readline()
curLock.Lock()
inputErr = validFn(cur.Get())
curLock.Unlock()

if inputErr == nil {
break
}
Expand All @@ -203,6 +211,8 @@ func (p *Prompt) Run() (string, error) {
}
}

defer curLock.Unlock()
curLock.Lock()
if err != nil {
switch err {
case readline.ErrInterrupt:
Expand Down
7 changes: 6 additions & 1 deletion select.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"sync"
"text/template"

"github.com/chzyer/readline"
Expand Down Expand Up @@ -246,6 +247,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
rl.Write([]byte(hideCursor))
sb := screenbuf.New(rl)

var curLock sync.Mutex
cur := NewCursor("", s.Pointer, false)

canSearch := s.Searcher != nil
Expand All @@ -254,6 +256,8 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
s.list.SetStart(scroll)

c.SetListener(func(line []rune, pos int, key rune) ([]rune, int, bool) {
defer curLock.Unlock()
curLock.Lock()
switch {
case key == KeyEnter:
return nil, 0, true
Expand Down Expand Up @@ -372,7 +376,8 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
}

}

defer curLock.Unlock()
curLock.Lock()
if err != nil {
if err.Error() == "Interrupt" {
err = ErrInterrupt
Expand Down