Browse Source

inital commit

main
Pixdigit 12 months ago
parent
commit
f66ccb42dc
  1. 1
      .gitignore
  2. 21
      client/displayManager.go
  3. 27
      client/logger.go
  4. 102
      client/main.go
  5. 9
      go.mod
  6. 16
      go.sum

1
.gitignore

@ -15,3 +15,4 @@
# Dependency directories (remove the comment below to include it)
# vendor/
log.txt

21
client/displayManager.go

@ -0,0 +1,21 @@
package main
import (
"time"
)
func refresh(fps uint) {
exitChan := shutdownBroadcast.Subscribe()
go func() {
fpsTicker := time.NewTicker(time.Duration(float64(time.Second) / float64(opts.FPS)))
done := false
for !done {
select {
case <-fpsTicker.C:
screen.Show()
case <-exitChan:
done = true
}
}
}()
}

27
client/logger.go

@ -0,0 +1,27 @@
package main
import (
"fmt"
"io"
"os"
"time"
)
var logger io.WriteCloser
func initLogger() {
var err error
logger, err = os.OpenFile("./log.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(fmt.Sprintf("Could not open or create logger file: %v\n", err))
}
log("Started at %v", time.Now().Unix())
}
func log(format string, a ...interface{}) {
if len(a) > 0 {
io.WriteString(logger, fmt.Sprintf(format, a...)+"\n")
} else {
io.WriteString(logger, format+"\n")
}
}

102
client/main.go

@ -0,0 +1,102 @@
package main
import (
"fmt"
//"math/rand"
//"time"
"os"
"os/signal"
"git.pixdigit.tk/Pixdigit/broadcast"
"github.com/davecgh/go-spew/spew"
"github.com/gdamore/tcell"
)
type options struct {
FPS uint
}
var shutdownBroadcast = broadcast.Broadcast{}
var screen tcell.Screen
var opts = options{
FPS: 60,
}
func initTCell() {
var err error
// initialize tcell
if screen, err = tcell.NewScreen(); err != nil {
panic(fmt.Sprintf("Could create Screen:%v\n", err))
}
err = screen.Init()
if err != nil {
panic(fmt.Sprintf("Could not init screen:%v\n", err))
}
}
func initScreen() {
screen.HideCursor()
screen.SetStyle(tcell.StyleDefault.
Background(tcell.ColorBlack).
Foreground(tcell.ColorWhite))
screen.Clear()
}
func listenShutdown() {
go func() {
sigChan := make(chan os.Signal)
signal.Notify(sigChan, os.Interrupt)
signal.Notify(sigChan, os.Kill)
<-sigChan
shutdownBroadcast.Send(nil)
}()
}
func setup() {
//rand.Seed(time.Now().UnixNano())
initLogger()
initTCell()
initScreen()
refresh(opts.FPS)
listenShutdown()
}
func main() {
setup()
done := false
for !done {
event := screen.PollEvent()
if event != nil {
log("Got event: %v", spew.Sdump(event))
// switch on event type
switch ev := event.(type) {
case *tcell.EventKey:
switch ev.Key() {
case tcell.KeyCtrlZ, tcell.KeyCtrlC:
done = true
case tcell.KeyRune:
switch ev.Rune() {
case 'q':
done = true
}
}
case *tcell.EventResize:
//TODO
case *tcell.EventError:
fmt.Printf("TCell error: %v\n", ev.Error())
done = true
}
}
}
shutdownBroadcast.Send(nil)
screen.Fini()
log("Closing logger and exiting.")
logger.Close()
}

9
go.mod

@ -0,0 +1,9 @@
module git.pixdigit.tk/pixdigit/IFgameSH-SJ-21
go 1.16
require (
git.pixdigit.tk/Pixdigit/broadcast v0.0.1
github.com/davecgh/go-spew v1.1.1
github.com/gdamore/tcell v1.4.0
)

16
go.sum

@ -0,0 +1,16 @@
git.pixdigit.tk/Pixdigit/broadcast v0.0.1 h1:lTCgFEnz9M1Em2yShGkByvIhogrxt6z4EHwIBnBGazI=
git.pixdigit.tk/Pixdigit/broadcast v0.0.1/go.mod h1:g+6DaVLFTMlAZo2XGHaH4EQXglPwsBNTZIWMKEwp2KE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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 v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=
github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=
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 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Loading…
Cancel
Save