class Shindo::Tests

def prompt(&block)

def prompt(&block)
  print("#{indentation}Action? [c,i,q,r,t,#,?]? ")
  choice = STDIN.gets.strip
  print("\n")
  case choice
  when 'c'
    return
  when 'i'
    print_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][:TREST] = {}
    end
    for key, value in IRB.conf[:PROMPT][:SIMPLE]
      IRB.conf[:PROMPT][:TREST][key] = "#{indentation}#{value}"
    end
    @irb.context.prompt_mode = :TREST
    @irb.context.workspace = IRB::WorkSpace.new(block.binding)
    begin
      @irb.eval_input
    rescue SystemExit
    end
  when 'q'
    Thread.current[:success] = false
    Thread.exit
  when 'r'
    print("Reloading...\n")
    Thread.current[:reload] = true
    Thread.exit
  when 't'
    indent {
      if @annals.lines.empty?
        print_line('no backtrace available')
      else
        index = 1
        for line in @annals.lines
          print_line("#{' ' * (2 - index.to_s.length)}#{index}  #{line}")
          index += 1
        end
      end
    }
    print("\n")
  when '?'
    print_line('c - ignore this error and continue')
    print_line('i - interactive mode')
    print_line('q - quit Shindo')
    print_line('r - reload and run the tests again')
    print_line('t - display backtrace')
    print_line('# - enter a number of a backtrace line to see its context')
    print_line('? - display help')
  when /\d/
    index = choice.to_i - 1
    if backtrace.lines[index]
      indent {
        print_line("#{@annals.lines[index]}: ")
        indent {
          print("\n")
          current_line = @annals.buffer[index]
          File.open(current_line[:file], 'r') do |file|
            data = file.readlines
            current = current_line[:line]
            min     = [0, current - (@annals.max / 2)].max
            max     = [current + (@annals.max / 2), data.length].min
            min.upto(current - 1) do |line|
              print_line("#{line}  #{data[line].rstrip}")
            end
            yellow_line("#{current}  #{data[current].rstrip}")
            (current + 1).upto(max - 1) do |line|
              print_line("#{line}  #{data[line].rstrip}")
            end
          end
          print("\n")
        }
      }
    else
      red_line("#{choice} is not a valid backtrace line, please try again.")
    end
  else
    red_line("#{choice} is not a valid choice, please try again.")
  end
  red_line("- #{full_description}")
  prompt(&block)
end