aboutsummaryrefslogtreecommitdiff
path: root/ruby/mal_readline.rb
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-17 22:23:07 -0500
committerJoel Martin <github@martintribe.org>2014-04-17 22:23:07 -0500
commit718887c3019c49fc807bc18fbd5feb975ec03c85 (patch)
tree8b0d1d2e501541c015e66f4cde0510bdd94db195 /ruby/mal_readline.rb
parentdb4c329aff4621e05b92a55be4f18173f5a4f655 (diff)
downloadmal-718887c3019c49fc807bc18fbd5feb975ec03c85.tar.gz
mal-718887c3019c49fc807bc18fbd5feb975ec03c85.zip
Ruby,Python,C#: readline history fixes. Ruby include path.
Diffstat (limited to 'ruby/mal_readline.rb')
-rw-r--r--ruby/mal_readline.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/ruby/mal_readline.rb b/ruby/mal_readline.rb
new file mode 100644
index 0000000..63c5571
--- /dev/null
+++ b/ruby/mal_readline.rb
@@ -0,0 +1,18 @@
+require "readline"
+
+$history_loaded = false
+$histfile = "#{ENV['HOME']}/.mal-history"
+
+def _readline(prompt)
+ if not $history_loaded
+ $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