Add files via upload

This commit is contained in:
公明
2026-03-06 20:11:22 +08:00
committed by GitHub
parent d9a0178f80
commit 27830d1399
4 changed files with 21 additions and 6 deletions

View File

@@ -96,7 +96,7 @@ func (h *TerminalHandler) RunCommand(c *gin.Context) {
} else {
cmd = exec.CommandContext(ctx, shell, "-c", cmdStr)
// 无 TTY 时设置 COLUMNS/TERM使 ping 等工具的 usage 排版与真实终端一致
cmd.Env = append(os.Environ(), "COLUMNS=120", "LINES=40", "TERM=xterm-256color")
cmd.Env = append(os.Environ(), "COLUMNS=256", "LINES=40", "TERM=xterm-256color")
}
if req.Cwd != "" {
@@ -218,7 +218,7 @@ func (h *TerminalHandler) RunCommandStream(c *gin.Context) {
cmd = exec.CommandContext(ctx, "cmd", "/c", cmdStr)
} else {
cmd = exec.CommandContext(ctx, shell, "-c", cmdStr)
cmd.Env = append(os.Environ(), "COLUMNS=120", "LINES=40", "TERM=xterm-256color")
cmd.Env = append(os.Environ(), "COLUMNS=256", "LINES=40", "TERM=xterm-256color")
}
if req.Cwd != "" {
absCwd, err := filepath.Abs(req.Cwd)

View File

@@ -11,7 +11,7 @@ import (
"github.com/creack/pty"
)
const ptyCols = 120
const ptyCols = 256
const ptyRows = 40
// runCommandStreamImpl 在 Unix 下用 PTY 执行,使 ping 等命令按终端宽度排版isatty 为真)

View File

@@ -37,7 +37,7 @@ func (h *TerminalHandler) RunCommandWS(c *gin.Context) {
}
cmd := exec.Command(shell)
cmd.Env = append(os.Environ(),
"COLUMNS=120",
"COLUMNS=256",
"LINES=40",
"TERM=xterm-256color",
)
@@ -55,7 +55,7 @@ func (h *TerminalHandler) RunCommandWS(c *gin.Context) {
for {
n, err := ptmx.Read(buf)
if n > 0 {
_ = conn.WriteMessage(websocket.TextMessage, buf[:n])
_ = conn.WriteMessage(websocket.BinaryMessage, buf[:n])
}
if err != nil {
break

View File

@@ -100,7 +100,22 @@
ws.onmessage = function (ev) {
if (!tab.term) return;
tab.term.write(ev.data);
// 处理二进制消息和文本消息
if (ev.data instanceof ArrayBuffer) {
var decoder = new TextDecoder('utf-8');
tab.term.write(decoder.decode(ev.data));
} else if (ev.data instanceof Blob) {
// Blob 类型,需要异步读取
var reader = new FileReader();
reader.onload = function () {
var decoder = new TextDecoder('utf-8');
tab.term.write(decoder.decode(reader.result));
};
reader.readAsArrayBuffer(ev.data);
} else {
// 字符串类型
tab.term.write(ev.data);
}
};
ws.onclose = function () {