<commit_before>package main

import (
	"runtime"
	"time"

	"github.com/veandco/go-sdl2/sdl"

	"github.com/kasworld/actionstat"
	"github.com/kasworld/htmlcolors"
	"github.com/kasworld/log"

	"github.com/kasworld/go-sdlgui"
)

func main() {
	runtime.LockOSThread()

	app := App{
		Stat:  actionstat.NewActionStat(),
		SdlCh: make(chan interface{}, 1),
		Keys:  make(map[sdl.Scancode]bool),
	}
	app.Run()
	runtime.UnlockOSThread()
}

type App struct {
	Quit  bool
	SdlCh chan interface{}
	Keys  sdlgui.KeyState
	Win   *sdlgui.Window
	Stat  *actionstat.ActionStat

	controls []sdlgui.ControlI
	msgtexts *sdlgui.TextBoxControl
	barctrl  *sdlgui.TextControl
}

func (g *App) addControls() {
	g.Win = sdlgui.NewWindow("", 1024, 800, true)

	g.msgtexts = sdlgui.NewTextBoxControl(
		0, 0, 0,
		1024, 720, 60,
		sdlgui.LoadFont("DejaVuSerif.ttf", 12))
	g.msgtexts.SetBG(htmlcolors.Gray.ToRGBA())
	g.Win.AddControl(g.msgtexts)

	g.barctrl = sdlgui.NewTextControl(
		0, 720, 0,
		1024, 80, "hello",
		sdlgui.LoadFont("DejaVuSerif.ttf", 36))
	g.barctrl.SetBG(htmlcolors.Pink.ToRGBA())
	g.Win.AddControl(g.barctrl)

	g.Win.UpdateAll()
}

func (g *App) Run() {
	g.addControls()
	sdlgui.SDLEvent2Ch(g.SdlCh)
	timerInfoCh := time.Tick(time.Duration(1000) * time.Millisecond)
	timerDrawCh := time.Tick(time.Duration(1000/60) * time.Millisecond)
	barlen := 0.0
	for !g.Quit {
		select {
		case data := <-g.SdlCh:
			if g.Win.ProcessSDLMouseEvent(data) ||
				g.Keys.ProcessSDLKeyEvent(data) {
				g.Quit = true
			}
			g.msgtexts.AddText("data %v", data)
			g.barctrl.SetBar(barlen)
			barlen += 0.01
			if barlen > 1 {
				barlen = 0
			}
			g.Stat.Inc()

		case <-timerDrawCh:
			g.msgtexts.DrawSurface()
			g.barctrl.DrawSurface()
			g.Win.Update()

		case <-timerInfoCh:
			log.Info("stat %v", g.Stat)
			g.Stat.UpdateLap()
		}
	}
}<commit_msg>more structured example<commit_after>package main

import (
	"runtime"
	"time"

	"github.com/veandco/go-sdl2/sdl"

	"github.com/kasworld/actionstat"
	"github.com/kasworld/htmlcolors"
	"github.com/kasworld/log"

	"github.com/kasworld/go-sdlgui"
)

func main() {
	NewApp().Run()
}

type App struct {
	Quit     bool
	SdlCh    chan interface{}
	Keys     sdlgui.KeyState
	Win      *sdlgui.Window
	Controls sdlgui.ControlIList

	Stat    *actionstat.ActionStat
	msgtext *sdlgui.TextBoxControl
	barctrl *sdlgui.TextControl
}

func NewApp() *App {
	app := App{
		SdlCh: make(chan interface{}, 1),
		Keys:  make(map[sdl.Scancode]bool),
		Win:   sdlgui.NewWindow("SDL GUI Example", 1024, 800, true),

		Stat: actionstat.NewActionStat(),
	}
	app.addControls()
	app.Win.UpdateAll()
	return &app
}

func (app *App) AddControl(c sdlgui.ControlI) {
	app.Controls = append(app.Controls, c)
	app.Win.AddControl(c)
}

// changed for every app

func (g *App) addControls() {
	g.msgtext = sdlgui.NewTextBoxControl(
		0, 0, 0,
		1024, 720, 60,
		sdlgui.LoadFont("DejaVuSerif.ttf", 12))
	g.msgtext.SetBG(htmlcolors.Gray.ToRGBA())
	g.AddControl(g.msgtext)

	g.barctrl = sdlgui.NewTextControl(
		0, 720, 0,
		1024, 80, "hello",
		sdlgui.LoadFont("DejaVuSerif.ttf", 36))
	g.barctrl.SetBG(htmlcolors.Pink.ToRGBA())
	g.AddControl(g.barctrl)

}

func (app *App) Run() {
	// need to co-exist sdl lib
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	// start sdl event loop
	sdlgui.SDLEvent2Ch(app.SdlCh)
	timerInfoCh := time.Tick(time.Duration(1000) * time.Millisecond)
	timerDrawCh := time.Tick(time.Duration(1000/60) * time.Millisecond)
	barlen := 0.0

	for !app.Quit {
		select {
		case data := <-app.SdlCh:
			if app.Win.ProcessSDLMouseEvent(data) ||
				app.Keys.ProcessSDLKeyEvent(data) {
				app.Quit = true
			}
			app.msgtext.AddText("data %v", data)
			app.barctrl.SetBar(barlen)
			barlen += 0.01
			if barlen > 1 {
				barlen = 0
			}
			app.Stat.Inc()

		case <-timerDrawCh:
			for _, v := range app.Controls {
				v.DrawSurface()
			}
			app.Win.Update()

		case <-timerInfoCh:
			log.Info("stat %v", app.Stat)
			app.Stat.UpdateLap()

		}
	}
}
{'fraction_non_alphanumeric': 0.15427275018905975, 'fraction_numerical': 0.027224602974539956, 'mean_word_length': 3.5979142526071843, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3260738', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1643, 'n_words': 289}