module Nirvana::Shell

Included into Ripl::Shell at runtime

Public Instance Methods

format_result(result) click to toggle source
Calls superclass method
# File lib/nirvana/shell.rb, line 29
def format_result(result)
  stdout, stderr, output = Util.capture_all { super }
  @stdout << (stdout.empty? ? output : stdout)
  @stderr << stderr
  output = Util.format_output @stdout
  output = "<div class='nirvana_warning'>#{@stderr}</div>" + output unless @stderr.to_s.empty?
  output
end
loop_eval(str) click to toggle source
Calls superclass method
# File lib/nirvana/shell.rb, line 20
def loop_eval(str)
  @stdout, @stderr, result = Util.capture_all { super(str) }
  result
end
print_eval_error(error) click to toggle source
print_result(result) click to toggle source
web_loop_once(input) click to toggle source
Calls superclass method
# File lib/nirvana/shell.rb, line 7
def web_loop_once(input)
  super
  @eval_error = nil
  @input[/^:AUTOCOMPLETE:/] ? get_completions(@input) : loop_once
rescue Exception => e
  exit if e.message[/^uncaught throw `ripl_exit'/]
  html_error(e, "Internal #{@name} error: ")
end

Protected Instance Methods

completions(line_buffer) click to toggle source
# File lib/nirvana/shell.rb, line 48
def completions(line_buffer)
  input = line_buffer[/([^#{Bond::Readline::DefaultBreakCharacters}]+)$/,1]
  arr = Bond.agent.call(input || line_buffer, line_buffer)
  return [] if arr[0].to_s[/^Bond Error:/] #silence bond debug errors
  return arr if input == line_buffer
  chopped_input = line_buffer.sub(/#{Regexp.quote(input.to_s)}$/, '')
  arr.map {|e| chopped_input + e }
end
get_completions(input) click to toggle source
# File lib/nirvana/shell.rb, line 43
def get_completions(input)
  arr = completions input.sub(/^:AUTOCOMPLETE:\s*/, '')
  ':AUTOCOMPLETE: ' + JSON.generate(arr)
end
html_error(error, message) click to toggle source
# File lib/nirvana/shell.rb, line 39
def html_error(error, message)
  "<span class='nirvana_exception'>#{Util.format_output(message + format_error(error))}</span>"
end