1
0
Files
Skill/manager/internal/prompt/prompt.go

40 lines
791 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package prompt
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
// ConfirmWithReader 询问用户确认y/n支持自定义输入源
// 用于测试时注入 mock 输入
func ConfirmWithReader(message string, reader io.Reader) bool {
r := bufio.NewReader(reader)
for {
fmt.Printf("%s [y/N]: ", message)
response, err := r.ReadString('\n')
if err != nil {
return false
}
response = strings.TrimSpace(strings.ToLower(response))
if response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" || response == "" {
return false
}
fmt.Println("请输入 'y' 或 'n'")
}
}
// Confirm 询问用户确认y/n
// 使用标准输入
func Confirm(message string) bool {
return ConfirmWithReader(message, os.Stdin)
}