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