<commit_before>package progressbar

import (
	"fmt"
	"time"
)

type bar struct {
	curPos    int
	taskCount int
	workers   int
}

const line = "                                                            "

func NewBar(taskCount int, workers int) chan<- struct{} {
	var ch = make(chan struct{})
	b := &bar{
		taskCount: taskCount,
		workers:   workers,
	}
	go b.consume(ch)
	go func() {
		for range time.NewTicker(100 * time.Millisecond).C {
			b.draw()
		}
	}()
	return ch
}

func (b *bar) consume(c <-chan struct{}) {
	for range c {
		b.curPos++
		// b.draw()
	}
}

func (b *bar) clearLine() {
	fmt.Print("\r" + line + "\r")
}

func (b *bar) draw() {
	b.clearLine()
	fmt.Printf("%v/%v", b.curPos, b.taskCount)
}<commit_msg>lib/progressbar: tty width<commit_after>package progressbar

import (
	"fmt"
	"os"
	"os/exec"
	"strconv"
	"strings"
	"time"
)

type bar struct {
	curPos    int
	taskCount int
	workers   int
}

const line = "                                                            "

func NewBar(taskCount int, workers int) chan<- struct{} {
	var ch = make(chan struct{})
	b := &bar{
		taskCount: taskCount,
		workers:   workers,
	}
	go b.consume(ch)
	go func() {
		for range time.NewTicker(100 * time.Millisecond).C {
			b.draw()
		}
	}()
	return ch
}

func (b *bar) consume(c <-chan struct{}) {
	for range c {
		b.curPos++
		// b.draw()
	}
}

func (b *bar) clearLine() {
	fmt.Print("\r" + line + "\r")
}

func (b *bar) draw() {
	b.clearLine()
	fmt.Printf("%v/%v", b.curPos, b.taskCount)
}

func maxWidth() int {
	cmd := exec.Command("stty", "size")
	cmd.Stdin = os.Stdin
	sttyOut, err := cmd.Output()
	if err != nil {
		return 80
	}
	width, err := strconv.Atoi(strings.Split(string(sttyOut), " ")[0])
	if err != nil {
		return 80
	}
	return width
}
{'fraction_non_alphanumeric': 0.16704545454545455, 'fraction_numerical': 0.00625, 'mean_word_length': 2.4194174757281552, 'pattern_counts': {'":': 0, '<': 7, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4986738', 'n_tokens_mistral': 718, 'n_tokens_neox': 686, 'n_words': 173}