Skip to content

Commit

Permalink
Merge pull request #147 from jamesdobson/master
Browse files Browse the repository at this point in the history
Fixed echo of cursor after input is finished. (fixes #117)
  • Loading branch information
jbowes committed Sep 28, 2020
2 parents 85345fc + c2f558a commit ff07e3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion cursor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package promptui

import "fmt"
import (
"fmt"
"strings"
)

// Pointer is A specific type that translates a given set of runes into a given
// set of runes pointed at by the cursor.
Expand Down Expand Up @@ -144,6 +147,11 @@ func (c *Cursor) Get() string {
return string(c.input)
}

// GetMask returns a mask string with length equal to the input
func (c *Cursor) GetMask(mask rune) string {
return strings.Repeat(string(mask), len(c.input))
}

// Replace replaces the previous input with whatever is specified, and moves the
// cursor to the end position
func (c *Cursor) Replace(input string) {
Expand Down
4 changes: 2 additions & 2 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func (p *Prompt) Run() (string, error) {
return "", err
}

echo := cur.Format()
echo := cur.Get()
if p.Mask != 0 {
echo = cur.FormatMask(p.Mask)
echo = cur.GetMask(p.Mask)
}

prompt := render(p.Templates.success, p.Label)
Expand Down

0 comments on commit ff07e3d

Please sign in to comment.