mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 11:09:22 +08:00
feat: 优化终端进程创建,支持交互模式并添加回退逻辑
This commit is contained in:
@@ -52,8 +52,8 @@ func newTerminalImpl() (*terminalImpl, error) {
|
|||||||
if shell == "" {
|
if shell == "" {
|
||||||
return nil, fmt.Errorf("no supported shell found")
|
return nil, fmt.Errorf("no supported shell found")
|
||||||
}
|
}
|
||||||
// 创建进程
|
// 创建进程: 优先使用交互模式,如不支持则回退
|
||||||
cmd := exec.Command(shell)
|
cmd := exec.Command(shell, "-i")
|
||||||
cmd.Env = append(os.Environ(), // 继承系统环境变量
|
cmd.Env = append(os.Environ(), // 继承系统环境变量
|
||||||
"TERM=xterm-256color",
|
"TERM=xterm-256color",
|
||||||
"LANG=C.UTF-8",
|
"LANG=C.UTF-8",
|
||||||
@@ -61,7 +61,17 @@ func newTerminalImpl() (*terminalImpl, error) {
|
|||||||
)
|
)
|
||||||
tty, err := pty.Start(cmd)
|
tty, err := pty.Start(cmd)
|
||||||
if err != nil {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置初始终端大小
|
// 设置初始终端大小
|
||||||
|
Reference in New Issue
Block a user