<commit_before>package main

import (
	"bytes"
	"github.com/sugyan/ttyread"
	"image"
	"image/gif"
	"io"
	"io/ioutil"
	"j4k.co/terminal"
	"log"
	"os"
)

// GifGenerator type
type GifGenerator struct {
	Speed  float64
	Col    int
	Row    int
	NoLoop bool
}

// NewGifGenerator returns GifGenerator instance
func NewGifGenerator() *GifGenerator {
	return &GifGenerator{
		Speed:  1.0,
		Col:    80,
		Row:    24,
		NoLoop: false,
	}
}

// Generate writes to outFile an animated GIF
func (g *GifGenerator) Generate(input string, output string) (err error) {
	// input
	inFile, err := os.Open(input)
	if err != nil {
		return
	}
	defer inFile.Close()

	// virtual terminal
	var state = terminal.State{}
	vt, err := terminal.Create(&state, ioutil.NopCloser(bytes.NewBuffer([]byte{})))
	if err != nil {
		return
	}
	defer vt.Close()
	vt.Resize(g.Col, g.Row)

	// read ttyrecord
	reader := ttyread.NewTtyReader(inFile)
	var (
		prevTv *ttyread.TimeVal
		images []*image.Paletted
		delays []int
	)
	for {
		var data *ttyread.TtyData
		data, err = reader.ReadData()
		if err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		}
		var diff ttyread.TimeVal
		if prevTv != nil {
			diff = data.TimeVal.Subtract(*prevTv)
		}
		prevTv = &data.TimeVal

		// calc delay and capture
		delay := int(float64(diff.Sec*1000000+diff.Usec)/g.Speed) / 10000
		if delay > 0 {
			log.Println(delay)
			var img *image.Paletted
			img, err = g.Capture(&state)
			if err != nil {
				return
			}
			images = append(images, img)
			delays = append(delays, delay)
		}
		// write to vt<commit_msg>remove debug log<commit_after>package main

import (
	"bytes"
	"github.com/sugyan/ttyread"
	"image"
	"image/gif"
	"io"
	"io/ioutil"
	"j4k.co/terminal"
	"os"
)

// GifGenerator type
type GifGenerator struct {
	Speed  float64
	Col    int
	Row    int
	NoLoop bool
}

// NewGifGenerator returns GifGenerator instance
func NewGifGenerator() *GifGenerator {
	return &GifGenerator{
		Speed:  1.0,
		Col:    80,
		Row:    24,
		NoLoop: false,
	}
}

// Generate writes to outFile an animated GIF
func (g *GifGenerator) Generate(input string, output string) (err error) {
	// input
	inFile, err := os.Open(input)
	if err != nil {
		return
	}
	defer inFile.Close()

	// virtual terminal
	var state = terminal.State{}
	vt, err := terminal.Create(&state, ioutil.NopCloser(bytes.NewBuffer([]byte{})))
	if err != nil {
		return
	}
	defer vt.Close()
	vt.Resize(g.Col, g.Row)

	// read ttyrecord
	reader := ttyread.NewTtyReader(inFile)
	var (
		prevTv *ttyread.TimeVal
		images []*image.Paletted
		delays []int
	)
	for {
		var data *ttyread.TtyData
		data, err = reader.ReadData()
		if err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		}
		var diff ttyread.TimeVal
		if prevTv != nil {
			diff = data.TimeVal.Subtract(*prevTv)
		}
		prevTv = &data.TimeVal

		// calc delay and capture
		delay := int(float64(diff.Sec*1000000+diff.Usec)/g.Speed) / 10000
		if delay > 0 {
			var img *image.Paletted
			img, err = g.Capture(&state)
			if err != nil {
				return
			}
			images = append(images, img)
			delays = append(delays, delay)
		}
		// write to vt
{'fraction_non_alphanumeric': 0.13144493952896244, 'fraction_numerical': 0.015276893698281349, 'mean_word_length': 2.9584382871536525, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2674836', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1222, 'n_words': 303}