class Shindo::Tests
def prompt(description, &block)
def prompt(description, &block) return if Thread.main[:exit] || Thread.current[:reload] Thread.current[:formatador].display("Action? [c,e,i,q,r,t,?]? ") choice = STDIN.gets.strip continue = false Thread.current[:formatador].display_line Thread.current[:formatador].indent do case choice when 'c', 'continue' continue = true when /^e .*/, /^eval .*/ begin value = eval(choice[2..-1], @gestalt.bindings.last) if value.nil? value = 'nil' end Thread.current[:formatador].display_line(value) rescue => error display_error(error) end when 'i', 'interactive', 'irb' Thread.current[:formatador].display_line('Starting interactive session...') if @irb.nil? require 'irb' ARGV.clear # Avoid passing args to IRB IRB.setup(nil) @irb = IRB::Irb.new(nil) IRB.conf[:MAIN_CONTEXT] = @irb.context IRB.conf[:PROMPT][:SHINDO] = {} end for key, value in IRB.conf[:PROMPT][:SIMPLE] IRB.conf[:PROMPT][:SHINDO][key] = "#{Thread.current[:formatador].indentation}#{value}" end @irb.context.prompt_mode = :SHINDO @irb.context.workspace = IRB::WorkSpace.new(@gestalt.bindings.last) begin @irb.eval_input rescue SystemExit end when 'q', 'quit', 'exit' Thread.current[:formatador].display_line("Exiting...") Thread.main[:exit] = true when 'r', 'reload' Thread.current[:formatador].display_line("Reloading...") Thread.current[:reload] = true when 't', 'backtrace', 'trace' if @gestalt.calls.empty? Thread.current[:formatador].display_line("[red]No methods were called, so no backtrace was captured.[/]") else @gestalt.display_calls end when '?', 'help' Thread.current[:formatador].display_lines([ 'c - ignore this error and continue', 'i - interactive mode', 'q - quit Shindo', 'r - reload and run the tests again', 't - display backtrace', '? - display help' ]) else Thread.current[:formatador].display_line("[red]#{choice} is not a valid choice, please try again.[/]") end Thread.current[:formatador].display_line end unless continue || Thread.main[:exit] Thread.current[:formatador].display_line("[red]- #{description}[/]") prompt(description, &block) end end