Class: Byebug::History
- Inherits:
-
Object
- Object
- Byebug::History
- Defined in:
- lib/byebug/history.rb
Overview
Handles byebug’s history of commands.
Class Method Summary collapse
Class Method Details
.load ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/byebug/history.rb', line 9 def load open(Setting[:histfile], 'r') do |file| file.each do |line| line.chomp! Readline::HISTORY << line end end if File.exist?(Setting[:histfile]) end |
.save ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/byebug/history.rb', line 18 def save open(Setting[:histfile], 'w') do |file| Readline::HISTORY.to_a.last(Setting[:histsize]).each do |line| file.puts line unless line.strip.empty? end end end |
.to_s(size = Setting[:histsize]) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/byebug/history.rb', line 26 def to_s(size = Setting[:histsize]) rl_size = Readline::HISTORY.length n_entries = rl_size < size ? rl_size : size first = rl_size - n_entries commands = Readline::HISTORY.to_a.last(n_entries) s = '' commands.each_with_index do |command, index| s += format("%5d %s\n", first + index + 1, command) end s end |