Sha256: 2ea50f94288e660eaafd4481f42413212cc6e078ca592eccd7ecf455ab487055

Contents?: true

Size: 891 Bytes

Versions: 1

Compression:

Stored size: 891 Bytes

Contents

require 'amun/object'
require 'amun/helpers/colors'
require 'amun/behaviours/emacs'

module Amun
  module MajorModes
    #  mode that executes the last line in
    # the current environment and print the output
    class IRB < Object
      include Behaviours::Emacs

      def initialize(buffer)
        super()
        self.buffer = buffer

        emacs_behaviour_initialize
        bind "\n", self, :execute_last_line
        read_io if buffer.empty?
      end

      def execute_last_line(*)
        last_line = buffer.lines.last
        result = eval(last_line)
        buffer << "\n#{result}"
      rescue StandardError, SyntaxError => error
        buffer << "\n#{error.inspect}\n#{error.backtrace}"
      ensure
        buffer.point = buffer.length
      end

      private

      attr_accessor :buffer

      def read_io
        buffer << buffer.io.read
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amun-0.2.0 lib/amun/major_modes/irb.rb