Module: Chake::Readline

Defined in:
lib/chake/readline.rb

Class Method Summary collapse

Class Method Details

.finish ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/chake/readline.rb', line 22

def finish
  history = ::Readline::HISTORY.map { |line| line }
  File.open(history_file, 'w') do |f|
    history.last(500).each do |line|
      f.puts(line)
    end
  end
end

.history_file ⇒ Object



10
11
12
# File 'lib/chake/readline.rb', line 10

def history_file
  File.join(Dir.home, '.chake_history')
end

.init ⇒ Object



14
15
16
17
18
19
20
# File 'lib/chake/readline.rb', line 14

def init
  return if !File.exists?(history_file)
  File.readlines(history_file).each do |line|
    @last = line.strip
    ::Readline::HISTORY.push(@last)
  end
end

.readline ⇒ Object



31
32
33
34
35
36
37
# File 'lib/chake/readline.rb', line 31

def readline
  input = ::Readline.readline('$ ')
  if input && input.strip != '' && input != @last
    ::Readline::HISTORY.push(input)
  end
  input
end