Michael Fellinger wrote:
Still want to hear
from you about alt keys.
They seem to work for me just fine, what terminal are you using?
You could look which key codes are pushed into the @stack.
1. manver. what do the alt-keys print for you (or send to press() ) ?
2. I have found the issue:
when you generate PRINTABLE_KEYS as follows:
PRINTABLE.each do |key|
code = key.unpack('c')[0] # using unpack to be compatible with 1.9
PRINTABLE_KEYS[code] = key
MOD_KEYS[[ESC, code]] = "M-#{key}" unless key == '[' # don't map
esc
end
in line: PRINTABLE_KEYS[code] = key
for ALT-A which is 165, 165.chr = "\245" (slash 245)
the key unpack line generates "-91".
So PRINTABLE_KEYS has: -91 => "\245"
instead of : 165 => "\245"
Thus, nothing is being picked up in line 41:
NCURSES_KEYS[char] || CONTROL_KEYS[char] || PRINTABLE_KEYS[char]
If I do: "\245"[0], I get 165. btw, I am using ruby 1.8.7 not 1.9.
I did a quick check with:
key.unpack('C')[0]
and this gives me 165. So perhaps, instead of:
- code = key.unpack('c')[0] # using unpack to be compatible with
1.9
it should be (C - unsigned int)
+ code = key.unpack('C')[0] # using unpack to be compatible with
1.9
···
------------
I cannot verify this due to something extremely baffling to me:
in IRB,
ASCII = (0..255).map{|c| c.chr }
PRINTABLE = ASCII.grep(/[[:print:]]/)
PRINTABLE.length
191
However, inside the ruby program PRINTABLE.length only gives 95 !! ???
#!/opt/local/bin/ruby
ASCII = (0..255).map{|c| c.chr }
puts(ASCII.length)
PRINTABLE = ASCII.grep(/[[:print:]]/)
puts(PRINTABLE.length)
So the alt-codes are lost. I am using the same terminal for both. I am
using the same ruby interpreter in the sample program, as the one irb is
using.
Can someone tell me why the grep command returns a different result in
irb vs a ruby program ???
--
Posted via http://www.ruby-forum.com/\.