update code to current
This commit is contained in:
parent
0a563d8b02
commit
0ad7b3f110
6 changed files with 55 additions and 17 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.exe
|
||||
workspace
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
log.Println("Starting client...")
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
|
||||
|
@ -59,19 +61,42 @@ func main() {
|
|||
|
||||
// create execConn off of / endpoint
|
||||
|
||||
// BLAME COPILOT FOR THIS
|
||||
// Send the contents over the lang websocket
|
||||
sendSourceData := func() {
|
||||
err = execConn.WriteMessage(websocket.TextMessage, sourceData)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to send source data over lang websocket:", err)
|
||||
}
|
||||
}
|
||||
|
||||
sendSourceData()
|
||||
|
||||
// Listen for space key press in console
|
||||
go func() {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
char, _, err := reader.ReadRune()
|
||||
if err != nil {
|
||||
log.Fatal("Failed to read from console:", err)
|
||||
}
|
||||
|
||||
if char == ' ' {
|
||||
sendSourceData()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Send the contents over the lang websocket
|
||||
err = execConn.WriteMessage(websocket.TextMessage, sourceData)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to send source data over lang websocket:", err)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-interrupt:
|
||||
<-interrupt
|
||||
fmt.Println("Interrupt signal received, closing connections...")
|
||||
close(done)
|
||||
time.Sleep(1 * time.Second)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func connectWebSocket(urlStr string) (*websocket.Conn, error) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
@ -12,13 +13,18 @@ import (
|
|||
)
|
||||
|
||||
func handleCase(caseName, data string) string {
|
||||
// caseName = strings.ReplaceAll(caseName, "\n", "")
|
||||
caseName = strings.ReplaceAll(caseName, "\n", "")
|
||||
caseName = strings.ReplaceAll(caseName, "\r", "")
|
||||
caseName = strings.ReplaceAll(caseName, ":", "")
|
||||
|
||||
log.Println("Handling case", caseName)
|
||||
switch caseName {
|
||||
case "python", "python3", "py":
|
||||
log.Println(data)
|
||||
runPython(data)
|
||||
default:
|
||||
fmt.Printf("caseName: %q\n", caseName)
|
||||
log.Println(data)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -57,10 +63,8 @@ func runPython(data string) {
|
|||
|
||||
cmd := exec.Command(fname, "./main.py")
|
||||
cmd.Dir = filepath.ToSlash("./workspace/")
|
||||
// set the command's stdout to the pipe writer
|
||||
cmd.Stdout = pyWriter
|
||||
|
||||
// set the command's stderr to the pipe writer
|
||||
cmd.Stdout = pyWriter
|
||||
cmd.Stderr = pyWriter
|
||||
|
||||
// start the command
|
||||
|
|
10
makefile
Normal file
10
makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
default: runserver
|
||||
|
||||
setup:
|
||||
-mkdir -p workspace
|
||||
runserver: setup
|
||||
go build -o workspace/server.exe ./cmd/server
|
||||
./workspace/server.exe
|
||||
runclient: setup
|
||||
go build -o workspace/client.exe ./cmd/client
|
||||
./workspace/client.exe
|
|
@ -1,2 +1,2 @@
|
|||
:py
|
||||
print("fuckme")
|
||||
:python
|
||||
print("log test")
|
|
@ -1,4 +1 @@
|
|||
import time
|
||||
for i in range(10):
|
||||
print(i)
|
||||
time.sleep(0.5)
|
||||
print("log test")
|
Loading…
Reference in a new issue