Created
December 1, 2019 17:34
-
-
Save mjudeikis/98bd445b25d85253f3557b9f0492558b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"os" | |
"time" | |
tm "github.com/buger/goterm" | |
"github.com/sirupsen/logrus" | |
"github.com/chbmuc/cec") | |
var ( | |
log *logrus.Entry | |
) | |
func init() { | |
logger := logrus.New() | |
logger.Formatter = &logrus.TextFormatter{FullTimestamp: true} | |
logger.SetLevel(logrus.DebugLevel) | |
log = logrus.NewEntry(logger) | |
} | |
func run() error { | |
log.Info("start demo app") | |
tty, err := os.OpenFile("/dev/tty0", os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm) | |
if err != nil { | |
return err | |
} | |
tm.Output = bufio.NewWriter(tty) | |
tm.Clear() | |
for { | |
log.Info("print...") | |
// By moving cursor to top-left position we ensure that console output | |
// will be overwritten each time, instead of adding new. | |
tm.MoveCursor(10, 10) | |
tm.Println("Current Time:", time.Now().Format(time.RFC1123)) | |
tm.Flush() // Call it every time at the end of rendering | |
time.Sleep(time.Second) | |
} | |
} | |
func main() { | |
err := run() | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment