<commit_before>package textbox

import "github.com/nsf/termbox-go"

func Init() error {
	if err := termbox.Init(); err != nil {
		return err
	}
	return nil
}

func Close() {
	termbox.Close()
}<commit_msg>add event and main loops<commit_after>package textbox

import (
	"sync"

	"github.com/nsf/termbox-go"
)

var (
	closed    chan struct{}
	closeOnce sync.Once
)

func init() {
	closed = make(chan struct{})
}

func Init() error {
	if err := termbox.Init(); err != nil {
		return err
	}
	events := make(chan *termbox.Event)
	go func() {
		for {
			ev := termbox.PollEvent()
			switch ev.Type {
			case termbox.EventError:
				Close()
				return
			default:
				events <- &ev
			}
		}
	}()
	go func() {
		select {
		case ev := <-events:
			_ = ev
			//TODO
		case <-closed:
			return
		}
	}()
	return nil
}

func Close() {
	closeOnce.Do(func() {
		close(closed)
		termbox.Close()
	})
}
{'fraction_non_alphanumeric': 0.15384615384615385, 'fraction_numerical': 0.0, 'mean_word_length': 2.782051282051282, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '2295221', 'n_tokens_mistral': 384, 'n_tokens_neox': 342, 'n_words': 84}