master
HimbeerserverDE 2021-04-22 16:54:20 +02:00
parent 3b6bce9964
commit cd2bc2c92f
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
1 changed files with 15 additions and 2 deletions

17
log.go
View File

@ -1,8 +1,11 @@
package main
import (
"fmt"
"log"
"os"
"strings"
"time"
"github.com/tncardoso/gocurses"
)
@ -34,8 +37,18 @@ func newLogger() *Logger {
}
func (l *Logger) Write(p []byte) (int, error) {
row, _ := gocurses.Getmaxyx()
l.visible = appendPop(row-1, l.visible, string(p))
rows, _ := gocurses.Getmaxyx()
for i, line := range strings.Split(string(p)[:len(p)-1], "\n") {
if i > 0 {
t := time.Now()
date := fmt.Sprintf("%.4d/%.2d/%.2d %.2d:%.2d:%.2d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
line = date + " " + line
}
l.visible = appendPop(rows-1, l.visible, line)
}
draw(l.visible)
l.all = append(l.all, p...)