Roguelike project?

N

Nit Khair

Nit said:
Then for kicks, i linked only keyboard.rb to a sample program and with
only a couple lines added it worked. Prints out the control keys and ESC
key combos.
It even gets Esc-a and Esc-A separately - wonderful. (it did hang when
ESC was pressed twice).
Sorry, the hang was due to not setting half-delay. Still want to hear
from you about alt keys.
 
M

Michael Fellinger

Sorry, the hang was due to not setting half-delay. 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.
 
N

Nit Khair

Michael said:
They seem to work for me just fine, what terminal are you using?

I am using "screen". Its the only one which supported the F1.. keys. My
default xterm-color does not.
You could look which key codes are pushed into the @stack.

okay, will try that.
 
N

Nit Khair

Charles said:
Probably just some missing build flags; libffi, on which it's based,
does support Darwin on PPC.

Jump on Ruby-FFI lists if you think you can help debug and get it
working:

http://kenai.com/projects/ruby-ffi

- Charlie

The problem comes here (line 28 of platform.rb).
ARCH = case CPU.downcase
when /i?86|x86|i86pc/
"i386"
when /amd64|x86_64/
"x86_64"
else
28. raise FFI::platformError, "Unknown cpu architecture: #{ARCH_}"
end

When i checked my rbconfig.rb I have "powerpc" as the "host_cpu".

So, I changed platform.rb to :

- when /i?86|x86|i86pc/
+ when /i?86|x86|i86pc|powerpc/

... and now your sample works fine! Thanks.

Forgive me for being spoilt, but is there some script that takes a
header file, or C source and generates the attach_function lines ?
 
N

Nit Khair

Michael Fellinger wrote:
Still want to hear
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:[QUOTE]
NCURSES_KEYS[char] || CONTROL_KEYS[char] || PRINTABLE_KEYS[char][/QUOTE]

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:[QUOTE]
key.unpack('C')[0][/QUOTE]
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
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 ???
 
N

Nit Khair

Nit said:
Michael Fellinger wrote:
However, it does not accept/print the Alt-keys - is that deliberate, or
did have you not looked into it.

