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: Break, Bye, Clear, Failed, Prompt, Quit, Redirect, RedirectFile, RedirectNone, RedirectPipe

Constant Summary collapse

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Intar.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/intar.rb', line 80

def initialize obj = nil, **params
  @obj = obj.nil? ? (eval "self", TOPLEVEL_BINDING) : obj
  if @@current then
    @params = @@current.params
    @prompt = @@current.prompt
    @depth  = @@current.depth + 1
  else
    @params = DEFAULTS.dup.update params
    @prompt = Prompt.new
    @depth = 0
  end
  @n = 1

  @binding = @obj.intar_binding
end

Class Attribute Details

.metacmdsObject (readonly)

Returns the value of attribute metacmds.



357
358
359
# File 'lib/intar.rb', line 357

def metacmds
  @metacmds
end

Instance Attribute Details

#depthObject (readonly)

Returns the value of attribute depth.



79
80
81
# File 'lib/intar.rb', line 79

def depth
  @depth
end

#nObject (readonly)

Returns the value of attribute n.



79
80
81
# File 'lib/intar.rb', line 79

def n
  @n
end

#paramsObject (readonly)

Returns the value of attribute params.



79
80
81
# File 'lib/intar.rb', line 79

def params
  @params
end

#promptObject (readonly)

Returns the value of attribute prompt.



79
80
81
# File 'lib/intar.rb', line 79

def prompt
  @prompt
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



145
146
147
# File 'lib/intar.rb', line 145

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

#runObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/intar.rb', line 103

def run
  handle_history do
    set_current do
      oldset = eval OLDSET, @binding
      loop do
        l = readline
        l or break
        @redir = find_redirect l
        begin
          if l.slice! /^\\(\w+|.)\s*(.*?)\s*$\n?/ then
            r = send (get_metacommand $1).method, (eval_param $2)
            l.empty? or @previous = l
          else
            begin
              r = eval_line l
            rescue SyntaxError
              raise if l.end_with? $/
              @previous = l
            end
          end
          next if @previous
          display r
        rescue Clear
          @previous = nil
          next
        rescue Bye
          raise if @depth.nonzero?
          break
        rescue Quit
          break
        rescue Exception
          break if SystemExit === $! and not @params[ :catch_exit]
          r = $!
          show_exception
        end
        oldset.call r, @n
        @n += 1
      end
    end
  end
end

#set_var(name, val) ⇒ Object



149
150
151
# File 'lib/intar.rb', line 149

def set_var name, val
  @binding.local_variable_set name, val
end