You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1021 B
Go

package core
import (
"bufio"
"context"
2 weeks ago
"io"
"log/slog"
"os"
"time"
"github.com/EngoEngine/ecs"
)
type App struct {
W *ecs.World
L *slog.Logger
}
2 weeks ago
func New(level string, logFile io.Writer) *App {
var logLevel slog.Level
switch level {
case "INFO", "info":
logLevel = slog.LevelInfo
case "DEBUG", "debug":
logLevel = slog.LevelDebug
case "ERROR", "error":
logLevel = slog.LevelError
}
l := slog.New(slog.NewTextHandler(
2 weeks ago
logFile, &slog.HandlerOptions{
Level: logLevel,
},
),
)
world := &ecs.World{}
return &App{
L: l,
W: world,
}
}
func (a *App) Run(ctx context.Context) {
go func() {
t := time.NewTicker(time.Millisecond * 30)
for range t.C {
a.W.Update(1)
}
}()
scanner := bufio.NewScanner(os.Stdin)
var line string
for {
select {
case <-ctx.Done():
a.L.Error("cancelled")
return
default:
if scanner.Scan() {
line = scanner.Text()
}
a.L.Info("scanning input")
a.L.With(slog.String("input", line)).Info("received command")
}
}
}