# Ruby-ncurses related problems

**URL:** <https://www.ruby-forum.com/t/ruby-ncurses-related-problems/75190>\
**Category:** Ruby\
**Created:** [November 8, 2006, 3:37am UTC](https://www.ruby-forum.com/t/ruby-ncurses-related-problems/75190 "2006-11-08T03:37:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanislaw\_Halik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Stanislaw\_Halik](https://www.ruby-forum.com/u/Stanislaw_Halik)\
**Post date:** [November 8, 2006, 3:37am UTC](https://www.ruby-forum.com/t/ruby-ncurses-related-problems/75190/1 "2006-11-08T03:37:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Stanislaw\_Halik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Stanislaw\_Halik](https://www.ruby-forum.com/u/Stanislaw_Halik)\
**Post date:** [November 8, 2006, 7:51am UTC](https://www.ruby-forum.com/t/ruby-ncurses-related-problems/75190/2 "2006-11-08T07:51:56Z")

</div>

Stanislaw Halik wrote:

> Ncurses.noecho
> 
> 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)?

---

<div class="post-metadata">

**Author:** ![Stanislaw\_Halik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@Stanislaw\_Halik](https://www.ruby-forum.com/u/Stanislaw_Halik)\
**Post date:** [November 8, 2006, 8:20am UTC](https://www.ruby-forum.com/t/ruby-ncurses-related-problems/75190/3 "2006-11-08T08:20:00Z")

</div>

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:

> > 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?
