Class: IRB::ReadlineInputMethod

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

Instance Method Summary collapse

Instance Method Details

#getsObject



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/coderunner/interactive_methods.rb', line 353

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