Class: Readline::History

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/readline.rb

Instance Method Summary collapse

Instance Method Details

#<<(str) ⇒ Object

Raises:

  • (TypeError)


137
138
139
140
141
142
# File 'lib/readline.rb', line 137

def <<(str)
  raise TypeError unless str.respond_to?(:to_str)

  FFI::Readline.add_history(str.to_str)
  HISTORY
end

#[](index) ⇒ Object

Raises:

  • (IndexError)


122
123
124
125
126
127
128
# File 'lib/readline.rb', line 122

def [](index)
  index += FFI::Readline.history_length if index < 0
  p = FFI::Readline.history_get(FFI::Readline.history_base + index)
  raise IndexError, "invalid index" if p.null?
  entry = FFI::Readline::HistoryEntry.new(p)
  entry[:line].taint
end

#[]=(index, str) ⇒ Object

Raises:

  • (IndexError)


130
131
132
133
134
135
# File 'lib/readline.rb', line 130

def []=(index, str)
  index += FFI::Readline.hisrory_length if index < 0
  p = FFI::Readline.replace_history_entry(index, str, nil)
  raise IndexError, "invalid index" if p.null?
  str
end

#delete_at(index) ⇒ Object

Raises:

  • (IndexError)


186
187
188
189
190
191
192
# File 'lib/readline.rb', line 186

def delete_at(index)
  l = FFI::Readline.history_length
  index += l if index < 0
  raise IndexError, "invalid index" if (index < 0) or (index > l - 1)
  r  = remove_history(index)
  r.taint
end

#each(&block) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/readline.rb', line 165

def each(&block)
  i = 0
  while i < FFI::Readline.history_length
    p = FFI::Readline.history_get(FFI::Readline.history_base + i)
    break if p.null?
    entry = FFI::Readline::HistoryEntry.new(p)
    block.call(String.new(entry[:line]).taint)
    i += 1
  end
  self
end

#empty?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/readline.rb', line 182

def empty?
  FFI::Readline.history_length == 0 ? true : false
end

#lengthObject Also known as: size



177
178
179
# File 'lib/readline.rb', line 177

def length
  FFI::Readline.history_length
end

#popObject



152
153
154
155
156
157
# File 'lib/readline.rb', line 152

def pop
  l = FFI::Readline.history_length
  return nil if l <= 0
  r = remove_history(l - 1)
  r.taint
end

#push(*args) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/readline.rb', line 144

def push(*args)
  for s in args
    raise TypeError unless s.respond_to?(:to_str)
    FFI::Readline.add_history(s.to_str)
  end
  HISTORY
end

#shiftObject



159
160
161
162
163
# File 'lib/readline.rb', line 159

def shift
  return nil unless FFI::Readline.history_length > 0
  r = remove_history(0)
  r.taint
end

#to_sObject



120
# File 'lib/readline.rb', line 120

def to_s; "HISTORY" end