Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created May 25, 2011 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/990164 to your computer and use it in GitHub Desktop.
Save havenwood/990164 to your computer and use it in GitHub Desktop.
require 'readline'
# Empty and dup are BAD.
# 1. Read line and append to history
# 2. Quick Break on nil
# 3. Remove from history if empty or dup
def readline_lineread
line = Readline.readline('> ', true)
return nil if line.nil?
if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
Readline::HISTORY.pop
end
line
end
# Debug
while line = readline_lineread
p line
p Readline::HISTORY.to_a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment