Class: Intar

Inherits:
Object show all
Defined in:
lib/intar/version.rb,
lib/intar.rb,
lib/intar/prompt.rb,
lib/intar/redirect.rb

Overview

intar/version.rb – Version number

Defined Under Namespace

Classes: Failed, Prompt, Quit, Redirect, RedirectFile, RedirectNone, RedirectPipe

Constant Summary collapse

DEFAULTS =
{
  prompt:     "%(32)c%i%c:%1c%03n%c%> ",
  color:      true,
  show:       1,
  shownil:    false,
  pager:      nil,
  catch_exit: false,
  histhid:    true,
  histfile:   nil,
  histmax:    500,
}
VERSION =
"2.0".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil, **params) ⇒ Intar

Returns a new instance of Intar.



77
78
79
80
81
82
83
# File 'lib/intar.rb', line 77

def initialize obj = nil, **params
  @obj = obj.nil? ? (eval "self", TOPLEVEL_BINDING) : obj
  @params = DEFAULTS.dup.update params
  @binding = @obj.intar_binding
  @n = 0
  @prompt = Prompt.new
end

Class Attribute Details

.metacmdsObject (readonly)

Returns the value of attribute metacmds.



286
287
288
# File 'lib/intar.rb', line 286

def metacmds
  @metacmds
end

Class Method Details

.open(obj = nil, **params) {|i| ... } ⇒ Object

Yields:

  • (i)


53
54
55
56
# File 'lib/intar.rb', line 53

def open obj = nil, **params
  i = new obj, **params
  yield i
end

.run(obj = nil, **params) ⇒ Object



58
59
60
# File 'lib/intar.rb', line 58

def run obj = nil, **params
  open obj, **params do |i| i.run end
end

Instance Method Details

#execute(code) ⇒ Object



126
127
128
# File 'lib/intar.rb', line 126

def execute code
  eval code, @binding, "#{self.class}/execute"
end

#runObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/intar.rb', line 89

def run
  prompt_load_history
  oldset = eval OLDSET, @binding
  while l = readline do
    begin
      @redir = find_redirect l
      r = if l =~ /\A\\(\w+|.)\s*(.*?)\s*\Z/ then
        m = get_metacommand $1
        send m.method, (eval_param $2)
      else
        begin
          @redir.redirect_output do eval l, @binding, @file end
        rescue SyntaxError
          raise if l.end_with? $/
          @previous = l
          next
        end
      end
    rescue Quit
      break
    rescue Failed
      switchcolor 31, 1
      puts $!
      switchcolor
      r = $!
    rescue Exception
      raise if SystemExit === $! and not @params[ :catch_exit]
      show_exception
      r = $!
    else
      display r
    end
    oldset.call r, @n
  end
  prompt_save_history
end