Skip to content

Commit c2f558a

Browse files
committed
Fixed echo of cursor after input is finished. (fixes manifoldco#117)
Based on: manifoldco#118 by github.com/richardmcsong, taking only the changes required to fix issue manifoldco#117.
1 parent e15db71 commit c2f558a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cursor.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package promptui
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

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

150+
// GetMask returns a mask string with length equal to the input
151+
func (c *Cursor) GetMask(mask rune) string {
152+
return strings.Repeat(string(mask), len(c.input))
153+
}
154+
147155
// Replace replaces the previous input with whatever is specified, and moves the
148156
// cursor to the end position
149157
func (c *Cursor) Replace(input string) {

prompt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ func (p *Prompt) Run() (string, error) {
218218
return "", err
219219
}
220220

221-
echo := cur.Format()
221+
echo := cur.Get()
222222
if p.Mask != 0 {
223-
echo = cur.FormatMask(p.Mask)
223+
echo = cur.GetMask(p.Mask)
224224
}
225225

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

0 commit comments

Comments
 (0)