ffi-ncurses 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.rdoc +18 -5
- data/Rakefile +14 -2
- data/examples/doc-eg3.rb +23 -0
- data/lib/ffi-ncurses/darwin.rb +0 -172
- metadata +4 -13
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -5,10 +5,10 @@ Author: Sean O'Halpin
|
|
5
5
|
A wrapper for ncurses 5.x. Tested on Mac OS X 10.4 (Tiger) and Ubuntu
|
6
6
|
8.04 with ruby 1.8.6 using ruby-ffi (>= 0.2.0) and JRuby 1.1.6.
|
7
7
|
|
8
|
-
The API is
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
The API is a transliteration of the C API rather than an attempt to
|
9
|
+
provide an idiomatic Ruby object-oriented API. The intent is to
|
10
|
+
provide a 'close to the metal' wrapper around the ncurses library upon
|
11
|
+
which you can build your own abstractions.
|
12
12
|
|
13
13
|
This is still very much a work-in-progress, so expect some rough
|
14
14
|
edges. Having said that, you can do quite a lot with it as it is. The
|
@@ -18,6 +18,16 @@ various macros.
|
|
18
18
|
Below are some very preliminary notes on usage. See the examples
|
19
19
|
directory for real working examples.
|
20
20
|
|
21
|
+
== Install
|
22
|
+
|
23
|
+
ruby 1.8.6:
|
24
|
+
|
25
|
+
$ sudo gem install ffi ffi-ncurses
|
26
|
+
|
27
|
+
jruby 1.1.6:
|
28
|
+
|
29
|
+
$ jruby -S gem install ffi-ncurses
|
30
|
+
|
21
31
|
== Usage
|
22
32
|
|
23
33
|
Load the library with:
|
@@ -100,14 +110,17 @@ or as included methods:
|
|
100
110
|
== Windows
|
101
111
|
|
102
112
|
require 'ffi-ncurses'
|
113
|
+
include FFI::NCurses
|
103
114
|
begin
|
115
|
+
initscr
|
104
116
|
win = newwin(6, 12, 15, 15)
|
105
117
|
box(win, 0, 0)
|
106
118
|
inner_win = newwin(4, 10, 16, 16)
|
107
|
-
waddstr(inner_win, (["Hello
|
119
|
+
waddstr(inner_win, (["Hello!"] * 5).join(' '))
|
108
120
|
wrefresh(win)
|
109
121
|
wrefresh(inner_win)
|
110
122
|
ch = wgetch(inner_win)
|
123
|
+
delwin(win)
|
111
124
|
|
112
125
|
rescue Object => e
|
113
126
|
FFI::NCurses.endwin
|
data/Rakefile
CHANGED
@@ -25,11 +25,23 @@ PROJ.authors = ["Sean O'Halpin"]
|
|
25
25
|
PROJ.email = 'sean.ohalpin@gmail.com'
|
26
26
|
PROJ.url = 'http://github.com/seanohalpin/ffi-ncurses'
|
27
27
|
PROJ.summary = "FFI wrapper for ncurses"
|
28
|
-
PROJ.version = "0.3.
|
28
|
+
PROJ.version = "0.3.1"
|
29
29
|
PROJ.rubyforge.name = 'ffi-ncurses'
|
30
30
|
|
31
|
+
PROJ.description = <<EOT
|
32
|
+
A wrapper for ncurses 5.x. Tested on Mac OS X 10.4 (Tiger) and Ubuntu
|
33
|
+
8.04 with ruby 1.8.6 using ruby-ffi (>= 0.2.0) and JRuby 1.1.6.
|
34
|
+
|
35
|
+
The API is very much a transliteration of the C API rather than an
|
36
|
+
attempt to provide an idiomatic Ruby object-oriented API. The intent
|
37
|
+
is to provide a 'close to the metal' wrapper around the ncurses
|
38
|
+
library upon which you can build your own abstractions.
|
39
|
+
|
40
|
+
See the examples directory for real working examples.
|
41
|
+
EOT
|
42
|
+
|
31
43
|
# gem
|
32
|
-
PROJ.gem.dependencies << ["ffi", ">= 0.2.0"]
|
44
|
+
# PROJ.gem.dependencies << ["ffi", ">= 0.2.0"]
|
33
45
|
|
34
46
|
# rdoc
|
35
47
|
PROJ.rdoc.exclude << "^notes"
|
data/examples/doc-eg3.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Sean O'Halpin, 2009-02-15
|
4
|
+
#
|
5
|
+
require 'ffi-ncurses'
|
6
|
+
include FFI::NCurses
|
7
|
+
begin
|
8
|
+
initscr
|
9
|
+
win = newwin(6, 12, 15, 15)
|
10
|
+
box(win, 0, 0)
|
11
|
+
inner_win = newwin(4, 10, 16, 16)
|
12
|
+
waddstr(inner_win, (["Hello!"] * 5).join(' '))
|
13
|
+
wrefresh(win)
|
14
|
+
wrefresh(inner_win)
|
15
|
+
ch = wgetch(inner_win)
|
16
|
+
delwin(win)
|
17
|
+
|
18
|
+
rescue Object => e
|
19
|
+
FFI::NCurses.endwin
|
20
|
+
puts e
|
21
|
+
ensure
|
22
|
+
FFI::NCurses.endwin
|
23
|
+
end
|
data/lib/ffi-ncurses/darwin.rb
CHANGED
@@ -1,74 +1,6 @@
|
|
1
1
|
module FFI
|
2
2
|
module NCurses
|
3
3
|
module Darwin
|
4
|
-
NCURSES_SIZE_T = :short
|
5
|
-
NCURSES_ATTR_T = :int
|
6
|
-
NCURSES_COLOR_T = :short
|
7
|
-
NCURSES_CH_T = :short
|
8
|
-
|
9
|
-
CHTYPE = :ulong
|
10
|
-
CCHARW_MAX = 5
|
11
|
-
|
12
|
-
BOOLEAN = :uchar # sizeof(bool) == 1
|
13
|
-
|
14
|
-
WCHAR_T = :ushort
|
15
|
-
|
16
|
-
# class CCharT < FFI::Struct
|
17
|
-
# layout \
|
18
|
-
# :attr, NCURSES_ATTR_T,
|
19
|
-
# :chars, [WCHAR_T, CCHARW_MAX]
|
20
|
-
# end
|
21
|
-
|
22
|
-
class PDat < FFI::Struct
|
23
|
-
layout \
|
24
|
-
:_pad_y, NCURSES_SIZE_T,
|
25
|
-
:_pad_x, NCURSES_SIZE_T,
|
26
|
-
:_pad_top, NCURSES_SIZE_T,
|
27
|
-
:_pad_left, NCURSES_SIZE_T,
|
28
|
-
:_pad_bottom, NCURSES_SIZE_T,
|
29
|
-
:_pad_right, NCURSES_SIZE_T
|
30
|
-
end
|
31
|
-
|
32
|
-
class WinSt < FFI::Struct
|
33
|
-
layout \
|
34
|
-
:_cury, NCURSES_SIZE_T,
|
35
|
-
:_curx, NCURSES_SIZE_T,
|
36
|
-
:_maxy, NCURSES_SIZE_T,
|
37
|
-
:_maxx, NCURSES_SIZE_T,
|
38
|
-
:_begy, NCURSES_SIZE_T,
|
39
|
-
:_begx, NCURSES_SIZE_T,
|
40
|
-
:_flags, :short,
|
41
|
-
:_attrs, NCURSES_ATTR_T,
|
42
|
-
:_bkgd, CHTYPE,
|
43
|
-
:_notimeout, BOOLEAN,
|
44
|
-
:_clear, BOOLEAN,
|
45
|
-
:_leaveok, BOOLEAN,
|
46
|
-
:_scroll, BOOLEAN,
|
47
|
-
:_idlok, BOOLEAN,
|
48
|
-
:_idcok, BOOLEAN,
|
49
|
-
:_immed, BOOLEAN,
|
50
|
-
:_sync, BOOLEAN,
|
51
|
-
:_use_keypad, BOOLEAN,
|
52
|
-
:_delay, :int,
|
53
|
-
|
54
|
-
# struct ldat *_line
|
55
|
-
:_line, :pointer,
|
56
|
-
|
57
|
-
:_regtop, NCURSES_SIZE_T,
|
58
|
-
:_regbottom, NCURSES_SIZE_T,
|
59
|
-
|
60
|
-
# why x,y when everything else is y,x?
|
61
|
-
:_parx, :int,
|
62
|
-
:_pary, :int,
|
63
|
-
:_parent, :pointer # WINDOW
|
64
|
-
|
65
|
-
# don't know how to include nested Struct yet
|
66
|
-
# :_pad, PDat,
|
67
|
-
|
68
|
-
# :_yoffset, NCURSES_SIZE_T
|
69
|
-
# :_bkgrnd, CCharT
|
70
|
-
end
|
71
|
-
|
72
4
|
# translated from Mac OSX 10.4 ('Tiger') /usr/include/ncurses.h
|
73
5
|
def getattrs(win)
|
74
6
|
win_st = WinSt.new(win)
|
@@ -106,110 +38,6 @@ module FFI
|
|
106
38
|
win_st = WinSt.new(win)
|
107
39
|
win ? win_st[:_pary] : ERR
|
108
40
|
end
|
109
|
-
|
110
|
-
def _win(win, member)
|
111
|
-
win && WinSt.new(win)[member]
|
112
|
-
end
|
113
|
-
private :_win
|
114
|
-
|
115
|
-
# extensions - not in X/Open
|
116
|
-
def is_cleared(win)
|
117
|
-
_win(win, :_clear)
|
118
|
-
end
|
119
|
-
def is_idcok(win)
|
120
|
-
_win(win, :_idcok)
|
121
|
-
end
|
122
|
-
def is_idlok(win)
|
123
|
-
_win(:win, :_idlok)
|
124
|
-
end
|
125
|
-
def is_immedok(win)
|
126
|
-
_win(win, :_immed)
|
127
|
-
end
|
128
|
-
def is_keypad(win)
|
129
|
-
_win(win, :_use_keypad)
|
130
|
-
end
|
131
|
-
def is_leaveok(win)
|
132
|
-
_win(win, :_leaveok) || ERR
|
133
|
-
end
|
134
|
-
def is_nodelay(win)
|
135
|
-
_win(win, :_delay) == 0 ? FFI::NCurses::TRUE : FFI::NCurses::FALSE
|
136
|
-
end
|
137
|
-
def is_notimeout(win)
|
138
|
-
_win(win, :_notimeout)
|
139
|
-
end
|
140
|
-
def is_scrollok(win)
|
141
|
-
_win(win, :_scroll)
|
142
|
-
end
|
143
|
-
def is_syncok(win)
|
144
|
-
_win(win, :_sync)
|
145
|
-
end
|
146
|
-
def wgetparent(win)
|
147
|
-
_win(win, :_parent)
|
148
|
-
end
|
149
|
-
def wgetscrreg(win, t, b)
|
150
|
-
# ((win) ? (*(t) = (win)->_regtop, *(b) = (win)->_regbottom, OK) : ERR)
|
151
|
-
# not entirely satisfactory - no error return
|
152
|
-
# should I raise an exception?
|
153
|
-
if win
|
154
|
-
win_st = WinSt.new(win)
|
155
|
-
[win_st[:_regtop], win_st[:_regbottom]]
|
156
|
-
else
|
157
|
-
#raise ArgumentError, "win is nil"
|
158
|
-
nil
|
159
|
-
end
|
160
|
-
end
|
161
41
|
end
|
162
|
-
|
163
|
-
# struct _win_st
|
164
|
-
# {
|
165
|
-
# NCURSES_SIZE_T _cury, _curx; /* current cursor position */
|
166
|
-
|
167
|
-
# /* window location and size */
|
168
|
-
# NCURSES_SIZE_T _maxy, _maxx; /* maximums of x and y, NOT window size */
|
169
|
-
# NCURSES_SIZE_T _begy, _begx; /* screen coords of upper-left-hand corner */
|
170
|
-
|
171
|
-
# short _flags; /* window state flags */
|
172
|
-
|
173
|
-
# /* attribute tracking */
|
174
|
-
# attr_t _attrs; /* current attribute for non-space character */
|
175
|
-
# chtype _bkgd; /* current background char/attribute pair */
|
176
|
-
|
177
|
-
# /* option values set by user */
|
178
|
-
# bool _notimeout; /* no time out on function-key entry? */
|
179
|
-
# bool _clear; /* consider all data in the window invalid? */
|
180
|
-
# bool _leaveok; /* OK to not reset cursor on exit? */
|
181
|
-
# bool _scroll; /* OK to scroll this window? */
|
182
|
-
# bool _idlok; /* OK to use insert/delete line? */
|
183
|
-
# bool _idcok; /* OK to use insert/delete char? */
|
184
|
-
# bool _immed; /* window in immed mode? (not yet used) */
|
185
|
-
# bool _sync; /* window in sync mode? */
|
186
|
-
# bool _use_keypad; /* process function keys into KEY_ symbols? */
|
187
|
-
# int _delay; /* 0 = nodelay, <0 = blocking, >0 = delay */
|
188
|
-
|
189
|
-
# struct ldat *_line; /* the actual line data */
|
190
|
-
|
191
|
-
# /* global screen state */
|
192
|
-
# NCURSES_SIZE_T _regtop; /* top line of scrolling region */
|
193
|
-
# NCURSES_SIZE_T _regbottom; /* bottom line of scrolling region */
|
194
|
-
|
195
|
-
# /* these are used only if this is a sub-window */
|
196
|
-
# int _parx; /* x coordinate of this window in parent */
|
197
|
-
# int _pary; /* y coordinate of this window in parent */
|
198
|
-
# WINDOW *_parent; /* pointer to parent if a sub-window */
|
199
|
-
|
200
|
-
# /* these are used only if this is a pad */
|
201
|
-
# struct pdat
|
202
|
-
# {
|
203
|
-
# NCURSES_SIZE_T _pad_y, _pad_x;
|
204
|
-
# NCURSES_SIZE_T _pad_top, _pad_left;
|
205
|
-
# NCURSES_SIZE_T _pad_bottom, _pad_right;
|
206
|
-
# } _pad;
|
207
|
-
|
208
|
-
# NCURSES_SIZE_T _yoffset; /* real begy is _begy + _yoffset */
|
209
|
-
|
210
|
-
# #ifdef _XOPEN_SOURCE_EXTENDED
|
211
|
-
# cchar_t _bkgrnd; /* current background char/attribute pair */
|
212
|
-
# #endif
|
213
|
-
# };
|
214
42
|
end
|
215
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-ncurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -9,19 +9,9 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-16 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: ffi
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.2.0
|
24
|
-
version:
|
25
15
|
- !ruby/object:Gem::Dependency
|
26
16
|
name: bones
|
27
17
|
type: :development
|
@@ -32,7 +22,7 @@ dependencies:
|
|
32
22
|
- !ruby/object:Gem::Version
|
33
23
|
version: 2.4.0
|
34
24
|
version:
|
35
|
-
description:
|
25
|
+
description: A wrapper for ncurses 5.x. Tested on Mac OS X 10.4 (Tiger) and Ubuntu 8.04 with ruby 1.8.6 using ruby-ffi (>= 0.2.0) and JRuby 1.1.6. The API is very much a transliteration of the C API rather than an attempt to provide an idiomatic Ruby object-oriented API. The intent is to provide a 'close to the metal' wrapper around the ncurses library upon which you can build your own abstractions. See the examples directory for real working examples.
|
36
26
|
email: sean.ohalpin@gmail.com
|
37
27
|
executables: []
|
38
28
|
|
@@ -47,6 +37,7 @@ files:
|
|
47
37
|
- Rakefile
|
48
38
|
- examples/doc-eg1.rb
|
49
39
|
- examples/doc-eg2.rb
|
40
|
+
- examples/doc-eg3.rb
|
50
41
|
- examples/example-attributes.rb
|
51
42
|
- examples/example-colour.rb
|
52
43
|
- examples/example-cursor.rb
|