Skip to content

Instantly share code, notes, and snippets.

@abinoam
Created September 10, 2015 03:43
Show Gist options
  • 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}"
@abinoam
Copy link
Author

abinoam commented Sep 10, 2015

My output is when I try to autocomplete with tab the "with_utf_8_characters_like_ã_and_ç"string is bellow:

RbReadline::RB_READLINE_VERSION 0.5.3
Readline::VERSION 5.2
RUBY_DESCRIPTION ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
>
pure_ascii                         with_utf_8_characters_like_ã_and_ç
> wi/Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:3863:in `codepoints': invalid byte sequence in UTF-8 (ArgumentError)
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:3863:in `_rl_col_width'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:2956:in `update_line'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:3542:in `rl_redisplay'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:4683:in `_rl_internal_char_cleanup'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:4744:in `readline_internal_charloop'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:4808:in `readline_internal'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/rbreadline.rb:4830:in `readline'
    from /Users/abinoam/.rvm/gems/ruby-2.2.3/gems/rb-readline-0.5.3/lib/readline.rb:45:in `readline'
    from ptests/test_rbreadline_multibyte_support.rb:20:in `<main>'

@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