Sha256: 184ac25ba5792483810265b76b230b1a71b13163ea266d7dcaebdc78a5b7f039

Contents?: true

Size: 751 Bytes

Versions: 8

Compression:

Stored size: 751 Bytes

Contents

#!/usr/bin/env ruby

# Repl Example
#
# A simple interactive example for running a repl in flammarion
require 'flammarion'

class FlammarionRepl
  def initialize
    @f = Flammarion::Engraving.new(exit_on_disconnect:true)
    @f.subpane("output")
    @f.input("> ", autoclear:true, history:true) {|msg| repl(msg['text']) }
  end

  def repl(str)
    @f.subpane("output").puts "> #{str}"
    result =
      begin
        eval(str).to_s.green
      rescue Exception => e
        "#{e}".red
      end
    @f.subpane("output").puts result
  end

  def puts(str)
    @f.subpane("output").puts "#{str}"
  end
end

module Kernel
  def puts(str)
    $repl.puts(str)
  end
end

if __FILE__ == $0 then
  $repl = FlammarionRepl.new
  $repl.wait_until_closed
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
flammarion-utils-0.2.1 bin/flammarion-repl
flammarion-utils-0.2.0 bin/flammarion-repl
flammarion-utils-0.1.14 bin/flammarion-repl
flammarion-utils-0.1.13 bin/flammarion-repl
flammarion-utils-0.1.12 bin/flammarion-repl
flammarion-utils-0.1.11 bin/flammarion-repl
flammarion-utils-0.1.10pre2 bin/flammarion-repl
flammarion-utils-0.1.10pre bin/flammarion-repl