Class: Chake::Readline

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

Direct Known Subclasses

Commands, Recipes

Defined Under Namespace

Classes: Commands, Recipes

Class Method Summary collapse

Class Method Details

.finishObject



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

def finish
  return if !File.writable?(File.dirname(history_file)) || history.empty?
  File.open(history_file, 'w') do |f|
    history.last(500).each do |line|
      f.puts(line)
    end
  end
end

.historyObject



16
17
18
# File 'lib/chake/readline.rb', line 16

def history
  @history ||= []
end

.history_fileObject

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/chake/readline.rb', line 12

def history_file
  raise NotImplementedError
end

.initObject



24
25
26
27
# File 'lib/chake/readline.rb', line 24

def init
  return if !File.exists?(history_file)
  @history = File.readlines(history_file).map(&:strip)
end

.promptObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/chake/readline.rb', line 20

def prompt
  raise NotImplementedError
end

.readlineObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chake/readline.rb', line 38

def readline
  ::Readline::HISTORY.clear
  history.each do |cmd|
    ::Readline::HISTORY.push(cmd)
  end
  input = ::Readline.readline(prompt)
  if input && input.strip != '' && input != @last
    history.push(input)
  end
  input
end