Skip to content

Instantly share code, notes, and snippets.

@abinoam
Created September 10, 2015 03:43
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 abinoam/c8e81f7c0e851bee40f4 to your computer and use it in GitHub Desktop.
Save abinoam/c8e81f7c0e851bee40f4 to your computer and use it in GitHub Desktop.
RbReadline multibyte support test
#coding: utf-8
# This will remove old Readline if it's already defined
require 'rb-readline'
# This will load RbReadline for real
require 'rbreadline'
# This will load Readline that relies on RbReadline
require 'readline'
Readline.completion_proc = lambda do |str|
[ "pure_ascii", "with_utf_8_characters_like_ã_and_ç" ].grep(/\A#{Regexp.escape(str)}/)
end
line = Readline.readline("> ", false)
puts "Got: #{line}"
STDOUT.puts "RbReadline::RB_READLINE_VERSION #{RbReadline::RB_READLINE_VERSION}"
STDOUT.puts "Readline::VERSION #{Readline::VERSION}"
STDOUT.puts "RUBY_DESCRIPTION #{RUBY_DESCRIPTION}"
@djberg96
Copy link

I got this on my Mac:

> with_utf_8_characters_like_ã_and_çrbreadline.rb:13:in `===': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) (Encoding::CompatibilityError)
from rbreadline.rb:13:in `each'
from rbreadline.rb:13:in `grep'
from rbreadline.rb:13:in `block in <main>'
from /Users/dberger/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rb-readline-0.5.3/lib/readline.rb:136:in `call'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment