Class: Live::Context

Inherits:
Object show all
Defined in:
lib/live.rb

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Context

Returns a new instance of Context.


11
12
13
14
# File 'lib/live.rb', line 11

def initialize session
  @session = session
  @binding = binding
end

Instance Method Details

#bind_key(key, &block) ⇒ Object

Binds a proc to a keystroke


25
26
27
28
# File 'lib/live.rb', line 25

def bind_key key, &block
  @session.key_bindings[key.to_s.unpack('c').first] = block
  Notice.new "Key '#{key}' is bound to an action" if block
end

#eval(string) ⇒ Object


16
17
18
19
20
21
22
# File 'lib/live.rb', line 16

def eval string
  begin
    super string, @binding
  rescue Exception => exception
    SystemExit === exception ? quit! : exception
  end
end

#quit!Object


30
31
32
# File 'lib/live.rb', line 30

def quit!
  @session.quit!
end

#reset!Object


34
35
36
37
# File 'lib/live.rb', line 34

def reset!
  @session.key_bindings.clear
  @session.new_context
end