<commit_before>class << FancyIrb
  attr_accessor :options
  def [](key, key2 = nil)
    if key2
      @options[key][key2]
    else
      @options[key]
    end
  end

  attr_accessor :original_stdout
  attr_accessor :capture_irb_errors
  attr_accessor :real_lengths
  attr_accessor :continue
  attr_accessor :stdout_colorful
  attr_accessor :skip_next_rocket

  def start(user_options = {})
    @height_counter   = []
    @real_lengths     = { :output => 1, :input_prompt => 9999 } # or whatever
    @stdout_colorful  = false
    @continue         = false
    @skip_next_rocket = false
    @options = FancyIrb::DEFAULT_OPTIONS.dup
    @options[:colorize] = @options[:colorize].dup if @options[:colorize]

    FancyIrb::DEFAULT_OPTIONS.each{ |key, value|
      # (ugly) 1 level deep merge, maybe refactor
      if key == :colorize
        if user_options.has_key?(:colorize) && user_options[:colorize].nil?
          @options[:colorize] = {}
        else
          value.each{ |key2, _|
            if user_options[key] && user_options[key].has_key?(key2)
              @options[:colorize][key2] = user_options[key][key2]
            end
          }
        end
      else
        @options[key] =
            user_options.has_key?(key) ? user_options[key] : FancyIrb::DEFAULT_OPTIONS[key]
      end
    }

    # hook code into IRB
    require 'fancy_irb/irb_ext'
    true
  end

  def add_output_proc(prepend = false, &proc)
    action = prepend ? :unshift : :push
    @options[:output_procs].send action, proc
  end

  def set_result_proc(&proc)
    @options[:result_proc] = proc
  end

  def reset_height
    @height_counter = []
  end

  def track_height(data)
    data       = Paint.unpaint(data.to_s)
    lines      = data.count("\n")
    long_lines = data.split("\n").inject(0){ |sum, line|
      sum + (line.display_size / FancyIrb::TerminalInfo.cols)
    }<commit_msg>move option parsing out of initializer<commit_after>class << FancyIrb
  attr_accessor :options
  def [](key, key2 = nil)
    if key2
      @options[key][key2]
    else
      @options[key]
    end
  end

  attr_accessor :original_stdout
  attr_accessor :capture_irb_errors
  attr_accessor :real_lengths
  attr_accessor :continue
  attr_accessor :stdout_colorful
  attr_accessor :skip_next_rocket

  def start(user_options = {})
    @height_counter   = []
    @real_lengths     = { :output => 1, :input_prompt => 9999 } # or whatever
    @stdout_colorful  = false
    @continue         = false
    @skip_next_rocket = false

    @options = FancyIrb::DEFAULT_OPTIONS.dup
    @options[:colorize] = @options[:colorize].dup if @options[:colorize]
    parse_user_options(user_options)

    # hook code into IRB
    require 'fancy_irb/irb_ext'
    true
  end

  def parse_user_options(user_options)
    FancyIrb::DEFAULT_OPTIONS.each{ |key, value|
      # (ugly) 1 level deep merge, maybe refactor
      if key == :colorize
        if user_options.has_key?(:colorize) && user_options[:colorize].nil?
          @options[:colorize] = {}
        else
          value.each{ |key2, _|
            if user_options[key] && user_options[key].has_key?(key2)
              @options[:colorize][key2] = user_options[key][key2]
            end
          }
        end
      else
        @options[key] =
            user_options.has_key?(key) ? user_options[key] : FancyIrb::DEFAULT_OPTIONS[key]
      end
    }
  end

  def add_output_proc(prepend = false, &proc)
    action = prepend ? :unshift : :push
    @options[:output_procs].send action, proc
  end

  def set_result_proc(&proc)
    @options[:result_proc] = proc
  end

  def reset_height
    @height_counter = []
  end

  def track_height(data)
    data       = Paint.unpaint(data.to_s)
    lines      = data.count("\n")
    long_lines = data.split("\n").inject(0){ |sum, line|
      sum + (line.display_size / FancyIrb::TerminalInfo.cols)
    }
{'fraction_non_alphanumeric': 0.11410788381742738, 'fraction_numerical': 0.007261410788381743, 'mean_word_length': 2.7629268292682925, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5144372', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1315, 'n_words': 257}