Get pry to display characters like [äöüßÄÖÜß] (utf-8 encoding)? (Possibly Windows-specific issue?)

三世轮回 提交于 2019-12-30 06:58:06

问题


[All the scripts I'm working with with these German characters are in UTF-8 themselves, have #encoding: utf-8 at the top (and Encoding.external_default = 'utf-8', not that that's really relevant I think because German chars in strings that are defined within the script don't get displayed right.)]

All these things display fine at the windows command prompt and using irb etc.

I can't even enter these characters at the pry prompt, though. Attempting to paste in puts "äöüÄÖÜß" gets puts ". Attempting to actually type them freezes pry somehow, and I have to ^D out.

Using pry, I ran a script with GC = "äöüÄÖÜß" in it, and this is the kind of garbledeegook I get:

[1] pry(main)> GC                               
=> "├ñ├Â├╝├ä├û├£├ƒ"                             
[2] pry(main)> GC.split('').each{ |c| puts c }  
ä                                              
├                                              
├╝                                              
Ä                                              
Ö                                              
Ü                                              
ß                                              
=> ["├ñ", "├Â", "├╝", "├ä", "├û", "├£", "├ƒ"]
[3] pry(main)> File.open("output.txt", 'w'){|f| GC.split('').each{ |c| f.puts c } }

The test file output.txt created by that last line, however, is in utf-8 and reads:

ä
ö
ü
Ä
Ö
Ü
ß

Does anyone have any ideas how to fix this?


回答1:


I know that if you install Ruby with readline support, then you doesn't have this problem. To do so you will need something like this if you are using rbenv (with ruby-build):

RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline`" rbenv install 1.9.3

I don't know if there are other solutions though.



来源:https://stackoverflow.com/questions/16211133/get-pry-to-display-characters-like-%c3%a4%c3%b6%c3%bc%c3%9f%c3%84%c3%96%c3%9c%c3%9f-utf-8-encoding-possibly-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!