Skip to content

Commit

Permalink
return array with return type and ruby string
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Nov 19, 2013
1 parent 5475417 commit 25ade76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 8 additions & 2 deletions examples/form_get_wch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
scr.refresh()

# Loop through to get user requests
while((ch = Ncurses.get_wch()) != Ncurses::KEY_F1) do
while(true) do
ret = Ncurses.get_wch()

#ret[1].force_encoding('utf-8')
#puts "got: #{ret.inspect}"

ch = ret[1]
case(ch)
when Ncurses::KEY_DOWN
# Go to next field
Expand All @@ -56,7 +62,7 @@
Ncurses::Form.form_driver(form, Ncurses::Form::REQ_END_LINE);
else
# If this is a normal character, it gets Printed
Ncurses::Form.form_driver(form, ch)
Ncurses::Form.form_driver(form, ch.ord)
end
end

Expand Down
20 changes: 14 additions & 6 deletions ncurses_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,23 +913,29 @@ static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) {
return rbncurshelper_do_wgetch_functor (c_win, &wgetch);
}

/* wide char getch */
/* not thread safe: wide char getch */
static wint_t wget_wch_back;
static int my_wget_wch (WINDOW *c_win) {
return wget_wch (c_win, &wget_wch_back);
}

static int rbncurshelper_nonblocking_wget_wch(WINDOW *c_win) {
rbncurshelper_do_wgetch_functor (c_win, &my_wget_wch);
return wget_wch_back;
/* return array with first element being return key code status,
* and second element the key code */
static VALUE rbncurshelper_nonblocking_wget_wch(WINDOW *c_win) {
int retcode = rbncurshelper_do_wgetch_functor (c_win, &my_wget_wch);
//char c_str[2];
//c_str[0] = wget_wch_back;
//c_str[1] = 0;
VALUE r = rb_assoc_new (INT2NUM(retcode), rb_str_new((const char*)&wget_wch_back, 1));
return r;
}

static VALUE rbncurs_getch(VALUE dummy) {
return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr));
}

static VALUE rbncurs_get_wch(VALUE dummy) {
return LONG2NUM(rbncurshelper_nonblocking_wget_wch(stdscr));
return rbncurshelper_nonblocking_wget_wch(stdscr);
}

static VALUE rbncurs_halfdelay(VALUE dummy, VALUE arg1) {
Expand Down Expand Up @@ -1572,9 +1578,11 @@ static VALUE rbncurs_werase(VALUE dummy, VALUE arg1) {
static VALUE rbncurs_wgetch(VALUE dummy, VALUE arg1) {
return INT2NUM(rbncurshelper_nonblocking_wgetch(get_window(arg1)));
}

static VALUE rbncurs_wget_wch(VALUE dummy, VALUE arg1) {
return INT2NUM(rbncurshelper_nonblocking_wget_wch(get_window(arg1)));
return rbncurshelper_nonblocking_wget_wch(get_window(arg1));
}

static VALUE rbncurs_whline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
return INT2NUM(whline(get_window(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3)));
}
Expand Down

0 comments on commit 25ade76

Please sign in to comment.