Skip to content

Commit

Permalink
Merge pull request #1 from slashexx/preview
Browse files Browse the repository at this point in the history
Added code for rust
  • Loading branch information
slashexx authored Nov 10, 2024
2 parents eaa50fc + 08abeb7 commit 5f3b6bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions backend/code-execution-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func executeCode(language string, code string) (string, error) {
return string(cmdOutput), err
}
cmd = exec.Command(tmpFile.Name()[:len(tmpFile.Name())-4])
case "rs":
execCmd := exec.Command("rustc", tmpFile.Name())
if err := execCmd.Run(); err != nil {
cmdOutput,_ := execCmd.CombinedOutput()

return string(cmdOutput), err
}
case "java":
tmpFileName := filepath.Join(os.TempDir(), "Main.java")
tmpFile, err = os.Create(tmpFileName)
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import { useNavigate } from "react-router-dom";
import "devicon/devicon.min.css";


type Language = "c" | "cpp" | "python" | "java" | "go";
type Language = "c" | "cpp" | "python" | "java" | "go" | "rs";

const INITIAL_CODE: Record<Language, string> = {
c: '#include <stdio.h> \n\nint main() {\n printf("Hello world !"); \n return 0; \n}',
cpp: '#include <iostream>\n\nint main() {\n std::cout << "Hello, World!" << std::endl;\n return 0;\n}',
python: 'print("Hello, World!")',
java: 'public class Main {\n public static void main(String[] args) {\n System.out.println("Hello, World!");\n }\n}',
go: 'package main\n\nimport "fmt"\n\nfunc main() {\n fmt.Println("Hello, World!")\n}',
rust: 'fn main() {\n\tprintln!("Hello world !")\n}'
};

const LANGUAGE_CONFIGS = {
Expand All @@ -30,10 +31,11 @@ const LANGUAGE_CONFIGS = {
python: { label: "Python", icon: "devicon-python-plain colored" , color: "text-yellow-500" },
java: { label: "Java", icon: "devicon-java-plain colored", color: "text-red-500" },
go: { label: "Go", icon: "devicon-go-plain colored", color: "text-cyan-500" },
rust: { label: "Rust", icon: "devicon-rust-original colored", color: "text-red-500"}
};

function App() {
const [selectedLanguage, setSelectedLanguage] = useState<Language>("go");
const [selectedLanguage, setSelectedLanguage] = useState<Language>("c");
const [code, setCode] = useState(INITIAL_CODE[selectedLanguage]);
const [output, setOutput] = useState("Output will appear here...");
const [editorInstance, setEditorInstance] = useState<monaco.editor.IStandaloneCodeEditor>(null);
Expand Down

0 comments on commit 5f3b6bb

Please sign in to comment.