Files
aiops/frontend/src/lib/xterm-utils.ts
T
LoganandClaude 76ec9387f0 feat(rdp): 新增 RDP 远程桌面/SMB/账单同步能力 + 清理编译产物
主要变更:
- RDP 远程桌面:新增 backend/pkg/rdp(RDP 引擎 + credssp/display/rle/trace)、
  backend/controller/rdp*(连接/凭证/文件/会话/实时)、frontend RDP 组件与 API
- Windows SMB 文件传输:backend/pkg/winsmb
- 云账单同步:backend/pkg/billingsync + billing_sync/aliyun_billing,前端账单详情
- Agent CLI Kubernetes 工具:kubernetes_action/get、pod_execute/logs
- 服务器导入助手:server_import_helpers、ImportCredentialSettings
- 国际化与组件重构(cloud/deploy/monitor/server/system 等多模块)
- 清理编译产物二进制:移除 backend/server、backend/agent/bin/aiops-agent-*
- .gitignore:新增 backend/agent/ 与 .cache/(避免 334MB go-build 缓存误入库)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-04 01:50:36 +08:00

72 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Terminal as XTerm } from 'xterm';
import type { FitAddon } from 'xterm-addon-fit';
/** FitAddon 适配终端并同步远端 PTY 尺寸(WebSSH resize) // Logan.Li */
export function fitTerminal(fit: FitAddon, term: XTerm, ws?: WebSocket | null) {
fit.fit();
if (ws?.readyState === WebSocket.OPEN) {
const { cols, rows } = term;
if (cols > 0 && rows > 0) {
ws.send(JSON.stringify({ status: 1, cols, rows }));
}
}
}
/** 等待容器就绪后挂载 xterm,并延迟二次 fit 消除右侧黑边 // Logan.Li */
export function mountXterm(
term: XTerm,
fit: FitAddon,
getContainer: () => HTMLDivElement | null,
ws?: WebSocket | null,
) {
const applyFit = () => {
try {
fitTerminal(fit, term, ws);
term.focus();
} catch {
/* noop */
}
};
const tryMount = () => {
const el = getContainer();
if (!el) {
requestAnimationFrame(tryMount);
return;
}
if (!term.element) {
term.open(el);
}
requestAnimationFrame(applyFit);
setTimeout(applyFit, 100);
setTimeout(applyFit, 300);
};
tryMount();
}
/** ResizeObserver 监听容器尺寸,持续 fit // Logan.Li */
export function attachTerminalResize(
container: HTMLDivElement,
fit: FitAddon,
term: XTerm,
ws?: WebSocket | null,
) {
let timer: ReturnType<typeof setTimeout>;
const ro = new ResizeObserver(() => {
clearTimeout(timer);
timer = setTimeout(() => {
try {
fitTerminal(fit, term, ws);
} catch {
/* noop */
}
}, 60);
});
ro.observe(container);
return () => {
clearTimeout(timer);
ro.disconnect();
};
}