On Thu, Aug 17, 2006 at 04:11:08PM +0200, nobu / ruby-lang.org wrote:
> Hi,
> 
> At Thu, 17 Aug 2006 21:21:39 +0900,
> Ondrej Bilka wrote in [ruby-core:08656]:
> > Another issue at head is that Curses.getch still returns int.
> > Problem is that when keypad is set it returns pseudokeycodes, so we have
> > to convert only when <256.
> 
> It's a problem.
> 
> Only way I thought of is they return
> 
>   * a String for ordinary key,
>   * a Fixnum for keypad, and
>   * nil for ERR.
> 
Dont forget constants. All in Curses::Key are from keypad
Exception are KEY_CTRL_foo Because they are declared only in Curses and can be
replaced by "\C-foo" I would delete it



Index: ext/curses/curses.c
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/curses/curses.c,v
retrieving revision 1.33
diff -p -u -2 -r1.33 curses.c
--- ext/curses/curses.c	28 Jul 2006 08:18:22 -0000	1.33
+++ ext/curses/curses.c	17 Aug 2006 13:46:18 -0000
@@ -383,4 +383,15 @@ curses_addstr(VALUE obj, VALUE str)
 }
 
+static VALUE
+getch_value(int c)
+{
+    if (c == ERR) return Qnil;
+    if (!(c & KEY_CODE_YES)) {
+	char cc = (char)c;
+	return rb_tainted_str_new(&cc, 1);
+    }
+    return UINT2NUM(c);
+}
+
 /* def getch */
 static VALUE
@@ -389,5 +400,5 @@ curses_getch(VALUE obj)
     rb_read_check(stdin);
     curses_stdscr();
-    return UINT2NUM(getch());
+    return getch_value(getch());
 }
 
@@ -1068,8 +1079,8 @@ window_getch(VALUE obj)
 {
     struct windata *winp;
-    
+
     rb_read_check(stdin);
     GetWINDOW(obj, winp);
-    return UINT2NUM(wgetch(winp->window));
+    return getch_value(wgetch(winp->window));
 }

@@ -2006,14 +2006,6 @@
     rb_curses_define_const(KEY_MAX);
     rb_define_const(mKey, "MAX", INT2NUM(KEY_MAX));
 #endif
-    {
-      int c;
-      char name[] = "KEY_CTRL_x";
-      for( c = 'A'; c <= 'Z'; c++ ){
-	sprintf(name, "KEY_CTRL_%c", c);
-	rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1));
-      }
-    }
 #undef rb_curses_define_const
 
     rb_set_end_proc(curses_finalize, 0);