Update lxc-terminal-modal.tsx

This commit is contained in:
MacRimi
2026-01-31 18:17:50 +01:00
parent d2c7362736
commit 5bfc911e1b

View File

@@ -236,19 +236,34 @@ export function LxcTerminalModal({
outputBufferRef.current += event.data outputBufferRef.current += event.data
// Detect when we're inside the LXC container // Detect when we're inside the LXC container
// Look for shell prompt pattern after pct enter command // The LXC prompt will NOT contain "constructor" (the host name)
const afterPctEnter = outputBufferRef.current.split(`pct enter ${vmid}`).pop() || "" // It will be something like "root@plex:/#" or "user@containername:~$"
if (afterPctEnter.includes("@") && (afterPctEnter.includes("$") || afterPctEnter.includes("#") || afterPctEnter.includes(":~") || afterPctEnter.includes(":/#"))) { const buffer = outputBufferRef.current
// Successfully inside LXC
isInsideLxcRef.current = true
// Extract content after pct enter (skip command echo line) // Look for a prompt that:
const newlineIndex = afterPctEnter.indexOf('\n') // 1. Comes after pct enter command
if (newlineIndex !== -1) { // 2. Has @ followed by container name (not host name)
const lxcContent = afterPctEnter.substring(newlineIndex + 1) // 3. Ends with # or $
term.write(lxcContent) const pctEnterMatch = buffer.match(/pct enter \d+\r?\n/)
if (pctEnterMatch) {
const afterPctEnter = buffer.substring(buffer.indexOf(pctEnterMatch[0]) + pctEnterMatch[0].length)
// Find the LXC prompt - it should be a line ending with :~# :~$ :/# or similar
// and NOT containing the host name "constructor"
const lxcPromptMatch = afterPctEnter.match(/\r?\n?([^\r\n]*@(?!constructor)[^\r\n]*[#$]\s*)$/)
if (lxcPromptMatch) {
// Successfully inside LXC - only show from the LXC prompt onwards
isInsideLxcRef.current = true
// Find where the LXC prompt line starts
const promptStart = afterPctEnter.lastIndexOf(lxcPromptMatch[1])
if (promptStart !== -1) {
// Only show the LXC prompt itself
term.write(lxcPromptMatch[1])
}
return
} }
return
} }
} else { } else {
// Already inside LXC, write directly // Already inside LXC, write directly