Class: IRB::ReadlineInputMethod

Inherits:
InputMethod show all
Includes:
Readline
Defined in:
lib/coderunner/interactive_methods.rb

Instance Method Summary collapse

Instance Method Details

#getsObject



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# File 'lib/coderunner/interactive_methods.rb', line 425

def gets
  Readline.input = @stdin
  Readline.output = @stdout
        prompt_end = Time.now.to_s[11...16]
        begin
          memsize = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{Process::pid}"`.chomp.split(/\s+/).map {|s| s.strip.to_i}[1].to_i/1000
          prompt_end += " #{memsize}k"
        rescue
        end
        prompt_end +=" (#{CodeRunner::SETUP_RUN_CLASSES.join(",")})"
  if l = readline(@prompt.gsub(/timemarker/, prompt_end) , false)
    #HISTORY.push(l) if !l.empty? and (HISTORY.size ==0 or l != HISTORY[-1])
    HISTORY.push(l) if !l.empty? and (HISTORY.size ==0 or l != HISTORY[-1])

    i = 0
    loop do
      break if HISTORY.size == 1
      (HISTORY.delete_at(i); i-=1) if HISTORY[i] == l
      i+=1
      #ep "i: #{i}, HS: #{HISTORY.size}"
      break if i >= HISTORY.size - 1
    end
    #HISTORY.reverse!
    #HISTORY.uniq!
    #HISTORY.reverse!
    #HISTORY.push(l) if !l.empty? and (HISTORY.size ==0 or !HISTORY.include? l)
    @line[@line_no += 1] = l + "\n"
  else
    @eof = true
    l
  end
end