Basic minimalistic frame pushing
This commit is contained in:
parent
b823c890f9
commit
8e991054e7
|
@ -42,13 +42,14 @@ func render() {
|
|||
}
|
||||
|
||||
func runClient(cmd *cobra.Command, args []string) {
|
||||
data.InitNC()
|
||||
defer data.ExitNC()
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, os.Kill)
|
||||
signal.Notify(c, syscall.SIGTERM)
|
||||
|
||||
data.InitNC(c)
|
||||
// really important???
|
||||
defer data.ExitNC()
|
||||
|
||||
fmt.Println("running client ...")
|
||||
|
||||
if len(args) < 1 {
|
||||
|
@ -67,13 +68,6 @@ func runClient(cmd *cobra.Command, args []string) {
|
|||
go render()
|
||||
run := true
|
||||
for run {
|
||||
// block until sigkill:
|
||||
select {
|
||||
case <-c:
|
||||
// funzt noch nicht:
|
||||
run = false
|
||||
default:
|
||||
}
|
||||
var oFrame data.Frame
|
||||
// always use new decoder - reusing may lead to errors
|
||||
gd := gob.NewDecoder(con)
|
||||
|
@ -83,6 +77,16 @@ func runClient(cmd *cobra.Command, args []string) {
|
|||
run = false
|
||||
}
|
||||
renderQueue <- oFrame
|
||||
|
||||
select {
|
||||
case <-c:
|
||||
// funzt noch nicht:
|
||||
run = false
|
||||
default:
|
||||
if data.GetChar() != 0 {
|
||||
data.ExitNC()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,11 +68,10 @@ func serveClients() {
|
|||
if id > 0 {
|
||||
enc := gob.NewEncoder(client.con)
|
||||
enc.Encode(oFrame)
|
||||
log.Println("ID:", id, "Client:", client)
|
||||
|
||||
//log.Println("ID:", id, "Client:", client)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
time.Sleep(time.Second / 25)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
var (
|
||||
win *nc.Window
|
||||
ncquit = make(chan bool)
|
||||
)
|
||||
|
||||
func RenderFrame(f *Frame) {
|
||||
|
@ -19,20 +20,36 @@ func RenderFrame(f *Frame) {
|
|||
}
|
||||
}
|
||||
|
||||
func InitNC() {
|
||||
func InitNC(killchan chan<- os.Signal) {
|
||||
var err error
|
||||
win, err = nc.Init()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
win.Timeout(1)
|
||||
go func() {
|
||||
select {
|
||||
case <-ncquit:
|
||||
log.Println("Exiting NC")
|
||||
killchan <- os.Kill
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func ExitNC() {
|
||||
//if win != nil {
|
||||
|
||||
// }
|
||||
nc.End()
|
||||
ncquit <- true
|
||||
// }
|
||||
}
|
||||
|
||||
func GetChar() int {
|
||||
if win != nil {
|
||||
k := win.GetChar()
|
||||
return int(k)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestNC() (int, int) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user