added regex and duplicate line filtering
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"log"
|
||||
"os/exec"
|
||||
"path"
|
||||
"regexp"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@ -21,7 +22,6 @@ var (
|
||||
srv_cmd *exec.Cmd
|
||||
)
|
||||
|
||||
|
||||
// reload settings (and maybe other things too)
|
||||
func reload() {
|
||||
settings, _ = toml.LoadFile("serverwrapper.toml")
|
||||
@ -38,9 +38,6 @@ func settings_list(option string) []string {
|
||||
|
||||
//builds the cmd which is called to run the server
|
||||
func build_cmd() (string, []string) {
|
||||
//for debugging
|
||||
//return "ping", []string{"8.8.8.8"}
|
||||
|
||||
java_args := []string{"-jar"}
|
||||
|
||||
jvm_args := settings_list("server.jvm-args")
|
||||
@ -93,6 +90,11 @@ func server_run(g *gocui.Gui) {
|
||||
log.Panicln("Failed to call server command \"" + srv_cmd.String() + "\"")
|
||||
}
|
||||
|
||||
//preload the regexes from the config
|
||||
regexes := settings_list("logging.stdout_excludes")
|
||||
|
||||
lastline := ""
|
||||
|
||||
//read pipes and write them to the ring buffer
|
||||
buf := bufio.NewScanner(stdout)
|
||||
for {
|
||||
@ -103,12 +105,31 @@ func server_run(g *gocui.Gui) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(v, buf.Text())
|
||||
|
||||
line := buf.Text()
|
||||
match := lastline == line
|
||||
lastline = line
|
||||
for i := range regexes {
|
||||
match_line, err := regexp.Match(regexes[i], []byte(line))
|
||||
if err != nil {
|
||||
v2, _ := g.View("status")
|
||||
fmt.Fprintln(v2, err)
|
||||
}
|
||||
match = match || match_line
|
||||
if match {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !match {
|
||||
fmt.Fprintln(v, buf.Text())
|
||||
}
|
||||
|
||||
g.SetCurrentView("input")
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,6 +178,7 @@ func inputHandler(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
|
||||
case key == gocui.KeyEnter:
|
||||
s := v.Buffer()
|
||||
srv_stdin.Write([]byte(s))
|
||||
srv_stdin.Write([]byte("\n"))
|
||||
v.EditDeleteToStartOfLine()
|
||||
}
|
||||
}
|
||||
@ -210,7 +232,7 @@ func killserver(g *gocui.Gui, v *gocui.View) error {
|
||||
return err
|
||||
}
|
||||
v_status.Clear()
|
||||
err = srv_cmd.Process.Signal(syscall.SIGTERM)
|
||||
err = srv_cmd.Process.Signal(syscall.SIGINT)
|
||||
if err != nil {
|
||||
fmt.Fprintf(v_status, fmt.Sprint(err))
|
||||
}
|
||||
@ -228,7 +250,12 @@ func procstatus(g *gocui.Gui, v *gocui.View) error {
|
||||
return err
|
||||
}
|
||||
v_status.Clear()
|
||||
fmt.Fprintf(v_status, fmt.Sprint(srv_cmd.ProcessState))
|
||||
state := srv_cmd.ProcessState
|
||||
if state == nil {
|
||||
fmt.Fprintf(v_status, "Server Process is still running")
|
||||
} else {
|
||||
fmt.Fprintf(v_status, fmt.Sprint(state))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -249,8 +276,8 @@ func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
}
|
||||
} else {
|
||||
v_status.Clear()
|
||||
fmt.Fprintf(v_status, "Server process still running, sending SIGTERM... ")
|
||||
srv_cmd.Process.Signal(syscall.SIGTERM)
|
||||
fmt.Fprintf(v_status, "Server process still running, sending SIGINT... ")
|
||||
srv_cmd.Process.Signal(syscall.SIGINT)
|
||||
err = srv_cmd.Wait()
|
||||
if err != nil {
|
||||
fmt.Fprintf(v_status, fmt.Sprint(err))
|
||||
|
||||
Reference in New Issue
Block a user