diff --git a/Frontend/src/components/Panel.jsx b/Frontend/src/components/Panel.jsx index b71f961..1b8d2aa 100644 --- a/Frontend/src/components/Panel.jsx +++ b/Frontend/src/components/Panel.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useRef } from "react"; -import { X } from "lucide-react"; +import { X, Maximize2, ChevronDown, Plus } from "lucide-react"; -const Panel = ({ +const Panel = ({ height, terminalOutput = [], isRunning = false, @@ -11,125 +11,135 @@ const Panel = ({ onClose, userInput = "", onUserInputChange, - onInputSubmit + onInputSubmit, }) => { const [activeTab, setActiveTab] = useState(initialTab); + const terminalRef = useRef(null); + const [inputBuffer, setInputBuffer] = useState(""); - // Set active tab when initialTab changes + // Update active tab when initialTab changes useEffect(() => { setActiveTab(initialTab); }, [initialTab]); - // Update the renderTerminal function to create an interactive terminal - const renderTerminal = () => { - const terminalRef = useRef(null); - const [inputBuffer, setInputBuffer] = useState(""); - - // Auto-scroll terminal to bottom when content changes - useEffect(() => { - if (terminalRef.current) { - terminalRef.current.scrollTop = terminalRef.current.scrollHeight; - } - }, [terminalOutput]); - - // Set up keyboard event listeners when terminal is focused - useEffect(() => { - const handleKeyDown = (e) => { - if (!isRunning) return; - - if (e.key === 'Enter') { - // Send current input buffer through WebSocket - if (inputBuffer.trim() && onInputSubmit) { - e.preventDefault(); // Prevent default Enter behavior - - // Important: Set user input and THEN call submit in a sequence - onUserInputChange(inputBuffer); - - // Add a small delay before submitting to ensure state update - setTimeout(() => { - onInputSubmit(); - // Clear buffer after submission is processed - setInputBuffer(""); - }, 10); - } - } else if (e.key === 'Backspace') { - // Handle backspace to remove characters - setInputBuffer(prev => prev.slice(0, -1)); - } else if (e.key.length === 1) { - // Add regular characters to input buffer - setInputBuffer(prev => prev + e.key); + // Auto-scroll terminal to the bottom when content changes + useEffect(() => { + if (terminalRef.current) { + terminalRef.current.scrollTop = terminalRef.current.scrollHeight; + } + }, [terminalOutput]); + + // Handle keyboard input for the terminal + useEffect(() => { + const handleKeyDown = (e) => { + if (!isRunning) return; + + if (e.key === "Enter") { + if (inputBuffer.trim() && onInputSubmit) { + e.preventDefault(); + onUserInputChange(inputBuffer); + setTimeout(() => { + onInputSubmit(); + setInputBuffer(""); + }, 10); } - }; - - // Add event listener - if (terminalRef.current) { - terminalRef.current.addEventListener('keydown', handleKeyDown); + } else if (e.key === "Backspace") { + setInputBuffer((prev) => prev.slice(0, -1)); + } else if (e.key.length === 1) { + setInputBuffer((prev) => prev + e.key); } - - // Clean up - return () => { - if (terminalRef.current) { - terminalRef.current.removeEventListener('keydown', handleKeyDown); - } - }; - }, [isRunning, inputBuffer, onInputSubmit, onUserInputChange]); - - return ( -
terminalRef.current?.focus()} // Focus when clicked - > - {terminalOutput.length > 0 ? ( - // Render output from EditorArea when available - <> - {terminalOutput.map((line, index) => ( -
- {line.type === 'command' ? $ : ''} {line.content} + }; + + const terminalElement = terminalRef.current; + terminalElement?.addEventListener("keydown", handleKeyDown); + + return () => { + terminalElement?.removeEventListener("keydown", handleKeyDown); + }; + }, [isRunning, inputBuffer, onInputSubmit, onUserInputChange]); + + // Render the terminal tab + const renderTerminal = () => ( +
terminalRef.current?.focus()} // Focus when clicked + > + {terminalOutput.length > 0 ? ( + <> + {terminalOutput.map((line, index) => { + const typeClass = + line.type === "warning" + ? "terminal-warning" + : line.type === "error" + ? "terminal-error" + : "terminal-output"; + + return ( +
+ {line.timestamp && ( + {line.timestamp} + )} + {line.type === "command" && $} + {line.content}
- ))} - - {/* Show current input with blinking cursor only when connection is active */} - {isRunning && ( -
- $ {inputBuffer} - -
- )} - - ) : ( - // Default terminal content - <> -
- $ + ); + })} + + {isRunning && ( +
+ $ {inputBuffer} +
- - )} -
- ); - }; + )} + + ) : ( +
+ $ + +
+ )} +
+ ); - const renderProblems = () => { - return ( -
-
No problems have been detected in the workspace.
-
- ); - }; + // Render other tabs + const renderProblems = () => ( +
+
No problems have been detected in the workspace.
+
+ ); - const renderOutput = () => { - return ( -
-
[Extension Host] Extension host started.
-
[Language Server] Language server started.
- {activeRunningFile && ( -
[Running] {activeRunningFile}
- )} -
- ); - }; + const renderOutput = () => ( +
+
[Extension Host] Extension host started.
+
[Language Server] Language server started.
+ {activeRunningFile && ( +
[Running] {activeRunningFile}
+ )} +
+ ); + const renderDebugConsole = () => ( +
+
Debug session not yet started.
+
Press F5 to start debugging.
+
+ ); + + const renderPorts = () => ( +
+
No forwarded ports detected.
+
+ ); + + const renderComments = () => ( +
+
No comments have been added to this workspace.
+
+ ); + + // Get content for the active tab const getTabContent = () => { switch (activeTab) { case "terminal": @@ -138,6 +148,12 @@ const Panel = ({ return renderProblems(); case "output": return renderOutput(); + case "debug": + return renderDebugConsole(); + case "ports": + return renderPorts(); + case "comments": + return renderComments(); default: return
Unknown tab
; } @@ -146,76 +162,29 @@ const Panel = ({ return (
-
setActiveTab("problems")} - > - - - - - - - - Problems -
-
setActiveTab("output")}> - - - - - - - - Output -
-
setActiveTab("terminal")} - > - - - - - - - Terminal -
+ {["problems", "output", "debug", "terminal", "ports", "comments"].map((tab) => ( +
setActiveTab(tab)} + > + {tab.toUpperCase()} +
+ ))} - {/* Add close button */}
+ + +
@@ -225,5 +194,4 @@ const Panel = ({ ); }; -export default Panel; - +export default Panel; \ No newline at end of file