I have had problems with alt-keys (since they generate 2 bytes and that
goes thru my getch() loop twice, often leaving an extra char in the edit
field.

manver, I have figured out one thing about alt keys. To do this i had to
make: PRINTABLE = ASCII
until someone can tell me why irb != ruby.

In osx, there is a terminal option "Use alt as meta key". Now "alt"
gives me the same result as using Esc. So now, alt-a and Esc-a will both
generate "M-a".
Without this setting, alt-a gives 165, alt-b = 171, alt-c = 167 which is
not contiguous, and generates some junk chars.

So now i've basically duplicate esc and alt. But i accidentally
discovered something ... I can press "Esc ^A", or "Alt ^A" so i do have
a bunch more of keys i can map! Hope there's nothing more i've missed.

Your file keyboard.rb rocks, please make it a gem, so others CUI
programmers can benefit from it. Preferably standalone.
 
N

Nit Khair

manver -- a little bit of feedback regarding keyboard.rb.

1. it returns strings. If you use ncurses form drivers these take
integers. So one has to convert the value sent to an int to avoid
errors.

So typically in the start of the press method, I have done:

ret = ret[0] if ret.length == 1
ret = 32 if ret == 'space'

Even then one has to watch out for others that are not single length
tab/return/bs/ etc.... will have to check for others. Some of these are
separately handled in the case, such as tab and return so thats okay.
Others such as backspace and delete etc which were passed straight to
the driver, need to be watched out for.

2. You check for @stopping? inside the while char loop immediately after
while.
To me this means that after the user has entered the Exit key, he still
has to press one more key to actually exit. I've put the break before
the end of the loop. Would like you to confirm this.
 
C

Charles Oliver Nutter

Nit said:
So, I changed platform.rb to :

- when /i?86|x86|i86pc/
+ when /i?86|x86|i86pc|powerpc/

... and now your sample works fine! Thanks.

Can you submit this to Ruby FFI, as a bug or on the mailing list? I'm
not sure Wayne Meissner monitors ruby-talk.
Forgive me for being spoilt, but is there some script that takes a
header file, or C source and generates the attach_function lines ?

There's some generation logic for at least struct layout, but I'm not
sure if it does general function wiring. It was written by the Rubinius
guys, and there's not a lot of documentation for it I could see. Good
idea though.

I expect we'll see a flurry of fully-wired FFI-based libraries getting
released one after another very soon here, and each library is one less
library to wire.

- Charlie
 
N

Nit Khair

manver, I mentioned to your earlier that I am intending to use
keyboard.rb of the ver project.

I have also been studying keymap.rb and its associated programs so i can
get more keys like in vi and emacs. However, I understand these classes
in chunks but can't piece it together.

Wondering if you can give a small example that installs and uses keys
using these classes so i can use it. I am finding myself having to
reinvent the wheel since I am unable to grasp the code of ver.

Thanks in advance.
 
M

Michael Fellinger

manver, I mentioned to your earlier that I am intending to use
keyboard.rb of the ver project.

I have also been studying keymap.rb and its associated programs so i can
get more keys like in vi and emacs. However, I understand these classes
in chunks but can't piece it together.

Wondering if you can give a small example that installs and uses keys
using these classes so i can use it. I am finding myself having to
reinvent the wheel since I am unable to grasp the code of ver.

Hope this helps:
http://p.ramaze.net/10515

Sorry, it's quite late here, can't go into more explanation for now.
And yeah, the code is quite hard to grasp, i'm not going to change it
anymore though since it works really well for what i need, the main
difficulty is with the keymapping but i couldn't come up with anything
more elegant, the Keyboard is tied to the VER concept a bit as well,
but you should be able to improve on that easily.

^ manveru
 
N

Nit Khair

manver,
I have got the above sample working (after making some corrections. e.g.
let is not a method is was map. and map should be key.
Not sure if my corrections are correct, they are based on vi.rb.

The sample prints all keys, including Esc combinations, but does not use
C-c as a control, although the mapping is there.

key :esc, :into_control_mode
key 'C-c', :into_control_mode # esc is slow due to timeout

I also did this:

VER.map :control do
key 'C-q', :stop
key 'q', :stop
key 'r', :close
end

I assumed that under C-c I could press C-q or q or r. But these are not
mapped to C-c or Esc.
Any tips on what to do for C-c would be great.

Thanks a lot.
p.s. I have attached the file I modified from the link you gave me as
test.rb.

Attachments:
http://www.ruby-forum.com/attachment/2909/test.rb
 
M

Michael Fellinger

manver,
I have got the above sample working (after making some corrections. e.g.
let is not a method is was map. and map should be key.
Not sure if my corrections are correct, they are based on vi.rb.

Pull from the repo, there have been major changes and improvments to VER.
 
N

Nit Khair

Michael said:
Pull from the repo, there have been major changes and improvments to
VER.

manver.
I integrated your example into one of my programs. (Works fine. Changed
VER.stopping and VER.info the @focus.stopping and view.info.)

I was trying out the n-action feature: e.g 3j 10j etc.
It works fine for single digits but when i try double digits, i get:
No mapping for ["1", "2"].
I tried combinations such as :
map([/^(\d\d?)$/, 'k']){ @arg.to_i.times {view.up}}
or \d+ etc.

But apparently the stack reads one digit, and goes into ready().

1. I just want to check if multiple digits work with you, am i doing
something wrong.

2. I would like to know if you modify or improve/debug this further. Is
there some list or webpage for "ver"?

Thanks a lot for your help.
 
M

Michael Fellinger

Michael said:
Pull from the repo, there have been major changes and improvments to
VER.

manver.
I integrated your example into one of my programs. (Works fine. Changed
VER.stopping and VER.info the @focus.stopping and view.info.)

I was trying out the n-action feature: e.g 3j 10j etc.
It works fine for single digits but when i try double digits, i get:
No mapping for ["1", "2"].
I tried combinations such as :
map([/^(\d\d?)$/, 'k']){ @arg.to_i.times {view.up}}
or \d+ etc.

But apparently the stack reads one digit, and goes into ready().

1. I just want to check if multiple digits work with you, am i doing
something wrong.

Yeah, it has to be:
map([/^\d$/, /^\d$/, 'k']){ @args.join.to_i.times{ view.up }}
which is a PITA, so i made a shortcut for it, see below
2. I would like to know if you modify or improve/debug this further. Is
there some list or webpage for "ver"?

I fixed that just today, check it out :)
http://github.com/manveru/ver/commit/9fb04aa943e03850c19b0352b519d885826e7f44

^ manveru
 
N

Nit Khair

Michael said:
I integrated your example into one of my programs. (Works fine. Changed
But apparently the stack reads one digit, and goes into ready().

1. I just want to check if multiple digits work with you, am i doing
something wrong.

Yeah, it has to be:
map([/^\d$/, /^\d$/, 'k']){ @args.join.to_i.times{ view.up }}
which is a PITA, so i made a shortcut for it, see below
2. I would like to know if you modify or improve/debug this further. Is
there some list or webpage for "ver"?

I fixed that just today, check it out :)
http://github.com/manveru/ver/commit/9fb04aa943e03850c19b0352b519d885826e7f44

^ manveru

I've only integrated the count_map as yet.

Absolutely brilliant. Works like a dream :-D
 
N

Nit Khair

Nit said:
I've only integrated the count_map as yet.

Absolutely brilliant. Works like a dream :-D

manver,

macros were not working for me. Are they working with you?

I traced it down to the line in keymap.rb
@keys << Key.new(*args, &block)
where the key was created but not getting inserted into @keys.

Finally, I found that key assignments, when inspected, show "e" (for key
e), whereas a macro for e will show ["e"].
So i tried flattening and its worked out. Don't know the impact of this,
though.

def map(*args, &block)
if block_given?
args.flatten!
@keys << Key.new(args, &block)
else
self[*args]
end
end

btw, the sample vi.rb that you gave has the count_map lines for up and
down mapped incorrectly (up is mapped to down, and vice-versa)

Thanks.
 
N

Nit Khair

Michael said:

Manveru

I have a question regarding the scope of the keybindings. Being new to
ruby am confused.

Are these done in a global/application scope. I mean :
@keyhandler = VER::KeyHandler.new(self)
VER.let :insert do
map(/^([[:print:]])$/){ view.show(@arg) }

Here, i have defined a key handler, but i don't see an object for my key
mappings.

My application is slightly different from vi - its multi-screen. Take
alpine e.g. Each screen has its own mappings. I go from menu, to screen
A, then screen B, then back to menu. All objects in screen A are
released so the mappings too are. Thus each screen has its own bindings
mappings.

Am i correct in thinking that as per VER, my entire app would have to
share the same bindings?

thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top