mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-12-15 00:26:23 +00:00
Update terminal-panel.tsx
This commit is contained in:
@@ -33,7 +33,7 @@ interface TerminalInstance {
|
|||||||
term: any
|
term: any
|
||||||
ws: WebSocket | null
|
ws: WebSocket | null
|
||||||
isConnected: boolean
|
isConnected: boolean
|
||||||
// containerRef: React.RefObject<HTMLDivElement> // This is no longer needed as we use callback refs
|
fitAddon: any // Added fitAddon to TerminalInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWebSocketUrl(): string {
|
function getWebSocketUrl(): string {
|
||||||
@@ -179,8 +179,8 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
|
|||||||
(e: MouseEvent) => {
|
(e: MouseEvent) => {
|
||||||
if (!isResizing) return
|
if (!isResizing) return
|
||||||
|
|
||||||
const deltaY = resizeStartY.current - e.clientY
|
const deltaY = e.clientY - resizeStartY.current
|
||||||
const newHeight = Math.max(200, Math.min(800, resizeStartHeight.current + deltaY))
|
const newHeight = Math.max(200, Math.min(800, resizeStartHeight.current - deltaY))
|
||||||
setTerminalHeight(newHeight)
|
setTerminalHeight(newHeight)
|
||||||
},
|
},
|
||||||
[isResizing],
|
[isResizing],
|
||||||
@@ -288,6 +288,7 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
|
|||||||
term: null,
|
term: null,
|
||||||
ws: null,
|
ws: null,
|
||||||
isConnected: false,
|
isConnected: false,
|
||||||
|
fitAddon: null, // Added fitAddon initialization
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
setActiveTerminalId(newId)
|
setActiveTerminalId(newId)
|
||||||
@@ -324,6 +325,33 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
|
|||||||
})
|
})
|
||||||
}, [terminals, isMobile])
|
}, [terminals, isMobile])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isMobile) return
|
||||||
|
|
||||||
|
terminals.forEach((terminal) => {
|
||||||
|
if (terminal.term && terminal.fitAddon && terminal.isConnected) {
|
||||||
|
try {
|
||||||
|
setTimeout(() => {
|
||||||
|
terminal.fitAddon?.fit()
|
||||||
|
if (terminal.ws?.readyState === WebSocket.OPEN) {
|
||||||
|
const cols = terminal.term?.cols || 80
|
||||||
|
const rows = terminal.term?.rows || 24
|
||||||
|
terminal.ws.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "resize",
|
||||||
|
cols,
|
||||||
|
rows,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, 100)
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("[Terminal] resize on height change failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, [terminalHeight, layout, terminals, isMobile])
|
||||||
|
|
||||||
const initializeTerminal = async (terminal: TerminalInstance, container: HTMLDivElement) => {
|
const initializeTerminal = async (terminal: TerminalInstance, container: HTMLDivElement) => {
|
||||||
const [TerminalClass, FitAddonClass] = await Promise.all([
|
const [TerminalClass, FitAddonClass] = await Promise.all([
|
||||||
import("xterm").then((mod) => mod.Terminal),
|
import("xterm").then((mod) => mod.Terminal),
|
||||||
@@ -392,7 +420,9 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
setTerminals((prev) => prev.map((t) => (t.id === terminal.id ? { ...t, isConnected: true, term, ws } : t)))
|
setTerminals((prev) =>
|
||||||
|
prev.map((t) => (t.id === terminal.id ? { ...t, isConnected: true, term, ws, fitAddon } : t)),
|
||||||
|
)
|
||||||
term.writeln("\x1b[32mConnected to ProxMenux terminal.\x1b[0m")
|
term.writeln("\x1b[32mConnected to ProxMenux terminal.\x1b[0m")
|
||||||
syncSizeWithBackend()
|
syncSizeWithBackend()
|
||||||
}
|
}
|
||||||
@@ -665,7 +695,7 @@ export const TerminalPanel: React.FC<TerminalPanelProps> = ({ websocketUrl, onCl
|
|||||||
className={`h-3 bg-zinc-800 hover:bg-blue-600 cursor-ns-resize flex items-center justify-center transition-colors border-t border-zinc-700 ${
|
className={`h-3 bg-zinc-800 hover:bg-blue-600 cursor-ns-resize flex items-center justify-center transition-colors border-t border-zinc-700 ${
|
||||||
isResizing ? "bg-blue-600" : ""
|
isResizing ? "bg-blue-600" : ""
|
||||||
}`}
|
}`}
|
||||||
title="Arrastra para redimensionar la altura del terminal"
|
title="Arrastra hacia arriba para agrandar, hacia abajo para reducir"
|
||||||
>
|
>
|
||||||
<GripHorizontal className="h-4 w-4 text-zinc-400" />
|
<GripHorizontal className="h-4 w-4 text-zinc-400" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user