-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathTerminalComp.jsx
More file actions
61 lines (55 loc) · 1.65 KB
/
TerminalComp.jsx
File metadata and controls
61 lines (55 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { useState, useEffect, useRef } from "react";
import { ReactTerminal } from "react-terminal";
import { toast } from "react-toastify";
import axios from "axios";
import "./Terminal.css";
import { DataState } from "../../context/DataContext";
const TerminalComp = () => {
const { terminalOutput, commandPress, fileName } = DataState();
const [output, setOutput] = useState("");
const terminalRef = useRef(null);
const handleCommand = async (command, ...args) => {
const fullCommand = [command, ...args].join(" ");
console.log("Full Command:", fullCommand);
try {
const { data } = await axios.post("http://127.0.0.1:10000/gdb_command", {
command: fullCommand,
name: fileName || "program",
});
return data["result"];
} catch (error) {
toast.error("Terminal command failed");
return "Error executing command";
}
};
const defaultHandler = async (command, ...args) => {
const result = await handleCommand(command, ...args);
setOutput(result);
return result;
};
useEffect(() => {
console.log(terminalOutput);
if (terminalOutput) {
console.log(terminalOutput);
defaultHandler(terminalOutput);
}
}, [commandPress]);
return (
<div className="terminal">
<ReactTerminal
ref={terminalRef}
themes={{
"my-custom-theme": {
themeBGColor: "#000",
themeToolbarColor: "#000",
themeColor: "#00FF00",
themePromptColor: "#a917a8",
},
}}
theme="my-custom-theme"
defaultHandler={defaultHandler}
/>
</div>
);
};
export default TerminalComp;