changed from unmaintained version of gocui to newer fork; vastly improved handling of logging
This commit is contained in:
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module krumel.moe/serverwrapper
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/awesome-gocui/gocui v1.0.0 // indirect
|
||||||
github.com/jroimartin/gocui v0.4.0 // indirect
|
github.com/jroimartin/gocui v0.4.0 // indirect
|
||||||
github.com/nsf/termbox-go v1.1.1 // indirect
|
github.com/nsf/termbox-go v1.1.1 // indirect
|
||||||
github.com/pelletier/go-toml v1.9.1
|
github.com/pelletier/go-toml v1.9.1
|
||||||
|
|||||||
16
go.sum
16
go.sum
@ -1,8 +1,24 @@
|
|||||||
|
github.com/awesome-gocui/gocui v1.0.0 h1:1bf0DAr2JqWNxGFS8Kex4fM/khICjEnCi+a1+NfWy+w=
|
||||||
|
github.com/awesome-gocui/gocui v1.0.0/go.mod h1:UvP3dP6+UsTGl9IuqP36wzz6Lemo90wn5p3tJvZ2OqY=
|
||||||
|
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||||
|
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||||
|
github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs=
|
||||||
|
github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
|
||||||
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
|
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
|
||||||
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
|
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY=
|
github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY=
|
||||||
github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
|
github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
|
||||||
github.com/pelletier/go-toml v1.9.1 h1:a6qW1EVNZWH9WGI6CsYdD8WAylkoXBS5yv0XHlh17Tc=
|
github.com/pelletier/go-toml v1.9.1 h1:a6qW1EVNZWH9WGI6CsYdD8WAylkoXBS5yv0XHlh17Tc=
|
||||||
github.com/pelletier/go-toml v1.9.1/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
github.com/pelletier/go-toml v1.9.1/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
|
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
|||||||
@ -2,22 +2,20 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
// "fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
// "math"
|
|
||||||
"container/ring"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"github.com/awesome-gocui/gocui"
|
||||||
"github.com/jroimartin/gocui"
|
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
var settings *toml.Tree
|
var (
|
||||||
var stdout_ring *ring.Ring
|
settings *toml.Tree
|
||||||
var srv_stdin io.WriteCloser
|
srv_stdin io.WriteCloser
|
||||||
var new_stdout bool = false
|
)
|
||||||
|
|
||||||
|
|
||||||
// reload settings (and maybe other things too)
|
// reload settings (and maybe other things too)
|
||||||
func reload() {
|
func reload() {
|
||||||
@ -30,7 +28,7 @@ func build_cmd() (string, []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//run the server-thread
|
//run the server-thread
|
||||||
func server_run() {
|
func server_run(g *gocui.Gui) {
|
||||||
//create the command
|
//create the command
|
||||||
cmd_str, cmd_args := build_cmd()
|
cmd_str, cmd_args := build_cmd()
|
||||||
cmd := exec.Command(cmd_str, cmd_args...)
|
cmd := exec.Command(cmd_str, cmd_args...)
|
||||||
@ -50,9 +48,14 @@ func server_run() {
|
|||||||
buf := bufio.NewScanner(stdout)
|
buf := bufio.NewScanner(stdout)
|
||||||
for {
|
for {
|
||||||
if buf.Scan() {
|
if buf.Scan() {
|
||||||
stdout_ring.Value = buf.Text()
|
g.Update(func(g *gocui.Gui) error {
|
||||||
stdout_ring = stdout_ring.Next()
|
v, err := g.View("srv_log")
|
||||||
new_stdout = true
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintln(v, buf.Text())
|
||||||
|
return nil
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
}
|
}
|
||||||
@ -63,11 +66,8 @@ func main() {
|
|||||||
//initialize settings by "re"loading them from disk
|
//initialize settings by "re"loading them from disk
|
||||||
reload()
|
reload()
|
||||||
|
|
||||||
//initialize the stdout/err ringbuffer
|
|
||||||
stdout_ring = ring.New(255)
|
|
||||||
|
|
||||||
//init the CUI
|
//init the CUI
|
||||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
g, err := gocui.NewGui(gocui.OutputNormal, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
@ -79,17 +79,7 @@ func main() {
|
|||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go server_run()
|
go server_run(g)
|
||||||
|
|
||||||
go func(g *gocui.Gui) {
|
|
||||||
for {
|
|
||||||
time.Sleep(50 * time.Millisecond)
|
|
||||||
if new_stdout {
|
|
||||||
new_stdout = false
|
|
||||||
g.Update(layout)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(g)
|
|
||||||
|
|
||||||
//run the CUI main loop
|
//run the CUI main loop
|
||||||
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
||||||
@ -101,29 +91,13 @@ func main() {
|
|||||||
func layout(g *gocui.Gui) error {
|
func layout(g *gocui.Gui) error {
|
||||||
maxX, maxY := g.Size()
|
maxX, maxY := g.Size()
|
||||||
|
|
||||||
v, err := g.SetView("srv_log", 0, 0, maxX-1, int(float32(maxY) * 0.8))
|
v, err := g.SetView("srv_log", 0, 0, maxX-1, int(float32(maxY) * 0.8), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != gocui.ErrUnknownView {
|
if err != gocui.ErrUnknownView {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//dont put code in here you idiot
|
//*only* put initialization code for the view here
|
||||||
}
|
v.Autoscroll = true
|
||||||
|
|
||||||
v.Clear()
|
|
||||||
|
|
||||||
vW, vH := v.Size()
|
|
||||||
|
|
||||||
r := stdout_ring.Prev()
|
|
||||||
|
|
||||||
for i := 0; i < vH; i++ {
|
|
||||||
v.SetCursor(0, vH - i - 1)
|
|
||||||
if r.Value != nil {
|
|
||||||
s := r.Value.(string)
|
|
||||||
for i := 0; i < len(s) && i < vW; i++ {
|
|
||||||
v.EditWrite([]rune(s)[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r = r.Prev()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user