fix terminal popup release behavior (#1403)

This commit is contained in:
陈大猫
2026-06-11 14:48:52 +08:00
committed by GitHub
parent afefbd953f
commit 9013a7e312
29 changed files with 705 additions and 84 deletions

View File

@@ -3,15 +3,17 @@ export function sanitizeDockerContainerId(id: string): string {
return String(id || '').replace(/[^a-zA-Z0-9]/g, '').slice(0, 64);
}
const CLEAR_STARTUP_OUTPUT = "printf '\\033[H\\033[2J\\033[3J';";
/** Interactive shell into a container — prefer bash, fall back to sh. */
export function buildDockerExecShellCommand(containerId: string): string {
const safeId = sanitizeDockerContainerId(containerId);
if (!safeId) return 'echo "Invalid container id"';
return `docker exec -it ${safeId} sh -c 'command -v bash >/dev/null 2>&1 && exec bash || exec sh'`;
return `${CLEAR_STARTUP_OUTPUT} exec docker exec -it ${safeId} sh -c 'command -v bash >/dev/null 2>&1 && exec bash || exec sh'`;
}
export function buildDockerLogsCommand(containerId: string): string {
const safeId = sanitizeDockerContainerId(containerId);
if (!safeId) return 'echo "Invalid container id"';
return `docker logs -f --tail 200 ${safeId}`;
return `${CLEAR_STARTUP_OUTPUT} exec docker logs -f --tail 200 ${safeId}`;
}

View File

@@ -3,9 +3,11 @@ export function shQuote(str: string): string {
return `'${String(str).replace(/'/g, "'\"'\"'")}'`;
}
const CLEAR_STARTUP_OUTPUT = "printf '\\033[H\\033[2J\\033[3J';";
export function buildTmuxAttachCommand(sessionName: string, windowIndex?: number): string {
const target = windowIndex !== undefined
? `${shQuote(sessionName)}:${windowIndex}`
: shQuote(sessionName);
return `tmux attach -t ${target}`;
return `${CLEAR_STARTUP_OUTPUT} exec tmux attach -t ${target}`;
}

View File

@@ -121,9 +121,17 @@ export type DockerImageManageAction =
export type SystemManagerSubTab = 'processes' | 'tmux' | 'docker';
export interface TerminalPopupIcon {
kind: 'image';
src: string;
backgroundColor?: string;
alt?: string;
}
export interface TerminalPopupPayload {
popupId?: string;
title: string;
icon?: TerminalPopupIcon;
parentSessionId: string;
sourceSession: import('../../types').TerminalSession;
startupCommand: string;