<commit_before>$LOAD_PATH.unshift File.dirname($0)

require 'clipboard'
require_relative 'processor'
require_relative 'common'

processor = Processor.new

puts "#{GREEN_TEXT}RPN Calculator, ©2014, <NAME> #{CYAN_TEXT}#{'═' * (console_columns - 57)} Enter ? for help."
print "#{GREEN_TEXT}► #{BROWN_TEXT}"
input = gets.chomp
while input > ''
    begin
        answer = processor.execute(input)
    rescue Exception => msg
        answer = nil
        puts "#{RED_TEXT}#{msg}"
    end
    processor.registers.each{|name, value| 
        value = value.round if !value.kind_of?(Array) and value % 1 == 0
        value = value.map{|i| i % 1 == 0 ? i.round : i} if value.kind_of?(Array)
        print "#{BROWN_TEXT}#{name}#{GRAY_TEXT}=#{BROWN_TEXT}#{value} " 
    }
    print "#{BLUE_TEXT}• " if processor.registers != {}
    processor.stack.each{|value| print "#{GRAY_TEXT}#{value % 1 == 0 ? value.round : value} " }
    print "#{GREEN_TEXT}► #{BROWN_TEXT}"
    input = gets.chomp
end

puts "#{CYAN_TEXT}#{'═' * (console_columns - 23)} Thanks for using rpn."
if !answer.nil?
    answer = (answer % 1 == 0 ? answer.round : answer)
    Clipboard.copy answer.to_s
    puts "#{GRAY_TEXT}#{answer} #{BROWN_TEXT}was copied to the clipboard."
end
puts "#{RESET_COLORS} "
sleep 1<commit_msg>Display numbers with thousands separators.<commit_after>$LOAD_PATH.unshift File.dirname($0)

require 'clipboard'
require_relative 'processor'
require_relative 'common'

def format(value)
    if value.kind_of?(Array)
        return "[#{value.map{|v| format(v)}.join(' ')}]"
    elsif value % 1 == 0
        value.round.to_s.reverse.gsub( /\d{3}(?=\d)/, '\&,' ).reverse
    else
        pre, post = value.to_s.split '.'
        "#{pre.reverse.gsub( /\d{3}(?=\d)/, '\&,' ).reverse}.#{post}"
    end
end

processor = Processor.new

puts "#{GREEN_TEXT}RPN Calculator, ©2014, <NAME> #{CYAN_TEXT}#{'═' * (console_columns - 57)} Enter ? for help."
print "#{GREEN_TEXT}► #{BROWN_TEXT}"
input = gets.chomp
while input > ''
    begin
        answer = processor.execute(input)
    rescue Exception => msg
        answer = nil
        puts "#{RED_TEXT}#{msg}"
    end
    processor.registers.each{|name, value|
        print "#{BROWN_TEXT}#{name}#{GRAY_TEXT}=#{BROWN_TEXT}#{format(value)} " 
    }
    print "#{BLUE_TEXT}• " if processor.registers != {}
    processor.stack.each{|value| print "#{GRAY_TEXT}#{format(value)} " }
    print "#{GREEN_TEXT}► #{BROWN_TEXT}"
    input = gets.chomp
end

puts "#{CYAN_TEXT}#{'═' * (console_columns - 23)} Thanks for using rpn."
if !answer.nil?
    Clipboard.copy format(answer).to_s
    puts "#{GRAY_TEXT}#{format(answer)} #{BROWN_TEXT}was copied to the clipboard."
end
puts "#{RESET_COLORS} "
sleep 1
{'fraction_non_alphanumeric': 0.17664449371766444, 'fraction_numerical': 0.011825572801182557, 'mean_word_length': 3.6512027491408934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '541288', 'n_tokens_mistral': 1008, 'n_tokens_neox': 983, 'n_words': 213}