Sha256: a6c1e014a83e26b8e00d11f97bfde8019af3088bdfb3a9188f97127cd3dfdc5e

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), "..", "lib", "maths")

# The main script!

parser = Maths::Calculator.new


puts
puts "Welcome to maths (version #{Maths::VERSION})!"
puts "Type \"exit\" to quit."
puts

Readline.completion_proc = Proc.new do |str|
  # TODO: Get this working
end

prompt = "maths> "
while command = Readline.readline(prompt, true)
  command.strip!
  
  if /exit/i =~ command
    break 
  elsif /copy/i =~ command
    begin
      if Clipboard.implementation
        Clipboard.copy(Maths::Formatter.format(Maths::Brain.lookup("$")))
        puts "Copied #{Clipboard.paste} to your system clipboard."
        puts
      end
    rescue
      puts "Sorry, but clipboard support isn't enabled on your system."
      puts
    end
  
  elsif command == "vars" || command == "variables"
    puts
    puts "Defined Variables:"
    Maths::Brain.read.each do |key, value|
      puts "#{key}: #{Maths::Formatter.format(BigDecimal.new(value.to_s))}"
    end
    puts
  else
    begin
      result = parser.parse(command)

      puts "= #{Maths::Formatter.format(result)}"
      Maths::Brain.assign("$", result)
    rescue ParseError
      puts $!
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
maths-0.0.14 bin/maths
maths-0.0.13 bin/maths
maths-0.0.12 bin/maths
maths-0.0.11 bin/maths
maths-0.0.10 bin/maths