-
Notifications
You must be signed in to change notification settings - Fork 3
/
fxserver.go
56 lines (45 loc) · 877 Bytes
/
fxserver.go
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
package main
import (
"bufio"
"fmt"
"os/exec"
"runtime"
"github.com/jroimartin/gocui"
)
func listen(g *gocui.Gui, scanner *bufio.Scanner) {
for scanner.Scan() {
line := scanner.Text()
mu.Lock()
updateFxServer(g, line)
}
}
func updateFxServer(g *gocui.Gui, line string) {
g.Update(func(g *gocui.Gui) error {
v, err := g.View("main")
if err != nil {
return err
}
fmt.Fprintln(v, line)
mu.Unlock()
return nil
})
}
func startFxServer(profile string, g *gocui.Gui) {
path := Servers[profile]
os := runtime.GOOS
switch os {
case "windows":
CfxCmd = exec.Command(path)
case "linux":
CfxCmd = exec.Command("bash", "-c", path)
}
Writer, _ = CfxCmd.StdinPipe()
r, _ := CfxCmd.StdoutPipe()
CfxCmd.Stderr = CfxCmd.Stdout
Scanner = *bufio.NewScanner(r)
go listen(g, &Scanner)
err := CfxCmd.Start()
if err != nil {
panic(err)
}
}