aboutsummaryrefslogtreecommitdiff
path: root/ruby/mal_readline.rb
blob: 3799783b8e665de39a4675186cfbff71cc4da89b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
require "readline"

$history_loaded = false
$histfile = "#{ENV['HOME']}/.mal-history"

def _readline(prompt)
    if !$history_loaded && File.exist?($histfile)
        $history_loaded = true
        File.readlines($histfile).each {|l| Readline::HISTORY.push(l.chomp)}
    end

    if line = Readline.readline(prompt, true)
        File.open($histfile, 'a+') {|f| f.write(line+"\n")}
        return line
    else
        return nil
    end
end