Sha256: 5331797f7e421808fc5b2f5aa47e5c3efe09ad09df9cb1b3a9173217e3466c3f

Contents?: true

Size: 982 Bytes

Versions: 3

Compression:

Stored size: 982 Bytes

Contents

require 'pry'
require 'pry-byebug'
require 'arql/commands'
require 'rainbow'

module Arql
  class Repl
    def initialize
      Pry.config.prompt = Pry::Prompt.new("", "", prompt)
      Pry.start
    end

    def main_object
      return @main if @main
      @main = Object.new
      @main.instance_eval do
        def inspect
          to_s
        end
        def to_s
          "main"
        end
      end
      @main
    end

    def prompt
      [proc do |obj, nest_level, _|
         if obj == main_object && nest_level == 0
           nest_level_prompt = ''
         else
           nest_level_prompt = if nest_level.zero?
                                 "(#{obj})"
                               else
                                 "(#{obj}:#{nest_level})"
                               end
         end
         "%s#{Rainbow('@').green}%s#{nest_level_prompt} %s " % [Rainbow('ARQL').red, Rainbow(App.prompt).yellow, Rainbow('❯').green]
       end]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arql-0.2.1 lib/arql/repl.rb
arql-0.2.0 lib/arql/repl.rb
arql-0.1.33 lib/arql/repl.rb