Class: Readline::History
- Inherits:
-
Object
- Object
- Readline::History
- Extended by:
- Enumerable
- Defined in:
- lib/readline.rb
Overview
The History class encapsulates a history of all commands entered by users at the prompt, providing an interface for inspection and retrieval of all commands.
Class Method Summary collapse
-
.<<(str) ⇒ Object
Synonym for Readline.add_history.
-
.[](index) ⇒ Object
Returns the command that was entered at the specified
index
in the history buffer. -
.[]=(index, str) ⇒ Object
Sets the command
str
at the given index in the history buffer. -
.delete_at(index) ⇒ Object
Deletes an entry from the histoyr buffer at the specified
index
. -
.each ⇒ Object
Iterates over each entry in the history buffer.
-
.empty? ⇒ Boolean
Returns a bolean value indicating whether or not the history buffer is empty.
-
.length ⇒ Object
Returns the length of the history buffer.
-
.pop ⇒ Object
Removes and returns the last element from the history buffer.
-
.push(*args) ⇒ Object
Pushes a list of
args
onto the history buffer. -
.rb_remove_history(index) ⇒ Object
Internal function that removes the item at
index
from the history buffer, performing necessary duplication in the process. -
.shift ⇒ Object
Removes and returns the first element from the history buffer.
-
.size ⇒ Object
Synonym for Readline.length.
-
.to_s ⇒ Object
The History class, stringified in all caps.
Class Method Details
.<<(str) ⇒ Object
Synonym for Readline.add_history.
344 345 346 |
# File 'lib/readline.rb', line 344 def self.<<(str) RbReadline.add_history(str) end |
.[](index) ⇒ Object
Returns the command that was entered at the specified index
in the history buffer.
Raises an IndexError if the entry is nil.
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/readline.rb', line 315 def self.[](index) if index < 0 index += RbReadline.history_length end entry = RbReadline.history_get(RbReadline.history_base+index) if entry.nil? raise IndexError,"invalid index" end entry.line.dup end |
.[]=(index, str) ⇒ Object
Sets the command str
at the given index in the history buffer.
You can only replace an existing entry. Attempting to create a new entry will result in an IndexError.
331 332 333 334 335 336 337 338 339 340 |
# File 'lib/readline.rb', line 331 def self.[]=(index,str) if index<0 index += RbReadline.history_length end entry = RbReadline.replace_history_entry(index,str,nil) if entry.nil? raise IndexError,"invalid index" end str end |
.delete_at(index) ⇒ Object
Deletes an entry from the histoyr buffer at the specified index
.
423 424 425 426 427 428 429 430 431 |
# File 'lib/readline.rb', line 423 def self.delete_at(index) if index < 0 i += RbReadline.history_length end if index < 0 || index > RbReadline.history_length - 1 raise IndexError, "invalid index" end rb_remove_history(index) end |
.each ⇒ Object
Iterates over each entry in the history buffer.
393 394 395 396 397 398 399 400 |
# File 'lib/readline.rb', line 393 def self.each() for i in 0 ... RbReadline.history_length entry = RbReadline.history_get(RbReadline.history_base + i) break if entry.nil? yield entry.line.dup end self end |
.empty? ⇒ Boolean
Returns a bolean value indicating whether or not the history buffer is empty.
417 418 419 |
# File 'lib/readline.rb', line 417 def self.empty?() RbReadline.history_length == 0 end |
.length ⇒ Object
Returns the length of the history buffer.
404 405 406 |
# File 'lib/readline.rb', line 404 def self.length() RbReadline.history_length end |
.pop ⇒ Object
Removes and returns the last element from the history buffer.
373 374 375 376 377 378 379 |
# File 'lib/readline.rb', line 373 def self.pop() if RbReadline.history_length>0 rb_remove_history(RbReadline.history_length-1) else nil end end |
.push(*args) ⇒ Object
Pushes a list of args
onto the history buffer.
350 351 352 353 354 |
# File 'lib/readline.rb', line 350 def self.push(*args) args.each do |str| RbReadline.add_history(str) end end |
.rb_remove_history(index) ⇒ Object
Internal function that removes the item at index
from the history buffer, performing necessary duplication in the process. – TODO: mark private?
361 362 363 364 365 366 367 368 369 |
# File 'lib/readline.rb', line 361 def self.rb_remove_history(index) entry = RbReadline.remove_history(index) if (entry) val = entry.line.dup entry = nil return val end nil end |
.shift ⇒ Object
Removes and returns the first element from the history buffer.
383 384 385 386 387 388 389 |
# File 'lib/readline.rb', line 383 def self.shift() if RbReadline.history_length>0 rb_remove_history(0) else nil end end |
.size ⇒ Object
Synonym for Readline.length.
410 411 412 |
# File 'lib/readline.rb', line 410 def self.size() RbReadline.history_length end |
.to_s ⇒ Object
The History class, stringified in all caps. – Why?
306 307 308 |
# File 'lib/readline.rb', line 306 def self.to_s "HISTORY" end |