mirror of
https://github.com/manifoldco/promptui.git
synced 2026-03-14 22:35:53 +01:00
Merge branch 'master' into bdwyertech
This commit is contained in:
commit
fd5822cb85
4 changed files with 27 additions and 8 deletions
12
cursor.go
12
cursor.go
|
|
@ -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.
|
||||
|
|
@ -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) {
|
||||
|
|
@ -195,7 +203,7 @@ func (c *Cursor) Listen(line []rune, pos int, key rune) ([]rune, int, bool) {
|
|||
case 0: // empty
|
||||
case KeyEnter:
|
||||
return []rune(c.Get()), c.Position, false
|
||||
case KeyBackspace:
|
||||
case KeyBackspace, KeyCtrlH:
|
||||
if c.erase {
|
||||
c.erase = false
|
||||
c.Replace("")
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ var (
|
|||
// KeyEnter is the default key for submission/selection.
|
||||
KeyEnter rune = readline.CharEnter
|
||||
|
||||
// KeyCtrlH is the key for deleting input text.
|
||||
KeyCtrlH rune = readline.CharCtrlH
|
||||
|
||||
// KeyPrev is the default key to go up during selection.
|
||||
KeyPrev rune = readline.CharPrev
|
||||
KeyPrevDisplay = "↑"
|
||||
|
|
|
|||
18
prompt.go
18
prompt.go
|
|
@ -33,6 +33,9 @@ type Prompt struct {
|
|||
// allows hiding private information like passwords.
|
||||
Mask rune
|
||||
|
||||
// HideEntered sets whether to hide the text after the user has pressed enter.
|
||||
HideEntered bool
|
||||
|
||||
// Templates can be used to customize the prompt output. If nil is passed, the
|
||||
// default templates are used. See the PromptTemplates docs for more info.
|
||||
Templates *PromptTemplates
|
||||
|
|
@ -218,9 +221,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)
|
||||
|
|
@ -234,9 +237,14 @@ func (p *Prompt) Run() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
sb.Reset()
|
||||
sb.Write(prompt)
|
||||
sb.Flush()
|
||||
if p.HideEntered {
|
||||
clearScreen(sb)
|
||||
} else {
|
||||
sb.Reset()
|
||||
sb.Write(prompt)
|
||||
sb.Flush()
|
||||
}
|
||||
|
||||
rl.Write([]byte(showCursor))
|
||||
rl.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
|
|||
} else {
|
||||
searchMode = true
|
||||
}
|
||||
case key == KeyBackspace:
|
||||
case key == KeyBackspace || key == KeyCtrlH:
|
||||
if !canSearch || !searchMode {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue