Roguelike project?

They seem to work for me just fine, what terminal are you using?
You could look which key codes are pushed into the @stack.

···

On Tue, Nov 4, 2008 at 3:19 PM, Nit Khair <sentinel.2001@gmx.com> wrote:

Nit Khair wrote:

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.

Nit Khair wrote:

Nit Khair wrote:

Michael Fellinger wrote:

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.

···

--
Posted via http://www.ruby-forum.com/\.

Nit Khair wrote:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.

It supports "darwin", but not the "powerpc" cpu.

···

--
Posted via http://www.ruby-forum.com/\.

I'm running on Ubuntu 8.10:

$ ruby -v
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-linux]

Regards,
Sean

···

On Mon, Nov 3, 2008 at 3:42 PM, Nit Khair <sentinel.2001@gmx.com> wrote:

Sean O'halpin wrote:

Yes - the FFI interface is really easy to use. You just need to
specify which lib you are referencing with the #ffi_lib method.

require 'rubygems'
require 'ffi'

module NCursesFFI
  extend FFI::Library

Seem to be other dependencies other than the gem (which installed fine).
Does it expect Jruby or rubinius ? I get:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.
--

Michael Fellinger wrote:

Nit Khair wrote:

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.

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.

···

On Tue, Nov 4, 2008 at 3:19 PM, Nit Khair <sentinel.2001@gmx.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

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/\.

Michael Fellinger wrote:

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.

···

--
Posted via http://www.ruby-forum.com/\.

Nit Khair wrote:

Nit Khair wrote:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.

It supports "darwin", but not the "powerpc" cpu.

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

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

···

On Mon, Nov 10, 2008 at 12:16 AM, Nit Khair <sentinel.2001@gmx.com> wrote:

Michael Fellinger wrote:

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.

Charles Oliver Nutter wrote:

Nit Khair wrote:

Nit Khair wrote:

NameError: uninitialized constant FFI::Platform::ARCH_

Or maybe it does not work on OS X yet.

It supports "darwin", but not the "powerpc" cpu.

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 ?

···

--
Posted via http://www.ruby-forum.com/\.

Michael Fellinger wrote:

···

On Mon, Nov 10, 2008 at 12:16 AM, Nit Khair <sentinel.2001@gmx.com> > wrote:

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

Thanks a million. I really appreciate this. I should be able to get my
head around this.
Cheers.

--
Posted via http://www.ruby-forum.com/\.

Nit Khair wrote:

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

Nit Khair wrote:

Michael Fellinger wrote:

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

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

···

On Mon, Nov 10, 2008 at 12:16 AM, Nit Khair <sentinel.2001@gmx.com> >> wrote:

--
Posted via http://www.ruby-forum.com/\.

Nit Khair wrote:

Michael Fellinger wrote:

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

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.

···

On Mon, Nov 10, 2008 at 4:57 AM, Nit Khair <sentinel.2001@gmx.com> wrote:

On Mon, Nov 10, 2008 at 12:16 AM, Nit Khair <sentinel.2001@gmx.com> >>> wrote:

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

--
Posted via http://www.ruby-forum.com/\.

Michael Fellinger wrote:

···

On Mon, Nov 10, 2008 at 4:57 AM, Nit Khair <sentinel.2001@gmx.com> > wrote:

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.

Works like a charm :smiley:
--
Posted via http://www.ruby-forum.com/\.

Michael Fellinger wrote:

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.

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.

···

On Mon, Nov 10, 2008 at 4:57 AM, Nit Khair <sentinel.2001@gmx.com> > wrote:

--
Posted via http://www.ruby-forum.com/\.

Michael Fellinger wrote:

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.

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 :slight_smile:

^ manveru

···

On Tue, Nov 11, 2008 at 12:28 AM, Nit Khair <sentinel.2001@gmx.com> wrote:

On Mon, Nov 10, 2008 at 4:57 AM, Nit Khair <sentinel.2001@gmx.com> >> wrote:

Michael Fellinger wrote:

···

On Tue, Nov 11, 2008 at 12:28 AM, Nit Khair <sentinel.2001@gmx.com> > wrote:

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 :slight_smile:
easy count prefix via count_map: 10j, 200b, 20%, 42g, 7up, ... · manveru/ver@9fb04aa · GitHub

^ manveru

I've only integrated the count_map as yet.

Absolutely brilliant. Works like a dream :smiley:
--
Posted via http://www.ruby-forum.com/\.

Michael Fellinger wrote:

I fixed that just today, check it out :slight_smile:
easy count prefix via count_map: 10j, 200b, 20%, 42g, 7up, ... · manveru/ver@9fb04aa · GitHub

^ manveru

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.

···

--
Posted via http://www.ruby-forum.com/\.

Nit Khair wrote:

Michael Fellinger wrote:

I fixed that just today, check it out :slight_smile:
easy count prefix via count_map: 10j, 200b, 20%, 42g, 7up, ... · manveru/ver@9fb04aa · GitHub

^ manveru

I've only integrated the count_map as yet.

Absolutely brilliant. Works like a dream :smiley:

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.

···

On Tue, Nov 11, 2008 at 12:28 AM, Nit Khair <sentinel.2001@gmx.com> >> wrote:

--
Posted via http://www.ruby-forum.com/\.