Class: MiniReadline::History

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_readline/read_line/history.rb

Overview

Support for the edit history.

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ History

Setup the history array of the mini line editor.



10
11
12
13
# File 'lib/mini_readline/read_line/history.rb', line 10

def initialize(buffer)
  @_buffer = buffer
  goto_end_of_history
end

Instance Method Details

#append_history(str) ⇒ Object

Append a string to the history buffer if enabled.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mini_readline/read_line/history.rb', line 47

def append_history(str)
  return if @options[:no_blanks] && str.strip.empty?

  if history.include?(str)
    if @options[:no_dups]
      return if @options[:no_move]

      history.delete(str)
    end
  end

  history << str
end

#get_next_historyObject

Get the next history string



37
38
39
40
41
42
43
44
# File 'lib/mini_readline/read_line/history.rb', line 37

def get_next_history
  if @history_cursor < history.length
    @history_cursor += 1
    history[@history_cursor] || ""
  else
    false
  end
end

#get_previous_historyObject

Get the previous history string.



27
28
29
30
31
32
33
34
# File 'lib/mini_readline/read_line/history.rb', line 27

def get_previous_history
  if @history_cursor > 0
    @history_cursor -= 1
    self.history[@history_cursor]
  else
    false
  end
end

#goto_end_of_historyObject

Go to the end of the history array.



22
23
24
# File 'lib/mini_readline/read_line/history.rb', line 22

def goto_end_of_history
  @history_cursor = history.length
end

#historyObject

Get the history buffer associated with this instance.



62
63
64
# File 'lib/mini_readline/read_line/history.rb', line 62

def history
  @_buffer
end

#initialize_parms(options) ⇒ Object

Get the history object ready for the next read line operation.



16
17
18
19
# File 'lib/mini_readline/read_line/history.rb', line 16

def initialize_parms(options)
  @options = options
  goto_end_of_history
end