ruby-ncurses related problems

Discussion in 'Ruby' started by Stanislaw Halik, Nov 8, 2006.

  1. Heya,

    I'm trying to learn the Ncurses module. However, nonblocking getch()
    doesn't work. A simple test case:

    -->--
    #!/usr/bin/env ruby
    require 'ncurses'
    Ncurses.initscr
    Ncurses.start_color
    Ncurses.noecho
    Ncurses.cbreak
    Ncurses.noraw
    Ncurses.stdscr.nodelay(true)
    Ncurses.stdscr.keypad(true)
    Ncurses.refresh
    while ch = Ncurses.getch
    Ncurses.printw ch.to_s
    Ncurses.refresh
    end
    --<--

    prints '10' every time no characters are in the buffer. There's no
    constant defined to be a '10' in both ncurses.h and the Ruby wrapper.
    According to getch(3), it's supposed to return an 'ERR' constant, being
    '-1'. It, however, returns '10' for some reason.

    Now i'm out of luck. There's no support contact listed on ruby-ncurses
    project's site and the Curses module seems obsolete - it doesn't
    implement w*printw()-related functions which i like using much.

    Is there some other ncurses module that actually works?
    Stanislaw Halik, Nov 8, 2006
    #1
    1. Advertising

  2. Stanislaw Halik wrote:
    > Heya,
    >
    > I'm trying to learn the Ncurses module. However, nonblocking getch()
    > doesn't work. A simple test case:
    >
    > -->--
    > #!/usr/bin/env ruby
    > require 'ncurses'
    > Ncurses.initscr
    > Ncurses.start_color
    > Ncurses.noecho
    > Ncurses.cbreak
    > Ncurses.noraw
    > Ncurses.stdscr.nodelay(true)
    > Ncurses.stdscr.keypad(true)
    > Ncurses.refresh
    > while ch = Ncurses.getch
    > Ncurses.printw ch.to_s
    > Ncurses.refresh
    > end
    > --<--
    >
    > prints '10' every time no characters are in the buffer. There's no
    > constant defined to be a '10' in both ncurses.h and the Ruby wrapper.
    > According to getch(3), it's supposed to return an 'ERR' constant, being
    > '-1'. It, however, returns '10' for some reason.
    >


    Isn't 10 an ASCII CR (or is it LF)?


    > Now i'm out of luck. There's no support contact listed on ruby-ncurses
    > project's site and the Curses module seems obsolete - it doesn't
    > implement w*printw()-related functions which i like using much.
    >
    > Is there some other ncurses module that actually works?
    >
    Michael W. Ryder, Nov 8, 2006
    #2
    1. Advertising

  3. On Wed, Nov 08, 2006, Michael W. Ryder wrote:
    >> I'm trying to learn the Ncurses module. However, nonblocking getch()
    >> doesn't work. A simple test case:


    >> -->--
    >> #!/usr/bin/env ruby
    >> require 'ncurses'
    >> Ncurses.initscr
    >> Ncurses.start_color
    >> Ncurses.noecho
    >> Ncurses.cbreak
    >> Ncurses.noraw
    >> Ncurses.stdscr.nodelay(true)
    >> Ncurses.stdscr.keypad(true)
    >> Ncurses.refresh
    >> while ch = Ncurses.getch
    >> Ncurses.printw ch.to_s
    >> Ncurses.refresh
    >> end
    >> --<--


    >> prints '10' every time no characters are in the buffer. There's no
    >> constant defined to be a '10' in both ncurses.h and the Ruby wrapper.
    >> According to getch(3), it's supposed to return an 'ERR' constant, being
    >> '-1'. It, however, returns '10' for some reason.

    > Isn't 10 an ASCII CR (or is it LF)?


    It is. However, the Return key isn't pressed at the time.

    Besides, I found a bug in the standard Curses module: macro wrapping the
    return value of getch() treats it as an unsigned integer.

    /* def getch */
    static VALUE
    curses_getch(obj)
    VALUE obj;
    {
    rb_read_check(stdin);
    curses_stdscr();
    return UINT2NUM(getch());
    ~~~~~~~~
    }

    For the value of EOF (-1, as present in ncurses), it wraps around. Where
    should I report it?
    Stanislaw Halik, Nov 8, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maxwell Hammer
    Replies:
    7
    Views:
    629
    Peter Hansen
    Jun 18, 2005
  2. Tobias Peters

    [ANN] ncurses-ruby-0.8

    Tobias Peters, Sep 2, 2003, in forum: Ruby
    Replies:
    0
    Views:
    94
    Tobias Peters
    Sep 2, 2003
  3. Armin Roehrl
    Replies:
    2
    Views:
    96
    Dick Davies
    Apr 19, 2004
  4. Tobias Peters

    [ANN] ncurses-ruby 0.9

    Tobias Peters, May 16, 2004, in forum: Ruby
    Replies:
    0
    Views:
    78
    Tobias Peters
    May 16, 2004
  5. Kenneth McDonald
    Replies:
    1
    Views:
    138
    Nit Khair
    Sep 27, 2008
Loading...

Share This Page