From f10dc342f763b8463a13e7d1aef57778bc15c5a8 Mon Sep 17 00:00:00 2001 From: smail Date: Sat, 19 Sep 2026 22:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E7=AE=A1=E7=90=86=E5=91=98=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E9=AA=8C=E8=AF=81=E6=96=B9=E5=BC=8F=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/adminreset/client.go | 5 +++-- backend/services/adminreset/password_linux.go | 3 +++ backend/services/adminreset/password_windows.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) 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("读取安全验证输入失败")