show message even for password asks

This commit is contained in:
Kovid Goyal
2023-03-07 13:52:01 +05:30
parent f4b0fbc61e
commit 4cef83ffd0

View File

@@ -3,14 +3,23 @@
package ask package ask
import ( import (
"errors"
"fmt" "fmt"
"kitty/tools/cli" "kitty/tools/cli"
"kitty/tools/cli/markup"
"kitty/tools/tui" "kitty/tools/tui"
) )
var _ = fmt.Print var _ = fmt.Print
func show_message(msg string) {
if msg != "" {
m := markup.New(true)
fmt.Println(m.Bold(msg))
}
}
func main(_ *cli.Command, o *Options, args []string) (rc int, err error) { func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
output := tui.KittenOutputSerializer() output := tui.KittenOutputSerializer()
var result any var result any
@@ -21,13 +30,19 @@ func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
case "yesno", "choices": case "yesno", "choices":
result, err = choices(o, args) result, err = choices(o, args)
if err != nil { if err != nil {
return rc, err return 1, err
} }
case "password": case "password":
result, err = tui.ReadPassword(o.Prompt, true) show_message(o.Message)
pw, err := tui.ReadPassword(o.Prompt, true)
if err != nil { if err != nil {
return rc, err if errors.Is(err, tui.Canceled) {
pw = ""
} else {
return 1, err
}
} }
result = map[string]any{"items": args, "response": pw}
default: default:
return 1, fmt.Errorf("Unknown type: %s", o.Type) return 1, fmt.Errorf("Unknown type: %s", o.Type)
} }