34 lines
598 B
Go
34 lines
598 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/manifoldco/promptui"
|
|
"strconv"
|
|
)
|
|
|
|
func ReadLine(label string, defaultContent string) string {
|
|
for {
|
|
prompt := &promptui.Prompt{
|
|
Label: label,
|
|
Default: defaultContent,
|
|
}
|
|
line, err := prompt.Run()
|
|
if err != nil {
|
|
fmt.Println("输入错误:", err)
|
|
continue
|
|
}
|
|
return line
|
|
}
|
|
}
|
|
func ReadInt(label string, defaultContent string) int {
|
|
for {
|
|
line := ReadLine(label, defaultContent)
|
|
intValue, err := strconv.Atoi(line)
|
|
if err != nil {
|
|
fmt.Println("输入错误, 请输入整数:", err)
|
|
continue
|
|
}
|
|
return intValue
|
|
}
|
|
}
|