From 6e4bd4e4ae1e514c12f4f61a64ded565dc77b30a Mon Sep 17 00:00:00 2001 From: Akizon77 Date: Fri, 6 Jun 2025 18:20:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=BB=88=E7=AB=AF?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E5=88=9B=E5=BB=BA=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E6=A8=A1=E5=BC=8F=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terminal/terminal_unix.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/terminal/terminal_unix.go b/terminal/terminal_unix.go index 89ed2de..1c36477 100644 --- a/terminal/terminal_unix.go +++ b/terminal/terminal_unix.go @@ -52,8 +52,8 @@ func newTerminalImpl() (*terminalImpl, error) { if shell == "" { return nil, fmt.Errorf("no supported shell found") } - // 创建进程 - cmd := exec.Command(shell) + // 创建进程: 优先使用交互模式,如不支持则回退 + cmd := exec.Command(shell, "-i") cmd.Env = append(os.Environ(), // 继承系统环境变量 "TERM=xterm-256color", "LANG=C.UTF-8", @@ -61,7 +61,17 @@ func newTerminalImpl() (*terminalImpl, error) { ) tty, err := pty.Start(cmd) if err != nil { - return nil, fmt.Errorf("failed to start pty: %v", err) + // 交互模式不被支持,回退到无 -i 的启动方式 + cmd = exec.Command(shell) + cmd.Env = append(os.Environ(), + "TERM=xterm-256color", + "LANG=C.UTF-8", + "LC_ALL=C.UTF-8", + ) + tty, err = pty.Start(cmd) + if err != nil { + return nil, fmt.Errorf("failed to start pty with or without -i: %v", err) + } } // 设置初始终端大小