snowleopard-ncurses 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ /*
2
+ * This is a curses forms wrapper as part of ncurses-ruby
3
+ * Contributed by Simon Kaczor <skaczor@cox.net>
4
+ * Prognosoft Inc. <http://www.prognosoft.biz>
5
+ * Copyright 2004
6
+ *
7
+ * This module is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2 of the License, or (at your option) any later version.
11
+ *
12
+ * This module is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this module; if not, write to the Free Software
19
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ *
21
+ */
22
+
23
+ #if !defined(FORM_HH) && defined(HAVE_FORM_H)
24
+ #define FORM_HH
25
+
26
+ #include <form.h>
27
+ #include <ruby.h>
28
+
29
+ extern VALUE mForm;
30
+ extern VALUE cFIELD;
31
+ extern VALUE cFIELDTYPE;
32
+ extern VALUE cFORM;
33
+ /*extern VALUE cPAGE;*/
34
+
35
+ typedef struct {
36
+ bool (* field_check)(FIELD *,const void *);
37
+ FIELDTYPE* fieldtype;
38
+ } FLDCHKFUNC;
39
+
40
+
41
+
42
+ #define FORM_DEF_CONST(name) \
43
+ rb_define_const(mForm, #name, INT2NUM(name));
44
+
45
+ #define FORM_SNG_FUNC(name, nargs) \
46
+ rb_define_singleton_method(mForm, \
47
+ #name, \
48
+ &rbncurs_m_ ## name, \
49
+ nargs)
50
+ #define RB_CLASS_METH(class, alt_name, name, nargs) \
51
+ rb_define_method(class, #name, (&rbncurs_c_ ## name), nargs); \
52
+ if (alt_name != NULL) \
53
+ rb_define_method(class, alt_name, (&rbncurs_c_ ## name), nargs); \
54
+
55
+ void init_req_constants();
56
+ void init_just_constants();
57
+ void init_opts_constants();
58
+
59
+ void init_form(void);
60
+
61
+ #endif
@@ -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.8 2009/05/03 10:37:54 t-peters Exp $
21
+
22
+ require "ncurses_bin.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
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # $Id: make_dist.rb,v 1.6 2003/08/29 22:50:12 t-peters Exp $
4
+
5
+ require "fileutils"
6
+
7
+ def sys(i)
8
+ puts("\"#{i}\"")
9
+ system(i)
10
+ end
11
+
12
+ dir = File.dirname(__FILE__)
13
+ base = File.basename(dir)
14
+ base = "ncurses-ruby" if base == "."
15
+
16
+ files = IO.readlines(dir + "/MANIFEST").collect{|filename|filename.chomp}
17
+
18
+ Version = File.new("#{dir}/VERSION").readline.chomp!
19
+
20
+ FileUtils.mkdir "#{base}-#{Version}"
21
+ files.each{|filename|
22
+ if filename.index "/"
23
+ FileUtils.mkdir_p "#{base}-#{Version}/#{File.dirname(filename)}"
24
+ end
25
+ sys "cp #{dir}/#{filename} #{base}-#{Version}/#{filename}"
26
+ }
27
+ sys "tar cjf #{base}-#{Version}.tar.bz2 --owner=0 --group=0 #{base}-#{Version}"
28
+
29
+ # check if we create a binary distribution for a mingw extension
30
+ binary_description = `file ncurses.so`
31
+
32
+ if ((binary_description =~ /\s(windows)\s/i) &&
33
+ (binary_description =~ /\s(pe)|(portable executable)\s/i) &&
34
+ (binary_description =~ /\s(dll)\s/i))
35
+ sys "cp ncurses.so README.binary #{base}-#{Version}"
36
+ Dir.glob("#{base}-#{Version}/README*").each{|textfile|
37
+ text = IO.readlines(textfile).map{|line|line.chomp + "\r\n"}
38
+ File.open(textfile + ".txt", "wb"){|outfd| outfd.write(text.join)}
39
+ sys "rm #{textfile}"
40
+ }
41
+ sys "rm #{base}-#{Version}/{MANIFEST,make_dist.rb}"
42
+ sys "zip -9 -r #{base}-#{Version}-i386-mswin32.zip #{base}-#{Version}"
43
+ end
44
+
45
+ sys "rm -r #{base}-#{Version}/"