[ditz-talk] [PATCH] added GNU/Readline support
Ramsey Dow
yesmar at speakeasy.net
Sun Apr 13 01:54:51 EDT 2008
ditz is great, but I've got fat fingers and make a lot of typos. GNU
Readline comes with Ruby, so adding Readline support to ditz is a
simple matter of programming. Now when I make mistakes I can edit them
right there without having to use /edit. :)
yesmar
p.s. this patch should be applied to mainline
---
lib/lowline.rb | 29 ++++++++++++++++++-----------
1 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/lib/lowline.rb b/lib/lowline.rb
index 50836bc..966a1c2 100644
--- a/lib/lowline.rb
+++ b/lib/lowline.rb
@@ -1,3 +1,4 @@
+require 'readline'
require 'tempfile'
require "util"
@@ -82,8 +83,8 @@ module Lowline
end
while true
- print [q, default_s, tail].compact.join
- ans = gets.strip
+ prompt = [q, default_s, tail].compact.join
+ ans = Readline::readline(prompt)
if opts[:default]
ans = opts[:default] if ans.blank?
else
@@ -109,16 +110,22 @@ module Lowline
puts "#{q} (ctrl-d, ., or /stop to stop, /edit to edit, /reset
to reset):"
ans = ""
while true
- print "> "
- case(line = gets) && line.strip!
- when /^\.$/, nil, "/stop"
- break
- when "/reset"
- return ask_multiline(q)
- when "/edit"
- return ask_via_editor(q, ans)
+ line = Readline::readline('> ')
+ if line
+ Readline::HISTORY.push(line)
+ case line
+ when /^\.$/, "/stop"
+ break
+ when "/reset"
+ return ask_multiline(q)
+ when "/edit"
+ return ask_via_editor(q, ans)
+ else
+ ans << line + "\n"
+ end
else
- ans << line + "\n"
+ puts
+ break
end
end
ans.multistrip
--
1.5.4.4
More information about the ditz-talk
mailing list