sunaku / wmiirc

Ruby configuration for WMII window manager
ISC License
82 stars 26 forks source link

Encoding error! ascii8 utf8 == xterm? #19

Closed ghedamat closed 13 years ago

ghedamat commented 14 years ago

Wel.. i'm here again..

another issue raised up...

i've turned my xterm to utf8+256 colors and something strange happens..

when i'm on a gtk/qt application particularity skype...

I have no idea about that but trying to rise up an xterm with mod4+x as I'm used to causes wmii to crash giving this error...

/home/tha/.wmii/control/action/launch.yaml:control:keyboard_action:launch_terminal:13:in expand_path' /home/tha/.wmii/control/action/launch.yaml:control:keyboard_action:launch_terminal:13:inblock (4 levels) in control' /home/tha/.wmii/control/action/launch.yaml:control:keyboard_action:launch_terminal:12:in reverse_each' /home/tha/.wmii/control/action/launch.yaml:control:keyboard_action:launch_terminal:12:inblock (3 levels) in control' /home/tha/.wmii/lib/wmiirc/handler.rb:20:in call' /home/tha/.wmii/lib/wmiirc/handler.rb:20:inblock in handle' /home/tha/.wmii/lib/wmiirc/handler.rb:19:in each' /home/tha/.wmii/lib/wmiirc/handler.rb:19:inhandle' /home/tha/.wmii/lib/wmiirc/handler.rb:73:in key' /home/tha/.wmii/lib/wmiirc/config.rb:99:inblock (2 levels) in control' /home/tha/.wmii/lib/wmiirc/handler.rb:20:in call' /home/tha/.wmii/lib/wmiirc/handler.rb:20:inblock in handle' /home/tha/.wmii/lib/wmiirc/handler.rb:19:in each' /home/tha/.wmii/lib/wmiirc/handler.rb:19:inhandle' /home/tha/.wmii/lib/wmiirc/handler.rb:39:in event' /home/tha/.wmii/lib/wmiirc/loader.rb:94:inblock (2 levels) in enter_event_loop' /home/tha/.wmii/lib/wmiirc/loader.rb:90:in each' /home/tha/.wmii/lib/wmiirc/loader.rb:90:inblock in enter_event_loop' /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rumai-3.3.1/lib/rumai/fs.rb:105:in each_line' /usr/local/rvm/gems/ruby-1.9.2-p0/gems/rumai-3.3.1/lib/rumai/fs.rb:105:inblock in each_line'

i'm running funtoo linux ruby 1.9.2 with rvm wmii-hg with libixp-hg

thank you very much for your help as usual!

let me know if i can be useful

Mattia

sunaku commented 13 years ago

Sorry for the late response, I was away on holiday.

The problem is that your xterm title is UTF-8 whereas the File.expand_path() call at control/action/launch.yaml:17 is expecting ASCII-8BIT encoding.

Try changing that line into this:

path = File.expand_path(s.encode('ASCII-8BIT'))
ghedamat commented 13 years ago

No problem.. it's a marginal issue, and surely due to some sort of my fault..

Well.. the error remains the same :)

looking at s.encoding seems that normally the string encoding is US-ASCII but when I open the terminal from skype than the encoding is ASCII-8BIT...

trying to force it to ASCII-8BIT hence does nothing but trying to change it to UTF-8 or something else like US-ASCII rises a conversion error saying charset is incompatible..

??? I'm really a UTF8 noob... any hint is appreciated

thank you anyway for your help :) as usual.. :)

sunaku commented 13 years ago

Since encoding conversion is not working, try this:

path = File.expand_path(s) rescue s
ghedamat commented 13 years ago

it worked! Now i've to discover why! :P

thanks!

sunaku commented 13 years ago

The reason I use File.expand_path() is to take care of ~ in the paths. For example if your currently selected client has the title some_program ~/foo/bar.rb then Ruby will not be able to File.open("~/foo/bar.rb") because it does not know what ~ is. We have to do File.open(File.expand_path("~/foo/bar.rb")) for things to work properly.

In this case, we just give up if the path expansion fails and try to use the raw path instead (that's what the rescue clause does).

Hope that explains things. Cheers.

ghedamat commented 13 years ago

yes! I'm used to File.expand_path but didn't know about rescue used like this :)

thanks!

sunaku commented 13 years ago

Commit bef08e74da22eca6d8b40a6362224228e8a0e47d really solves this issue.

ghedamat commented 13 years ago

tested and it works! have to understand why :P but no time right know..

as usual many thanks!