elliottcable-ncurses 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
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_NCURSESW_NCURSESW_H
76
+ # include <ncursesw/ncursesw.h>
77
+ #elif HAVE_NCURSESW_CURSESW_H
78
+ # include <ncursesw/cursesw.h>
79
+ #elif HAVE_NCURSESW_NCURSES_H
80
+ # include <ncursesw/ncurses.h>
81
+ #elif HAVE_NCURSESW_CURSES_H
82
+ # include <ncursesw/curses.h>
83
+ #elif HAVE_NCURSESW_H
84
+ # include <ncursesw.h>
85
+ #elif HAVE_CURSESW_H
86
+ # include <cursesw.h>
87
+ #elif HAVE_NCURSES_NCURSES_H
88
+ # include <ncurses/ncurses.h>
89
+ #elif HAVE_NCURSES_CURSES_H
90
+ # include <ncurses/curses.h>
91
+ #elif HAVE_NCURSES_H
92
+ # include <ncurses.h>
93
+ #else
94
+ # include <curses.h>
95
+ #endif
96
+
97
+ #include <ruby.h>
98
+
99
+ extern VALUE mNcurses; /* module Ncurses */
100
+ extern VALUE cWINDOW; /* class Ncurses::WINDOW */
101
+ extern VALUE cSCREEN; /* class Ncurses::SCREEN */
102
+ extern VALUE eNcurses; /* Ncurses::Exception thrown by this extension */
103
+
104
+ #define NCFUNC(name, nargs) \
105
+ rb_define_singleton_method(mNcurses, \
106
+ #name, \
107
+ &rbncurs_ ## name, \
108
+ nargs)
109
+
110
+ WINDOW* get_window(VALUE rb_window);
111
+ 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,350 @@
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/etc'
23
+
24
+ begin
25
+ require 'ncurses.bundle'
26
+ rescue LoadError => e
27
+ raise e unless e.message =~ /^no such file to load -- ncurses\.bundle$/
28
+ require 'ncurses.so'
29
+ end
30
+
31
+ # Ncurses constants with leading underscore
32
+ def Ncurses._XOPEN_CURSES
33
+ Ncurses::XOPEN_CURSES
34
+ end
35
+ def Ncurses._SUBWIN
36
+ Ncurses::SUBWIN
37
+ end
38
+ def Ncurses._ENDLINE
39
+ Ncurses::ENDLINE
40
+ end
41
+ def Ncurses._FULLWIN
42
+ Ncurses::FULLWIN
43
+ end
44
+ def Ncurses._SCROLLWIN
45
+ Ncurses::SCROLLWIN
46
+ end
47
+ def Ncurses._ISPAD
48
+ Ncurses::ISPAD
49
+ end
50
+ def Ncurses._HASMOVED
51
+ Ncurses::HASMOVED
52
+ end
53
+ def Ncurses._WRAPPED
54
+ Ncurses::WRAPPED
55
+ end
56
+ def Ncurses._NOCHANGE
57
+ Ncurses::NOCHANGE
58
+ end
59
+ def Ncurses._NEWINDEX
60
+ Ncurses::NEWINDEX
61
+ end
62
+
63
+
64
+ module Ncurses
65
+ module Destroy_checker; def destroyed?; @destroyed; end; end
66
+ class WINDOW
67
+ include Destroy_checker
68
+ def method_missing(name, *args)
69
+ name = name.to_s
70
+ if (name[0,2] == "mv")
71
+ test_name = name.dup
72
+ test_name[2,0] = "w" # insert "w" after"mv"
73
+ if (Ncurses.respond_to?(test_name))
74
+ return Ncurses.send(test_name, self, *args)
75
+ end
76
+ end
77
+ test_name = "w" + name
78
+ if (Ncurses.respond_to?(test_name))
79
+ return Ncurses.send(test_name, self, *args)
80
+ end
81
+ Ncurses.send(name, self, *args)
82
+ end
83
+ def respond_to?(name)
84
+ name = name.to_s
85
+ if (name[0,2] == "mv" && Ncurses.respond_to?("mvw" + name[2..-1]))
86
+ return true
87
+ end
88
+ Ncurses.respond_to?("w" + name) || Ncurses.respond_to?(name)
89
+ end
90
+ def del
91
+ Ncurses.delwin(self)
92
+ end
93
+ alias delete del
94
+ def WINDOW.new(*args)
95
+ Ncurses.newwin(*args)
96
+ end
97
+ end
98
+ class SCREEN
99
+ include Destroy_checker
100
+ def del
101
+ Ncurses.delscreen(self)
102
+ end
103
+ alias delete del
104
+ end
105
+ class MEVENT
106
+ attr_accessor :id, :x,:y,:z, :bstate
107
+ end
108
+ GETSTR_LIMIT = 1024
109
+
110
+ module Panel
111
+ class PANEL; end
112
+ end
113
+
114
+ module Form
115
+ class FORM
116
+ attr_reader :user_object
117
+
118
+ # This placeholder replaces the form_userptr function in curses
119
+ def user_object=(obj)
120
+ @user_object = obj
121
+ end
122
+ end
123
+
124
+ class FIELD
125
+ attr_reader :user_object
126
+
127
+ # This placeholder replaces the field_userptr function in curses
128
+ def user_object=(obj)
129
+ @user_object = obj
130
+ end
131
+ end
132
+
133
+ class FIELDTYPE
134
+ end
135
+ end
136
+
137
+ module Menu
138
+ class MENU
139
+ attr_reader :user_object
140
+
141
+ # This placeholder replaces the menu_userptr function in curses
142
+ def user_object=(obj)
143
+ @user_object = obj
144
+ end
145
+ end
146
+
147
+ class ITEM
148
+ attr_reader :user_object
149
+
150
+ # This placeholder replaces the item_userptr function in curses
151
+ def user_object=(obj)
152
+ @user_object = obj
153
+ end
154
+ end
155
+ end
156
+ end
157
+ def Ncurses.inchnstr(str,n)
158
+ Ncurses.winchnstr(Ncurses.stdscr, str, n)
159
+ end
160
+ def Ncurses.inchstr(str)
161
+ Ncurses.winchstr(Ncurses.stdscr, str)
162
+ end
163
+ def Ncurses.mvinchnstr(y,x, str, n)
164
+ Ncurses.mvwinchnstr(Ncurses.stdscr, y,x, str, n)
165
+ end
166
+ def Ncurses.mvinchstr(y,x, str)
167
+ Ncurses.mvwinchstr(Ncurses.stdscr, y,x, str)
168
+ end
169
+ def Ncurses.mvwinchnstr(win, y,x, str, n)
170
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
171
+ Ncurses::ERR
172
+ else
173
+ Ncurses.winchnstr(win,str,n)
174
+ end
175
+ end
176
+ def Ncurses.mvwinchstr(win, y,x, str)
177
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
178
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
179
+ Ncurses.mvwinchnstr(win, y,x, str, maxx[0]+1)
180
+ end
181
+ def Ncurses.winchstr(win, str)
182
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
183
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
184
+ Ncurses.winchnstr(win, str, maxx[0]+1)
185
+ end
186
+
187
+ def Ncurses.getnstr(str,n)
188
+ Ncurses.wgetnstr(Ncurses.stdscr, str, n)
189
+ end
190
+ def Ncurses.mvgetnstr(y,x, str, n)
191
+ Ncurses.mvwgetnstr(Ncurses.stdscr, y,x, str, n)
192
+ end
193
+ def Ncurses.mvwgetnstr(win, y,x, str, n)
194
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
195
+ Ncurses::ERR
196
+ else
197
+ Ncurses.wgetnstr(win,str,n)
198
+ end
199
+ end
200
+
201
+ def Ncurses.innstr(str,n)
202
+ Ncurses.winnstr(Ncurses.stdscr, str, n)
203
+ end
204
+ def Ncurses.instr(str)
205
+ Ncurses.winstr(Ncurses.stdscr, str)
206
+ end
207
+ def Ncurses.mvinnstr(y,x, str, n)
208
+ Ncurses.mvwinnstr(Ncurses.stdscr, y,x, str, n)
209
+ end
210
+ def Ncurses.mvinstr(y,x, str)
211
+ Ncurses.mvwinstr(Ncurses.stdscr, y,x, str)
212
+ end
213
+ def Ncurses.mvwinnstr(win, y,x, str, n)
214
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
215
+ Ncurses::ERR
216
+ else
217
+ Ncurses.winnstr(win,str,n)
218
+ end
219
+ end
220
+ def Ncurses.mvwinstr(win, y,x, str)
221
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
222
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
223
+ Ncurses.mvwinnstr(win, y,x, str, maxx[0]+1)
224
+ end
225
+ def Ncurses.winstr(win, str)
226
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
227
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
228
+ Ncurses.winnstr(win, str, maxx[0]+1)
229
+ end
230
+
231
+ def Ncurses.mouse_trafo(pY, pX, to_screen)
232
+ Ncurses.wmouse_trafo(Ncurses.stdscr, pY, pX, to_screen)
233
+ end
234
+
235
+ def Ncurses.getcurx(win)
236
+ x = []; y = []; Ncurses.getyx(win, y,x); x[0]
237
+ end
238
+ def Ncurses.getcury(win)
239
+ x = []; y = []; Ncurses.getyx(win, y,x); y[0]
240
+ end
241
+ def Ncurses.getbegx(win)
242
+ x = []; y = []; Ncurses.getbegyx(win, y,x); x[0]
243
+ end
244
+ def Ncurses.getbegy(win)
245
+ x = []; y = []; Ncurses.getbegyx(win, y,x); y[0]
246
+ end
247
+ def Ncurses.getmaxx(win)
248
+ x = []; y = []; Ncurses.getmaxyx(win, y,x); x[0]
249
+ end
250
+ def Ncurses.getmaxy(win)
251
+ x = []; y = []; Ncurses.getmaxyx(win, y,x); y[0]
252
+ end
253
+ def Ncurses.getparx(win)
254
+ x = []; y = []; Ncurses.getparyx(win, y,x); x[0]
255
+ end
256
+ def Ncurses.getpary(win)
257
+ x = []; y = []; Ncurses.getparyx(win, y,x); y[0]
258
+ end
259
+ def Ncurses.erase
260
+ Ncurses.werase(Ncurses.stdscr)
261
+ end
262
+ def Ncurses.getstr(str)
263
+ Ncurses.getnstr(str, Ncurses::GETSTR_LIMIT)
264
+ end
265
+ def Ncurses.mvgetstr(y,x, str)
266
+ Ncurses.mvgetnstr(y,x, str, Ncurses::GETSTR_LIMIT)
267
+ end
268
+ def Ncurses.mvwgetstr(win, y,x, str)
269
+ Ncurses.mvwgetnstr(win, y,x, str, Ncurses::GETSTR_LIMIT)
270
+ end
271
+ def Ncurses.wgetstr(win, str)
272
+ Ncurses.wgetnstr(win, str, Ncurses::GETSTR_LIMIT)
273
+ end
274
+
275
+ def Ncurses.scanw(format, result)
276
+ Ncurses.wscanw(Ncurses.stdscr, format, result)
277
+ end
278
+ def Ncurses.mvscanw(y,x, format, result)
279
+ Ncurses.mvwscanw(Ncurses.stdscr, y,x, format, result)
280
+ end
281
+ def Ncurses.mvwscanw(win, y,x, format, result)
282
+ if (Ncurses.wmove(win, y,x) == Ncurses::ERR)
283
+ Ncurses::ERR
284
+ else
285
+ Ncurses.wscanw(win, format, result)
286
+ end
287
+ end
288
+ def Ncurses.wscanw(win, format, result)
289
+ str = ""
290
+ if (Ncurses.wgetstr(win, str) == Ncurses::ERR)
291
+ Ncurses::ERR
292
+ else
293
+ require "scanf.rb" # Use ruby's implementation of scanf
294
+ result.replace(str.scanf(format))
295
+ end
296
+ end
297
+
298
+ def Ncurses.mvprintw(*args)
299
+ Ncurses.mvwprintw(Ncurses.stdscr, *args)
300
+ end
301
+ def Ncurses.mvwprintw(win, y,x, *args)
302
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
303
+ Ncurses::ERR
304
+ else
305
+ wprintw(win, *args)
306
+ end
307
+ end
308
+ def Ncurses.printw(*args)
309
+ Ncurses.wprintw(Ncurses.stdscr, *args)
310
+ end
311
+ def Ncurses.touchline(win, start, count)
312
+ Ncurses.wtouchln(win, start, count, 1)
313
+ end
314
+ def Ncurses.touchwin(win)
315
+ wtouchln(win, 0, getmaxy(win), 1)
316
+ end
317
+
318
+ module Ncurses
319
+ Ncurses = self # for accessing Ncurses from a Module that includes Ncurses
320
+
321
+ # Some users like to include ncurses names despite namespace pollution
322
+ # This module is for them
323
+ module Namespace
324
+ def self.append_features(target)
325
+ # include constants
326
+ unless target.ancestors.member?(Ncurses)
327
+ target.__send__(:include, Ncurses)
328
+ end
329
+
330
+ # make methods available
331
+ unless target.respond_to?(:pre_Ncurses_method_missing)
332
+ target.module_eval{
333
+ alias pre_Ncurses_method_missing method_missing
334
+ def method_missing(name, *args)
335
+ if Ncurses.respond_to?(name)
336
+ Ncurses.send(name, *args)
337
+ else
338
+ pre_Ncurses_method_missing(name, *args)
339
+ end
340
+ end
341
+ }
342
+ end
343
+ end
344
+ def self.entend_object(object)
345
+ class << object
346
+ self
347
+ end.__send__(:include, self)
348
+ end
349
+ end
350
+ end