From 9ad3c8345013dd2217eafa3114d1c6203bd00b28 Mon Sep 17 00:00:00 2001 From: yaninyzwitty Date: Sat, 23 Aug 2025 10:15:28 +0300 Subject: [PATCH] fix(input): improve askStdin handling for normal and hidden input --- internal/tools/hypertest/exec.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/tools/hypertest/exec.go b/internal/tools/hypertest/exec.go index 4b2731c..2434a11 100644 --- a/internal/tools/hypertest/exec.go +++ b/internal/tools/hypertest/exec.go @@ -15,6 +15,7 @@ package main import ( + "bufio" "errors" "fmt" "io" @@ -25,7 +26,6 @@ import ( "strings" "sync" "sync/atomic" - "syscall" "time" "al.essio.dev/pkg/shellescape" @@ -309,28 +309,33 @@ func (r *runner) runOverSSH(remote string, tests []test) (string, error) { return stdout.String(), nil } +// interactive prompt handler for asking questions on the command line func askStdin(name, instruction string, questions []string, echos []bool) (answers []string, err error) { if len(questions) == 0 && name != "" { fmt.Printf("%s: %s\n", name, instruction) } answers = make([]string, len(questions)) + reader := bufio.NewReader(os.Stdin) // to allow capturing multiple words + for i, q := range questions { fmt.Printf("%s ", q) if echos[i] { - _, err := fmt.Scan("%s", &answers[i]) + // Normal input (echo on) → allow spaces + input, err := reader.ReadString('\n') if err != nil { return nil, err } + answers[i] = strings.TrimSpace(input) continue } - - answer, err := term.ReadPassword(syscall.Stdin) + // Hidden input - use os.Stdin.Fd for portability + answer, err := term.ReadPassword(int(os.Stdin.Fd())) fmt.Println() if err != nil { return nil, err } - answers[i] = string(answer) + answers[i] = strings.TrimSpace(string(answer)) // clean trailing spaces and lines } return answers, nil