diff --git a/backend/services/adminreset/client.go b/backend/services/adminreset/client.go index 23226b9..9cf1091 100644 --- a/backend/services/adminreset/client.go +++ b/backend/services/adminreset/client.go @@ -52,10 +52,11 @@ func SendVerifiedReset(ctx context.Context, conn net.Conn, input func(string) (s return ErrInvalidRequest } var prompt strings.Builder - prompt.WriteString("请选择安全验证方式(输入序号;选择邮箱即发送验证码):") + prompt.WriteString("请选择安全验证方式\n\n") for i, method := range challenge.Methods { - fmt.Fprintf(&prompt, " %d.%s", i+1, method.Label) + fmt.Fprintf(&prompt, "%d. %s\n", i+1, method.Label) } + prompt.WriteString("\n选项:") choice, err := input(prompt.String()) if err != nil { return err diff --git a/backend/services/adminreset/password_linux.go b/backend/services/adminreset/password_linux.go index e7669e8..fbba0e5 100644 --- a/backend/services/adminreset/password_linux.go +++ b/backend/services/adminreset/password_linux.go @@ -6,6 +6,7 @@ import ( "errors" "io" "os/exec" + "strings" "git.pcux.cn/xuans/Smail/utils/password" ) @@ -45,6 +46,8 @@ func ReadVisibleInput(prompt string) (string, error) { } func readSystemdInput(prompt, echo string) (string, error) { + // systemd 代理把提示保存在单行配置中,用终端换行控制显示列表,避免配置被拆行。 + prompt = strings.ReplaceAll(strings.ReplaceAll(prompt, "\r\n", "\n"), "\n", "\x1bE") command := exec.Command("systemd-ask-password", "--no-tty", "--echo="+echo, prompt) command.Stderr = io.Discard output, err := command.Output() diff --git a/backend/services/adminreset/password_windows.go b/backend/services/adminreset/password_windows.go index dac8ce9..d6945cd 100644 --- a/backend/services/adminreset/password_windows.go +++ b/backend/services/adminreset/password_windows.go @@ -60,7 +60,7 @@ func ReadVisibleInput(prompt string) (string, error) { if !term.IsTerminal(int(os.Stdin.Fd())) { return "", errors.New("安全验证需要交互式控制台") } - fmt.Fprint(os.Stderr, prompt+": ") + fmt.Fprint(os.Stderr, strings.TrimRight(prompt, ":: ")+": ") value, err := bufio.NewReader(os.Stdin).ReadString('\n') if err != nil { return "", errors.New("读取安全验证输入失败")