Skip to content

Commit

Permalink
set initial value on edit
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzz1y committed Jan 12, 2023
1 parent 11ba6d9 commit 267d347
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/mcli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func run(*cli.Context) error {
}

func add(*cli.Context) error {
nameField, err := prompt.InputPromptString(nameFieldText)
nameField, err := prompt.InputPromptString(nameFieldText, "")
if err != nil {
return err
}

commandField, err := prompt.InputPromptString(commandFieldText)
commandField, err := prompt.InputPromptString(commandFieldText, "")
if err != nil {
return err
}
Expand All @@ -44,12 +44,12 @@ func edit(*cli.Context) error {
return err
}

nameField, err := prompt.InputPromptString(nameFieldText)
nameField, err := prompt.InputPromptString(nameFieldText, cfg.Shortcuts[index].Name)
if err != nil {
return err
}

commandField, err := prompt.InputPromptString(commandFieldText)
commandField, err := prompt.InputPromptString(commandFieldText, cfg.Shortcuts[index].Cmd)
if err != nil {
return err
}
Expand All @@ -70,7 +70,7 @@ func delete(*cli.Context) error {
}

func setPromptSize(*cli.Context) error {
size, err := prompt.InputPromptInt(sizeFieldText)
size, err := prompt.InputPromptInt(sizeFieldText, cfg.PromptSize)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
"github.com/erikgeiser/promptkit/textinput"
)

func InputPromptInt(label string) (string, error) {
func InputPromptInt(label string, initValue int) (string, error) {
input := textinput.New(label + ":")
input.Placeholder = IntPlaceholderText
input.Validate = intValidator
input.InitialValue = strconv.Itoa(initValue)

return input.RunPrompt()
}

func InputPromptString(label string) (string, error) {
func InputPromptString(label string, initValue string) (string, error) {
input := textinput.New(label + ":")
input.Placeholder = StringPlaceholderText
input.InitialValue = initValue

return input.RunPrompt()
}
Expand Down

0 comments on commit 267d347

Please sign in to comment.