Skip to content

Commit

Permalink
Fixed echo of cursor after input is finished. (fixes manifoldco#117)
Browse files Browse the repository at this point in the history
Based on: manifoldco#118 by github.com/richardmcsong,
taking only the changes required to fix issue manifoldco#117.
  • Loading branch information
jamesdobson committed Apr 18, 2020
1 parent e15db71 commit c2f558a
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 c2f558a

Please sign in to comment.