1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-13 11:23:59 +03:00
mal/ruby/mal_readline.rb
Joel Martin c9de2e82ed Tests: add testing Dockerfile. Impl fixes.
- tests/docker/Dockerfile: specifies full docker image containing all
  tools/languages (except matlab).
- tests/docker-build.sh: build above image.
- tests/docker-run.sh: launch above image.
    Example: ./tests/docker-run.sh make test^js^step2
- Various fixes across multiple languages:
    - Unicode fixes for bash and R on Ubuntu Utopic
    - readline history fixes for when ~/.mal-history is not available
      or readable/writable. No fatal errors.
    - fixes to work with perl 5.20 (and still perl 5.18)
2015-03-11 22:22:35 -05:00

23 lines
548 B
Ruby

require "readline"
$history_loaded = false
$histfile = "#{ENV['HOME']}/.mal-history"
def _readline(prompt)
if !$history_loaded && File.exist?($histfile)
$history_loaded = true
if File.readable?($histfile)
File.readlines($histfile).each {|l| Readline::HISTORY.push(l.chomp)}
end
end
if line = Readline.readline(prompt, true)
if File.writable?($histfile)
File.open($histfile, 'a+') {|f| f.write(line+"\n")}
end
return line
else
return nil
end
end