Common Lisp: Add documentation
[jackhill/mal.git] / ruby / mal_readline.rb
1 require "readline"
2
3 $history_loaded = false
4 $histfile = "#{ENV['HOME']}/.mal-history"
5
6 def _readline(prompt)
7 if !$history_loaded && File.exist?($histfile)
8 $history_loaded = true
9 if File.readable?($histfile)
10 File.readlines($histfile).each {|l| Readline::HISTORY.push(l.chomp)}
11 end
12 end
13
14 if line = Readline.readline(prompt, true)
15 if File.writable?($histfile)
16 File.open($histfile, 'a+') {|f| f.write(line+"\n")}
17 end
18 return line
19 else
20 return nil
21 end
22 end