From 2de7498546b45b99e74ceb52bf88f15af41a5268 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 24 Oct 2020 18:18:27 +0000 Subject: [PATCH] creating a screen and doing some logging --- go.mod | 1 + go.sum | 4 ++++ main.go | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index fbabad0..04b41c1 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/fatih/motion v1.1.0 // indirect github.com/gdamore/tcell/v2 v2.0.0 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect + github.com/jordanorelli/blammo v0.0.0-20200201231725-9fd70eb7c1f2 github.com/josharian/impl v1.0.0 // indirect github.com/jstemmer/gotags v1.4.1 // indirect github.com/keegancsmith/rpc v1.3.0 // indirect diff --git a/go.sum b/go.sum index 99c0147..cfc20a3 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,8 @@ github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalip github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= +github.com/jordanorelli/blammo v0.0.0-20200201231725-9fd70eb7c1f2 h1:DH2VZ5Z4paQJe0zViSQENrwbgfrt4yyTeckjureCKOw= +github.com/jordanorelli/blammo v0.0.0-20200201231725-9fd70eb7c1f2/go.mod h1:hh4DdsA3OoMbUpCM3iftScrKFmrPuTLOqnK1aJmadqk= github.com/josharian/impl v1.0.0 h1:yMibyBqtigRRIK+47NGeIzPWJIPdj8DWvhHRp5gGZJQ= github.com/josharian/impl v1.0.0/go.mod h1:SQ6aJMP6xsJpGSD/36IIqrUdigLCYe9bz/9o5AKm6Aw= github.com/jstemmer/gotags v1.4.1 h1:aWIyXsU3lTDqhsEC49MP85p2cUUWr2ptvdGNqqGA3r4= @@ -82,9 +84,11 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 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-20180824175216-6c1c5e93cdc1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go index f4675de..57dd457 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,54 @@ package main import ( - "fmt" + "os" + "time" + "github.com/gdamore/tcell/v2" "github.com/jordanorelli/belt-mud/internal/exit" + "github.com/jordanorelli/blammo" ) +func newLog(path string) *blammo.Log { + f, err := os.OpenFile("./belt.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + exit.WithMessage(1, "unable to open log file %q for writing: %v", err) + } + + w := blammo.NewLineWriter(f) + + options := []blammo.Option{ + blammo.DebugWriter(w), + blammo.InfoWriter(w), + blammo.ErrorWriter(w), + } + + return blammo.NewLog("belt", options...) +} + func main() { + log := newLog("./belt.log") + start := time.Now() + log.Info("starting at: %v", start) + defer func() { + finished := time.Now() + log.Info("finished at: %v", finished) + log.Info("total play time: %v", finished.Sub(start)) + }() + screen, err := tcell.NewScreen() if err != nil { + exit.WithMessage(1, "unable to create a screen: %v", err) + } + log.Debug("sceen created") + if err := screen.Init(); err != nil { exit.WithMessage(1, "unable to initialize screen: %v", err) } - fmt.Println(screen) + log.Debug("screen initialized") + defer screen.Fini() + + log.Debug("clearing screen") + screen.Clear() + time.Sleep(1 * time.Second) }