Class: Drx::TkGUI::LineHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/drx/tk/app.rb

Overview

Manages history for an input line.

Instance Method Summary collapse

Constructor Details

#initializeLineHistory

Returns a new instance of LineHistory.



519
520
521
522
# File 'lib/drx/tk/app.rb', line 519

def initialize
  @entries = []
  @pos = 0
end

Instance Method Details

#add(s) ⇒ Object



526
527
528
529
530
# File 'lib/drx/tk/app.rb', line 526

def add(s)
  @entries.reject! { |ent| ent == s }
  @entries << s
  @pos = @entries.size
end

#currentObject



539
540
541
# File 'lib/drx/tk/app.rb', line 539

def current
  past_end? ? '' : @entries[@pos]
end

#next!Object



535
536
537
538
# File 'lib/drx/tk/app.rb', line 535

def next!
  @pos += 1 if not past_end?
  current
end

#past_end?Boolean

Returns:

  • (Boolean)


523
524
525
# File 'lib/drx/tk/app.rb', line 523

def past_end?
  @pos >= @entries.size
end

#prev!Object



531
532
533
534
# File 'lib/drx/tk/app.rb', line 531

def prev!
  @pos -= 1 if @pos > 0
  current
end