ncurses-ruby 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,100 @@
1
+ /*
2
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
3
+ * (C) 2002, 2003 Tobias Peters <t-peters@berlios.de>
4
+ * (C) 2004 Simon Kaczor <skaczor@cox.net>
5
+ *
6
+ * This module is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2 of the License, or (at your option) any later version.
10
+ *
11
+ * This module is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this module; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ *
20
+ * $Id: ncurses_wrap.h,v 1.2 2004/07/31 08:35:13 t-peters Exp $
21
+ *
22
+ * This file was adapted from the original ncurses header file which
23
+ * has the following copyright statements:
24
+ */
25
+
26
+ /****************************************************************************
27
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
28
+ * *
29
+ * Permission is hereby granted, free of charge, to any person obtaining a *
30
+ * copy of this software and associated documentation files (the *
31
+ * "Software"), to deal in the Software without restriction, including *
32
+ * without limitation the rights to use, copy, modify, merge, publish, *
33
+ * distribute, distribute with modifications, sublicense, and/or sell *
34
+ * copies of the Software, and to permit persons to whom the Software is *
35
+ * furnished to do so, subject to the following conditions: *
36
+ * *
37
+ * The above copyright notice and this permission notice shall be included *
38
+ * in all copies or substantial portions of the Software. *
39
+ * *
40
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
41
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
42
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
43
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
44
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
45
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
46
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
47
+ * *
48
+ * Except as contained in this notice, the name(s) of the above copyright *
49
+ * holders shall not be used in advertising or otherwise to promote the *
50
+ * sale, use or other dealings in this Software without prior written *
51
+ * authorization. *
52
+ ****************************************************************************/
53
+
54
+ /****************************************************************************
55
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
56
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
57
+ ****************************************************************************/
58
+
59
+ /*
60
+ NOT IMPLEMENTED:
61
+ - terminfo, termcap-functions
62
+ - rippoffline
63
+ - v*printw functions (but normal printw functions are supported!)
64
+ */
65
+
66
+ #if defined(HAVE_GETWIN) || defined(HAVE_PUTWIN)
67
+ # ifdef HAVE_UNISTD_H
68
+ # include <unistd.h>
69
+ # else
70
+ int dup(int);
71
+ int close(int);
72
+ # endif
73
+ #endif
74
+
75
+ #ifdef HAVE_NCURSES_H
76
+ #define NCURSES_OPAQUE 0
77
+ # include <ncurses.h>
78
+ #else
79
+ # ifdef HAVE_NCURSES_CURSES_H
80
+ # include <ncurses/curses.h>
81
+ # else
82
+ # include <curses.h>
83
+ # endif
84
+ #endif
85
+
86
+ #include <ruby.h>
87
+
88
+ extern VALUE mNcurses; /* module Ncurses */
89
+ extern VALUE cWINDOW; /* class Ncurses::WINDOW */
90
+ extern VALUE cSCREEN; /* class Ncurses::SCREEN */
91
+ extern VALUE eNcurses; /* Ncurses::Exception thrown by this extension */
92
+
93
+ #define NCFUNC(name, nargs) \
94
+ rb_define_singleton_method(mNcurses, \
95
+ #name, \
96
+ &rbncurs_ ## name, \
97
+ nargs)
98
+
99
+ WINDOW* get_window(VALUE rb_window);
100
+ VALUE wrap_window(WINDOW* window);
@@ -0,0 +1,256 @@
1
+ /*
2
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
3
+ * (C) 2002 Tobias Peters <t-peters@berlios.de>
4
+ *
5
+ * This module is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2 of the License, or (at your option) any later version.
9
+ *
10
+ * This module is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this module; if not, write to the Free Software
17
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ */
19
+
20
+ /* $Id: panel_wrap.c,v 1.2 2004/07/31 08:35:13 t-peters Exp $ */
21
+
22
+ #ifdef HAVE_PANEL_H
23
+
24
+ #include "panel_wrap.h"
25
+ #include "ncurses_wrap.h"
26
+
27
+ VALUE mPanel;
28
+ VALUE cPANEL;
29
+
30
+ static VALUE wrap_panel(PANEL* panel)
31
+ {
32
+ if (panel == 0) return Qnil;
33
+ {
34
+ VALUE panels_hash = rb_iv_get(mPanel, "@panels_hash");
35
+ VALUE panel_adress = INT2NUM((long)(panel));
36
+ VALUE rb_panel = rb_hash_aref(panels_hash, panel_adress);
37
+ if (rb_panel == Qnil) {
38
+ rb_panel = Data_Wrap_Struct(cPANEL, 0, 0, panel);
39
+ rb_iv_set(rb_panel, "@destroyed", Qfalse);
40
+ rb_hash_aset(panels_hash, panel_adress, rb_panel);
41
+ }
42
+ return rb_panel;
43
+ }
44
+ }
45
+ static PANEL* get_panel(VALUE rb_panel)
46
+ {
47
+ PANEL* panel;
48
+ if (rb_panel == Qnil) return 0;
49
+ if (rb_iv_get(rb_panel, "@destroyed") == Qtrue) {
50
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed panel");
51
+ return 0;
52
+ }
53
+ Data_Get_Struct(rb_panel, PANEL, panel);
54
+ return panel;
55
+ }
56
+ static VALUE rbncurs_c_del_panel(VALUE rb_panel) {
57
+ VALUE panels_hash = rb_iv_get(mPanel, "@panels_hash");
58
+ PANEL* panel = get_panel(rb_panel);
59
+ VALUE panel_adress = INT2NUM((long)(panel));
60
+ rb_funcall(panels_hash, rb_intern("delete"), 1, panel_adress);
61
+ rb_iv_set(rb_panel, "@destroyed", Qtrue);
62
+ return INT2NUM(del_panel(panel));
63
+ }
64
+ static VALUE rbncurs_m_del_panel(VALUE dummy, VALUE rb_panel)
65
+ { return rbncurs_c_del_panel(rb_panel); }
66
+
67
+ static VALUE rbncurs_c_panel_window(VALUE rb_panel)
68
+ { return wrap_window(panel_window(get_panel(rb_panel))); }
69
+ static VALUE rbncurs_m_panel_window(VALUE dummy, VALUE rb_panel)
70
+ { return rbncurs_c_panel_window(rb_panel); }
71
+
72
+ static VALUE rbncurs_m_update_panels(VALUE dummy)
73
+ { update_panels(); return Qnil; }
74
+
75
+ static VALUE rbncurs_c_hide_panel(VALUE rb_panel)
76
+ { return INT2NUM(hide_panel(get_panel(rb_panel))); }
77
+ static VALUE rbncurs_m_hide_panel(VALUE dummy, VALUE rb_panel)
78
+ { return rbncurs_c_hide_panel(rb_panel); }
79
+
80
+ static VALUE rbncurs_c_show_panel(VALUE rb_panel)
81
+ { return INT2NUM(show_panel(get_panel(rb_panel))); }
82
+ static VALUE rbncurs_m_show_panel(VALUE dummy, VALUE rb_panel)
83
+ { return rbncurs_c_show_panel(rb_panel); }
84
+
85
+ static VALUE rbncurs_c_top_panel(VALUE rb_panel)
86
+ { return INT2NUM(top_panel(get_panel(rb_panel))); }
87
+ static VALUE rbncurs_m_top_panel(VALUE dummy, VALUE rb_panel)
88
+ { return rbncurs_c_top_panel(rb_panel); }
89
+
90
+ static VALUE rbncurs_c_bottom_panel(VALUE rb_panel)
91
+ { return INT2NUM(bottom_panel(get_panel(rb_panel))); }
92
+ static VALUE rbncurs_m_bottom_panel(VALUE dummy, VALUE rb_panel)
93
+ { return rbncurs_c_bottom_panel(rb_panel); }
94
+
95
+ static VALUE rbncurs_c_new_panel(VALUE rb_window)
96
+ { return wrap_panel(new_panel(get_window(rb_window))); }
97
+ static VALUE rbncurs_m_new_panel(VALUE dummy, VALUE rb_window)
98
+ { return rbncurs_c_new_panel(rb_window); }
99
+ static VALUE rbncurs_c_panel_above(VALUE rb_panel)
100
+ { return wrap_panel(panel_above(get_panel(rb_panel))); }
101
+ static VALUE rbncurs_m_panel_above(VALUE rb_panel)
102
+ { return rbncurs_c_panel_above(rb_panel); }
103
+ static VALUE rbncurs_c_panel_below(VALUE rb_panel)
104
+ { return wrap_panel(panel_below(get_panel(rb_panel))); }
105
+ static VALUE rbncurs_m_panel_below(VALUE rb_panel)
106
+ { return rbncurs_c_panel_below(rb_panel); }
107
+ static VALUE rbncurs_c_set_panel_userptr(VALUE rb_panel, VALUE userptr)
108
+ { return INT2NUM(set_panel_userptr(get_panel(rb_panel),
109
+ (void*)(userptr))); }
110
+ static VALUE rbncurs_m_set_panel_userptr(VALUE dummy, VALUE rb_panel, VALUE userptr)
111
+ { return rbncurs_c_set_panel_userptr(rb_panel, userptr); }
112
+ static VALUE rbncurs_c_panel_userptr(VALUE rb_panel)
113
+ { return (VALUE)(panel_userptr(get_panel(rb_panel))); }
114
+ static VALUE rbncurs_m_panel_userptr(VALUE dummy, VALUE rb_panel)
115
+ { return rbncurs_c_panel_userptr(rb_panel); }
116
+ static VALUE rbncurs_c_move_panel(VALUE rb_panel, VALUE starty, VALUE startx)
117
+ { return INT2NUM(move_panel(get_panel(rb_panel), NUM2INT(starty),
118
+ NUM2INT(startx))); }
119
+ static VALUE rbncurs_m_move_panel(VALUE dummy, VALUE rb_panel, VALUE starty, VALUE startx)
120
+ { return rbncurs_c_move_panel(rb_panel, starty, startx); }
121
+ static VALUE rbncurs_c_replace_panel(VALUE rb_panel, VALUE rb_window)
122
+ { return INT2NUM(replace_panel(get_panel(rb_panel), get_window(rb_window))); }
123
+ static VALUE rbncurs_m_replace_panel(VALUE dummy, VALUE rb_panel, VALUE rb_window)
124
+ { return rbncurs_c_replace_panel(rb_panel, rb_window); }
125
+ static VALUE rbncurs_c_panel_hidden(VALUE rb_panel)
126
+ { return panel_hidden(get_panel(rb_panel)) ? Qtrue : Qfalse; }
127
+ static VALUE rbncurs_m_panel_hidden(VALUE dummy, VALUE rb_panel)
128
+ { return rbncurs_c_panel_hidden(rb_panel); }
129
+
130
+
131
+ void init_panel(void)
132
+ {
133
+ mPanel = rb_define_module_under(mNcurses, "Panel");
134
+ rb_iv_set(mPanel, "@panels_hash", rb_hash_new());
135
+ cPANEL = rb_define_class_under(mPanel, "PANEL", rb_cObject);
136
+ rb_define_singleton_method(mPanel, "del_panel",
137
+ (&rbncurs_m_del_panel),
138
+ 1);
139
+ rb_define_singleton_method(mPanel, "delpanel",
140
+ (&rbncurs_m_del_panel),
141
+ 1);
142
+ rb_define_method(cPANEL, "del",
143
+ (&rbncurs_c_del_panel), 0);
144
+ rb_define_method(cPANEL, "delete",
145
+ (&rbncurs_c_del_panel), 0);
146
+ rb_define_singleton_method(mPanel, "panel_window",
147
+ (&rbncurs_m_panel_window),
148
+ 1);
149
+ rb_define_method(cPANEL, "panel_window",
150
+ (&rbncurs_c_panel_window), 0);
151
+ rb_define_method(cPANEL, "window",
152
+ (&rbncurs_c_panel_window), 0);
153
+ rb_define_singleton_method(mPanel, "update_panels",
154
+ (&rbncurs_m_update_panels),
155
+ 0);
156
+ rb_define_singleton_method(mPanel, "update",
157
+ (&rbncurs_m_update_panels),
158
+ 0);
159
+ rb_define_singleton_method(mPanel, "hide_panel",
160
+ (&rbncurs_m_hide_panel),
161
+ 1);
162
+ rb_define_method(cPANEL, "hide_panel",
163
+ (&rbncurs_c_hide_panel), 0);
164
+
165
+ rb_define_method(cPANEL, "hide",
166
+ (&rbncurs_c_hide_panel), 0);
167
+ rb_define_singleton_method(mPanel, "show_panel",
168
+ (&rbncurs_m_show_panel),
169
+ 1);
170
+ rb_define_method(cPANEL, "show_panel",
171
+ (&rbncurs_c_show_panel), 0);
172
+
173
+ rb_define_method(cPANEL, "show",
174
+ (&rbncurs_c_show_panel), 0);
175
+ rb_define_singleton_method(mPanel, "top_panel",
176
+ (&rbncurs_m_top_panel), 1);
177
+ rb_define_method(cPANEL, "top_panel",
178
+ (&rbncurs_c_top_panel), 0);
179
+
180
+ rb_define_method(cPANEL, "top",
181
+ (&rbncurs_c_top_panel), 0);
182
+ rb_define_singleton_method(mPanel, "bottom_panel",
183
+ (&rbncurs_m_bottom_panel),
184
+ 1);
185
+ rb_define_method(cPANEL, "bottom_panel",
186
+ (&rbncurs_c_bottom_panel), 0);
187
+
188
+ rb_define_method(cPANEL, "bottom",
189
+ (&rbncurs_c_bottom_panel), 0);
190
+ rb_define_singleton_method(mPanel, "new_panel",
191
+ (&rbncurs_m_new_panel),
192
+ 1);
193
+ rb_define_singleton_method(cPANEL, "new",
194
+ (&rbncurs_m_new_panel),
195
+ 1);
196
+ rb_define_method(cWINDOW, "new_panel",
197
+ (&rbncurs_c_new_panel),
198
+ 0);
199
+ rb_define_singleton_method(mPanel, "panel_above",
200
+ (&rbncurs_m_panel_above),
201
+ 1);
202
+ rb_define_method(cPANEL, "panel_above",
203
+ (&rbncurs_c_panel_above), 0);
204
+ rb_define_method(cPANEL, "above",
205
+ (&rbncurs_c_panel_above), 0);
206
+ rb_define_singleton_method(mPanel, "panel_below",
207
+ (&rbncurs_m_panel_below),
208
+ 1);
209
+ rb_define_method(cPANEL, "panel_below",
210
+ (&rbncurs_c_panel_below), 0);
211
+ rb_define_method(cPANEL, "below",
212
+ (&rbncurs_c_panel_below), 0);
213
+ rb_define_singleton_method(mPanel, "set_panel_userptr",
214
+ (&rbncurs_m_set_panel_userptr), 2);
215
+ rb_define_method(cPANEL, "set_panel_userptr",
216
+ (&rbncurs_c_set_panel_userptr),
217
+ 1);
218
+ rb_define_method(cPANEL, "set_userptr",
219
+ (&rbncurs_c_set_panel_userptr),
220
+ 1);
221
+ rb_define_method(cPANEL, "userptr=",
222
+ (&rbncurs_c_set_panel_userptr),
223
+ 1);
224
+ rb_define_singleton_method(mPanel, "panel_userptr",
225
+ (&rbncurs_m_panel_userptr),
226
+ 1);
227
+ rb_define_method(cPANEL, "panel_userptr",
228
+ (&rbncurs_c_panel_userptr),
229
+ 0);
230
+ rb_define_method(cPANEL, "userptr",
231
+ (&rbncurs_c_panel_userptr),
232
+ 0);
233
+ rb_define_singleton_method(mPanel, "move_panel",
234
+ (&rbncurs_m_move_panel),
235
+ 3);
236
+ rb_define_method(cPANEL, "move_panel",
237
+ (&rbncurs_c_move_panel), 2);
238
+ rb_define_method(cPANEL, "move",
239
+ (&rbncurs_c_move_panel), 2);
240
+ rb_define_singleton_method(mPanel, "replace_panel",
241
+ (&rbncurs_m_replace_panel),
242
+ 2);
243
+ rb_define_method(cPANEL, "replace_panel",
244
+ (&rbncurs_c_replace_panel), 1);
245
+ rb_define_method(cPANEL, "replace",
246
+ (&rbncurs_c_replace_panel), 1);
247
+ rb_define_singleton_method(mPanel, "panel_hidden?",
248
+ (&rbncurs_m_panel_hidden),
249
+ 1);
250
+ rb_define_method(cPANEL, "panel_hidden?",
251
+ (&rbncurs_c_panel_hidden), 0);
252
+ rb_define_method(cPANEL, "hidden?",
253
+ (&rbncurs_c_panel_hidden), 0);
254
+ }
255
+
256
+ #endif
@@ -0,0 +1,32 @@
1
+ /*
2
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
3
+ * (C) 2002 Tobias Peters <t-peters@berlios.de>
4
+ *
5
+ * This module is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2 of the License, or (at your option) any later version.
9
+ *
10
+ * This module is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this module; if not, write to the Free Software
17
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ */
19
+
20
+ /* $Id: panel_wrap.h,v 1.5 2004/07/31 08:35:13 t-peters Exp $ */
21
+
22
+ #if !defined(PANEL_HH) && defined(HAVE_PANEL_H)
23
+ #define PANEL_HH
24
+ #include <panel.h>
25
+ #include <ruby.h>
26
+
27
+ extern VALUE mPanel;
28
+ extern VALUE cPANEL;
29
+
30
+ void init_panel(void);
31
+
32
+ #endif
@@ -0,0 +1,5 @@
1
+ module Ncurses
2
+ module Ruby
3
+ VERSION = '1.2.1'
4
+ end
5
+ end
data/lib/ncurses.rb ADDED
@@ -0,0 +1,344 @@
1
+ # ncurses-ruby is a ruby module for accessing the FSF's ncurses library
2
+ # (C) 2002, 2003, 2004 Tobias Peters <t-peters@users.berlios.de>
3
+ # (C) 2004 Simon Kaczor <skaczor@cox.net>
4
+ # (C) 2005 Tobias Herzke
5
+ #
6
+ # This module is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2 of the License, or (at your option) any later version.
10
+ #
11
+ # This module is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this module; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+
20
+ # $Id: ncurses.rb,v 1.7 2005/02/26 22:51:29 t-peters Exp $
21
+
22
+ require "ncurses.so"
23
+
24
+
25
+ # Ncurses constants with leading underscore
26
+ def Ncurses._XOPEN_CURSES
27
+ Ncurses::XOPEN_CURSES
28
+ end
29
+ def Ncurses._SUBWIN
30
+ Ncurses::SUBWIN
31
+ end
32
+ def Ncurses._ENDLINE
33
+ Ncurses::ENDLINE
34
+ end
35
+ def Ncurses._FULLWIN
36
+ Ncurses::FULLWIN
37
+ end
38
+ def Ncurses._SCROLLWIN
39
+ Ncurses::SCROLLWIN
40
+ end
41
+ def Ncurses._ISPAD
42
+ Ncurses::ISPAD
43
+ end
44
+ def Ncurses._HASMOVED
45
+ Ncurses::HASMOVED
46
+ end
47
+ def Ncurses._WRAPPED
48
+ Ncurses::WRAPPED
49
+ end
50
+ def Ncurses._NOCHANGE
51
+ Ncurses::NOCHANGE
52
+ end
53
+ def Ncurses._NEWINDEX
54
+ Ncurses::NEWINDEX
55
+ end
56
+
57
+
58
+ module Ncurses
59
+ module Destroy_checker; def destroyed?; @destroyed; end; end
60
+ class WINDOW
61
+ include Destroy_checker
62
+ def method_missing(name, *args)
63
+ name = name.to_s
64
+ if (name[0,2] == "mv")
65
+ test_name = name.dup
66
+ test_name[2,0] = "w" # insert "w" after"mv"
67
+ if (Ncurses.respond_to?(test_name))
68
+ return Ncurses.send(test_name, self, *args)
69
+ end
70
+ end
71
+ test_name = "w" + name
72
+ if (Ncurses.respond_to?(test_name))
73
+ return Ncurses.send(test_name, self, *args)
74
+ end
75
+ Ncurses.send(name, self, *args)
76
+ end
77
+ def respond_to?(name)
78
+ name = name.to_s
79
+ if (name[0,2] == "mv" && Ncurses.respond_to?("mvw" + name[2..-1]))
80
+ return true
81
+ end
82
+ Ncurses.respond_to?("w" + name) || Ncurses.respond_to?(name)
83
+ end
84
+ def del
85
+ Ncurses.delwin(self)
86
+ end
87
+ alias delete del
88
+ def WINDOW.new(*args)
89
+ Ncurses.newwin(*args)
90
+ end
91
+ end
92
+ class SCREEN
93
+ include Destroy_checker
94
+ def del
95
+ Ncurses.delscreen(self)
96
+ end
97
+ alias delete del
98
+ end
99
+ class MEVENT
100
+ attr_accessor :id, :x,:y,:z, :bstate
101
+ end
102
+ GETSTR_LIMIT = 1024
103
+
104
+ module Panel
105
+ class PANEL; end
106
+ end
107
+
108
+ module Form
109
+ class FORM
110
+ attr_reader :user_object
111
+
112
+ # This placeholder replaces the form_userptr function in curses
113
+ def user_object=(obj)
114
+ @user_object = obj
115
+ end
116
+ end
117
+
118
+ class FIELD
119
+ attr_reader :user_object
120
+
121
+ # This placeholder replaces the field_userptr function in curses
122
+ def user_object=(obj)
123
+ @user_object = obj
124
+ end
125
+ end
126
+
127
+ class FIELDTYPE
128
+ end
129
+ end
130
+
131
+ module Menu
132
+ class MENU
133
+ attr_reader :user_object
134
+
135
+ # This placeholder replaces the menu_userptr function in curses
136
+ def user_object=(obj)
137
+ @user_object = obj
138
+ end
139
+ end
140
+
141
+ class ITEM
142
+ attr_reader :user_object
143
+
144
+ # This placeholder replaces the item_userptr function in curses
145
+ def user_object=(obj)
146
+ @user_object = obj
147
+ end
148
+ end
149
+ end
150
+ end
151
+ def Ncurses.inchnstr(str,n)
152
+ Ncurses.winchnstr(Ncurses.stdscr, str, n)
153
+ end
154
+ def Ncurses.inchstr(str)
155
+ Ncurses.winchstr(Ncurses.stdscr, str)
156
+ end
157
+ def Ncurses.mvinchnstr(y,x, str, n)
158
+ Ncurses.mvwinchnstr(Ncurses.stdscr, y,x, str, n)
159
+ end
160
+ def Ncurses.mvinchstr(y,x, str)
161
+ Ncurses.mvwinchstr(Ncurses.stdscr, y,x, str)
162
+ end
163
+ def Ncurses.mvwinchnstr(win, y,x, str, n)
164
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
165
+ Ncurses::ERR
166
+ else
167
+ Ncurses.winchnstr(win,str,n)
168
+ end
169
+ end
170
+ def Ncurses.mvwinchstr(win, y,x, str)
171
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
172
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
173
+ Ncurses.mvwinchnstr(win, y,x, str, maxx[0]+1)
174
+ end
175
+ def Ncurses.winchstr(win, str)
176
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
177
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
178
+ Ncurses.winchnstr(win, str, maxx[0]+1)
179
+ end
180
+
181
+ def Ncurses.getnstr(str,n)
182
+ Ncurses.wgetnstr(Ncurses.stdscr, str, n)
183
+ end
184
+ def Ncurses.mvgetnstr(y,x, str, n)
185
+ Ncurses.mvwgetnstr(Ncurses.stdscr, y,x, str, n)
186
+ end
187
+ def Ncurses.mvwgetnstr(win, y,x, str, n)
188
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
189
+ Ncurses::ERR
190
+ else
191
+ Ncurses.wgetnstr(win,str,n)
192
+ end
193
+ end
194
+
195
+ def Ncurses.innstr(str,n)
196
+ Ncurses.winnstr(Ncurses.stdscr, str, n)
197
+ end
198
+ def Ncurses.instr(str)
199
+ Ncurses.winstr(Ncurses.stdscr, str)
200
+ end
201
+ def Ncurses.mvinnstr(y,x, str, n)
202
+ Ncurses.mvwinnstr(Ncurses.stdscr, y,x, str, n)
203
+ end
204
+ def Ncurses.mvinstr(y,x, str)
205
+ Ncurses.mvwinstr(Ncurses.stdscr, y,x, str)
206
+ end
207
+ def Ncurses.mvwinnstr(win, y,x, str, n)
208
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
209
+ Ncurses::ERR
210
+ else
211
+ Ncurses.winnstr(win,str,n)
212
+ end
213
+ end
214
+ def Ncurses.mvwinstr(win, y,x, str)
215
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
216
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
217
+ Ncurses.mvwinnstr(win, y,x, str, maxx[0]+1)
218
+ end
219
+ def Ncurses.winstr(win, str)
220
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
221
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
222
+ Ncurses.winnstr(win, str, maxx[0]+1)
223
+ end
224
+
225
+ def Ncurses.mouse_trafo(pY, pX, to_screen)
226
+ Ncurses.wmouse_trafo(Ncurses.stdscr, pY, pX, to_screen)
227
+ end
228
+
229
+ def Ncurses.getcurx(win)
230
+ x = []; y = []; Ncurses.getyx(win, y,x); x[0]
231
+ end
232
+ def Ncurses.getcury(win)
233
+ x = []; y = []; Ncurses.getyx(win, y,x); y[0]
234
+ end
235
+ def Ncurses.getbegx(win)
236
+ x = []; y = []; Ncurses.getbegyx(win, y,x); x[0]
237
+ end
238
+ def Ncurses.getbegy(win)
239
+ x = []; y = []; Ncurses.getbegyx(win, y,x); y[0]
240
+ end
241
+ def Ncurses.getmaxx(win)
242
+ x = []; y = []; Ncurses.getmaxyx(win, y,x); x[0]
243
+ end
244
+ def Ncurses.getmaxy(win)
245
+ x = []; y = []; Ncurses.getmaxyx(win, y,x); y[0]
246
+ end
247
+ def Ncurses.getparx(win)
248
+ x = []; y = []; Ncurses.getparyx(win, y,x); x[0]
249
+ end
250
+ def Ncurses.getpary(win)
251
+ x = []; y = []; Ncurses.getparyx(win, y,x); y[0]
252
+ end
253
+ def Ncurses.erase
254
+ Ncurses.werase(Ncurses.stdscr)
255
+ end
256
+ def Ncurses.getstr(str)
257
+ Ncurses.getnstr(str, Ncurses::GETSTR_LIMIT)
258
+ end
259
+ def Ncurses.mvgetstr(y,x, str)
260
+ Ncurses.mvgetnstr(y,x, str, Ncurses::GETSTR_LIMIT)
261
+ end
262
+ def Ncurses.mvwgetstr(win, y,x, str)
263
+ Ncurses.mvwgetnstr(win, y,x, str, Ncurses::GETSTR_LIMIT)
264
+ end
265
+ def Ncurses.wgetstr(win, str)
266
+ Ncurses.wgetnstr(win, str, Ncurses::GETSTR_LIMIT)
267
+ end
268
+
269
+ def Ncurses.scanw(format, result)
270
+ Ncurses.wscanw(Ncurses.stdscr, format, result)
271
+ end
272
+ def Ncurses.mvscanw(y,x, format, result)
273
+ Ncurses.mvwscanw(Ncurses.stdscr, y,x, format, result)
274
+ end
275
+ def Ncurses.mvwscanw(win, y,x, format, result)
276
+ if (Ncurses.wmove(win, y,x) == Ncurses::ERR)
277
+ Ncurses::ERR
278
+ else
279
+ Ncurses.wscanw(win, format, result)
280
+ end
281
+ end
282
+ def Ncurses.wscanw(win, format, result)
283
+ str = ""
284
+ if (Ncurses.wgetstr(win, str) == Ncurses::ERR)
285
+ Ncurses::ERR
286
+ else
287
+ require "scanf.rb" # Use ruby's implementation of scanf
288
+ result.replace(str.scanf(format))
289
+ end
290
+ end
291
+
292
+ def Ncurses.mvprintw(*args)
293
+ Ncurses.mvwprintw(Ncurses.stdscr, *args)
294
+ end
295
+ def Ncurses.mvwprintw(win, y,x, *args)
296
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
297
+ Ncurses::ERR
298
+ else
299
+ wprintw(win, *args)
300
+ end
301
+ end
302
+ def Ncurses.printw(*args)
303
+ Ncurses.wprintw(Ncurses.stdscr, *args)
304
+ end
305
+ def Ncurses.touchline(win, start, count)
306
+ Ncurses.wtouchln(win, start, count, 1)
307
+ end
308
+ def Ncurses.touchwin(win)
309
+ wtouchln(win, 0, getmaxy(win), 1)
310
+ end
311
+
312
+ module Ncurses
313
+ Ncurses = self # for accessing Ncurses from a Module that includes Ncurses
314
+
315
+ # Some users like to include ncurses names despite namespace pollution
316
+ # This module is for them
317
+ module Namespace
318
+ def self.append_features(target)
319
+ # include constants
320
+ unless target.ancestors.member?(Ncurses)
321
+ target.__send__(:include, Ncurses)
322
+ end
323
+
324
+ # make methods available
325
+ unless target.respond_to?(:pre_Ncurses_method_missing)
326
+ target.module_eval{
327
+ alias pre_Ncurses_method_missing method_missing
328
+ def method_missing(name, *args)
329
+ if Ncurses.respond_to?(name)
330
+ Ncurses.send(name, *args)
331
+ else
332
+ pre_Ncurses_method_missing(name, *args)
333
+ end
334
+ end
335
+ }
336
+ end
337
+ end
338
+ def self.entend_object(object)
339
+ class << object
340
+ self
341
+ end.__send__(:include, self)
342
+ end
343
+ end
344
+ end