Module: ClusterBomb::History

Included in:
BombShell
Defined in:
lib/cluster_bomb/history.rb

Constant Summary collapse

HISTORY_FILE =
File.join(Configuration::HOME,'history')

Instance Method Summary collapse

Instance Method Details

#libedit?Boolean

Cheesy check to see if libedit is in use – will affect history

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'lib/cluster_bomb/history.rb', line 31

def libedit?
  libedit = false
  # If NotImplemented then this might be libedit
  begin
    Readline.emacs_editing_mode
  rescue NotImplementedError
    libedit = true
  end
  libedit
end

#load_history(max_history = 500) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cluster_bomb/history.rb', line 16

def load_history(max_history=500)
  @max_history = max_history      
  return unless File.exists? HISTORY_FILE
  File.open(HISTORY_FILE, "r") do |f|
    c=0
    while line = f.gets
      Readline::HISTORY.push(line.strip)
      if c==0 && libedit? # libedit work-around 
        Readline::HISTORY.push(line.strip)
      end
      c+=1
    end
  end
end

#save_historyObject



6
7
8
9
10
11
12
13
14
# File 'lib/cluster_bomb/history.rb', line 6

def save_history
  save_history =  Readline::HISTORY.to_a.dup
  start=0
  start = save_history.length - @max_history if save_history.length > @max_history
  
  File.open(HISTORY_FILE, "w") do |f|
    save_history[start..-1].each {|l| f.puts(l)}
  end
end