Class: Chake::Readline
- Inherits:
-
Object
show all
- Defined in:
- lib/chake/readline.rb
Defined Under Namespace
Classes: Commands, Recipes
Class Method Summary
collapse
Class Method Details
.finish ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/chake/readline.rb', line 27
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
|
.history ⇒ Object
13
14
15
|
# File 'lib/chake/readline.rb', line 13
def history
@history ||= []
end
|
.history_file ⇒ Object
9
10
11
|
# File 'lib/chake/readline.rb', line 9
def history_file
raise NotImplementedError
end
|
.init ⇒ Object
21
22
23
24
25
|
# File 'lib/chake/readline.rb', line 21
def init
return unless File.exist?(history_file)
@history = File.readlines(history_file).map(&:strip)
end
|
.prompt ⇒ Object
17
18
19
|
# File 'lib/chake/readline.rb', line 17
def prompt
raise NotImplementedError
end
|
.readline ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/chake/readline.rb', line 37
def readline
::Readline::HISTORY.clear
history.each do |cmd|
::Readline::HISTORY.push(cmd)
end
input = ::Readline.readline(prompt)
history.push(input) if input && input.strip != '' && input != @last
input
end
|