<commit_before>require 'ncurses'
require 'progressbar'
require 'delegate'

module MultiProgressBar
  class << self
    attr_reader :bars

    # Set up the screen.  Always call +MultiProgressBar.start+ before using progress bars.
    def start
      @bars = [].freeze

      Ncurses.initscr
      Ncurses.curs_set(0)

      @bars_window = Ncurses::WINDOW.new(1, 0, Ncurses.LINES-1, 0)
      @log_window  = Ncurses::WINDOW.new(Ncurses.LINES-1, 0, 0, 0)
      @log_window.scrollok(true)
    end

    # Restore the terminal to normal function.  Always call this before exiting.
    def end
      Ncurses.endwin
      puts
    end

    # Write +text+ to the space above the progress bars.
    def log(text)
      @log_window.addstr("#{text}\n")
      @log_window.refresh
    end

    def width  #:nodoc:
      @bars_window.getmaxx
    end

    def add_bar(bar)  #:nodoc:
      @bars += [bar]

      @bars_window.mvwin(Ncurses.LINES-bars.size, @bars_window.getbegx)
      @bars_window.resize(bars.size, @bars_window.getmaxx)
      @bars_window.refresh

      @log_window.resize(Ncurses.LINES-bars.size, @log_window.getmaxx)
      @log_window.refresh
    end

    def update_bar(bar, rendered_bar)  #:nodoc:
      @bars_window.move(bars.index(bar), 0)
      @bars_window.addstr(rendered_bar)
      @bars_window.refresh
    end
  end
end

require 'multi_progress_bar/bar_renderer'
require 'multi_progress_bar/bar'
require 'multi_progress_bar/total_bar'
<commit_msg>Add extra line when ending in a better way.<commit_after>require 'ncurses'
require 'progressbar'
require 'delegate'

module MultiProgressBar
  class << self
    attr_reader :bars

    # Set up the screen.  Always call +MultiProgressBar.start+ before using progress bars.
    def start
      @bars = [].freeze

      Ncurses.initscr
      Ncurses.curs_set(0)

      @bars_window = Ncurses::WINDOW.new(1, 0, Ncurses.LINES-1, 0)
      @log_window  = Ncurses::WINDOW.new(Ncurses.LINES-1, 0, 0, 0)
      @log_window.scrollok(true)
    end

    # Restore the terminal to normal function.  Always call this before exiting.
    def end
      # Give an extra line below the output for the shell to prompt on.
      @log_window.resize(@log_window.getmaxy-1, @log_window.getmaxx)
      @bars_window.mvwin(@log_window.getmaxy-1, @bars_window.getbegx)
      @bars_window.resize(@bars_window.getmaxy+1, @bars_window.getmaxx)
      @log_window.refresh
      @bars_window.refresh

      Ncurses.endwin
    end

    # Write +text+ to the space above the progress bars.
    def log(text)
      @log_window.addstr("#{text}\n")
      @log_window.refresh
    end

    def width  #:nodoc:
      @bars_window.getmaxx
    end

    def add_bar(bar)  #:nodoc:
      @bars += [bar]

      @bars_window.mvwin(Ncurses.LINES-bars.size, @bars_window.getbegx)
      @bars_window.resize(bars.size, @bars_window.getmaxx)
      @bars_window.refresh

      @log_window.resize(Ncurses.LINES-bars.size, @log_window.getmaxx)
      @log_window.refresh
    end

    def update_bar(bar, rendered_bar)  #:nodoc:
      @bars_window.move(bars.index(bar), 0)
      @bars_window.addstr(rendered_bar)
      @bars_window.refresh
    end
  end
end

require 'multi_progress_bar/bar_renderer'
require 'multi_progress_bar/bar'
require 'multi_progress_bar/total_bar'

{'fraction_non_alphanumeric': 0.10489296636085627, 'fraction_numerical': 0.007033639143730887, 'mean_word_length': 3.068407960199005, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3917758', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1146, 'n_words': 242}