<commit_before>require 'io/console'
require 'thread'

class ProgressBar
  attr_writer :limit_per_second

  def initialize(total)
    @total = total
    @lines_taken = 0
    @semaphore = Mutex.new
    @last_print_time = 0
    @limit_per_second = 2
  end

  def print(progress, status, force: false)
    return unless force || can_print?
    status ||= ""

    return unless @semaphore.try_lock

    console_width = IO.console.winsize[1]

    return if console_width < 6

    if @lines_taken > 0
      $stdout.write "\e[1A\r"
      $stdout.write " " * @previous_status_length if @previous_status_length > status.length
      $stdout.write "\e[#{@lines_taken - 1}A\r"<commit_msg>Refresh progress bar more frequently<commit_after>require 'io/console'
require 'thread'

class ProgressBar
  attr_writer :limit_per_second

  def initialize(total)
    @total = total
    @lines_taken = 0
    @semaphore = Mutex.new
    @last_print_time = 0
    @limit_per_second = 10
  end

  def print(progress, status, force: false)
    return unless force || can_print?
    status ||= ""

    return unless @semaphore.try_lock

    console_width = IO.console.winsize[1]

    return if console_width < 6

    if @lines_taken > 0
      $stdout.write "\e[1A\r"
      $stdout.write " " * @previous_status_length if @previous_status_length > status.length
      $stdout.write "\e[#{@lines_taken - 1}A\r"
{'fraction_non_alphanumeric': 0.10610465116279069, 'fraction_numerical': 0.012354651162790697, 'mean_word_length': 3.263157894736842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2950128', 'n_tokens_mistral': 492, 'n_tokens_neox': 462, 'n_words': 109}