<commit_before>require 'highline'
require 'yaml'
require 'json'
require 'pp'

module MrMurano
  module Verbose
    def verbose(msg)
      if $cfg['tool.verbose'] then
        say msg
      end
    end

    def debug(msg)
      if $cfg['tool.debug'] then
        say msg
      end
    end

    def warning(msg)
      $stderr.puts HighLine.color(msg, :yellow)
    end


    ## Format and print the object
    def outf(obj)
      fmt = $cfg['tool.outformat']
      case fmt
      when /yaml/i
        $stdout.puts obj.to_yaml
      when /pp/
        pp obj
      when /json/i
        $stdout.puts obj.to_json
      else # aka plain.
        if obj.kind_of?(Array) then
          obj.each {|i| $stdout.puts i.to_s}
        else
          $stdout.puts obj.to_s
        end
      end
    end

  end
end
#  vim: set ai et sw=2 ts=2 :<commit_msg>Add error method and make outf more featureful<commit_after>require 'highline'
require 'yaml'
require 'json'
require 'pp'

module MrMurano
  module Verbose
    def verbose(msg)
      if $cfg['tool.verbose'] then
        say msg
      end
    end

    def debug(msg)
      if $cfg['tool.debug'] then
        say msg
      end
    end

    def warning(msg)
      $stderr.puts HighLine.color(msg, :yellow)
    end

    def error(msg)
      $stderr.puts HighLine.color(msg, :red)
    end


    ## Format and print the object
    def outf(obj, ios=nil, &block)
      fmt = $cfg['tool.outformat']
      ios = $stdout if ios.nil?
      case fmt
      when /yaml/i
        ios.puts obj.to_yaml
      when /pp/
        pp obj
      when /json/i
        ios.puts obj.to_json
      else # aka best.
        # sometime ‘best’ is only know by the caller, so block.
        if block_given? then
          yield obj
        else
          if obj.kind_of?(Array) then
            obj.each {|i| ios.puts i.to_s}
          else
            ios.puts obj.to_s
          end
        end
      end
    end

  end
end
#  vim: set ai et sw=2 ts=2 :
{'fraction_non_alphanumeric': 0.09225280326197757, 'fraction_numerical': 0.0020387359836901123, 'mean_word_length': 1.6527027027027028, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7026048', 'n_tokens_mistral': 687, 'n_tokens_neox': 662, 'n_words': 202}