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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -13,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.Println("Starting client...")
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt)
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
|
||||||
|
@ -59,19 +61,42 @@ func main() {
|
||||||
|
|
||||||
// create execConn off of / endpoint
|
// 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
|
// Send the contents over the lang websocket
|
||||||
err = execConn.WriteMessage(websocket.TextMessage, sourceData)
|
err = execConn.WriteMessage(websocket.TextMessage, sourceData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to send source data over lang websocket:", err)
|
log.Fatal("Failed to send source data over lang websocket:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
<-interrupt
|
||||||
case <-interrupt:
|
|
||||||
fmt.Println("Interrupt signal received, closing connections...")
|
fmt.Println("Interrupt signal received, closing connections...")
|
||||||
close(done)
|
close(done)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectWebSocket(urlStr string) (*websocket.Conn, error) {
|
func connectWebSocket(urlStr string) (*websocket.Conn, error) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -12,13 +13,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleCase(caseName, data string) string {
|
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, ":", "")
|
caseName = strings.ReplaceAll(caseName, ":", "")
|
||||||
|
|
||||||
log.Println("Handling case", caseName)
|
log.Println("Handling case", caseName)
|
||||||
switch caseName {
|
switch caseName {
|
||||||
case "python", "python3", "py":
|
case "python", "python3", "py":
|
||||||
|
log.Println(data)
|
||||||
runPython(data)
|
runPython(data)
|
||||||
|
default:
|
||||||
|
fmt.Printf("caseName: %q\n", caseName)
|
||||||
|
log.Println(data)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -57,10 +63,8 @@ func runPython(data string) {
|
||||||
|
|
||||||
cmd := exec.Command(fname, "./main.py")
|
cmd := exec.Command(fname, "./main.py")
|
||||||
cmd.Dir = filepath.ToSlash("./workspace/")
|
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
|
cmd.Stderr = pyWriter
|
||||||
|
|
||||||
// start the command
|
// 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
|
:python
|
||||||
print("fuckme")
|
print("log test")
|
|
@ -1,4 +1 @@
|
||||||
import time
|
print("log test")
|
||||||
for i in range(10):
|
|
||||||
print(i)
|
|
||||||
time.sleep(0.5)
|
|
Loading…
Reference in a new issue