ffi-ncurses 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/COPYING +22 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +13 -0
  4. data/History.txt +32 -3
  5. data/README.rdoc +118 -58
  6. data/Rakefile +30 -0
  7. data/examples/acs_chars.rb +53 -0
  8. data/examples/acs_chars.rbc +1502 -0
  9. data/examples/{example-attributes.rb → attributes.rb} +0 -0
  10. data/examples/color.rb +63 -0
  11. data/examples/cursor.rb +27 -0
  12. data/examples/example.rb +17 -17
  13. data/examples/getkey.rb +212 -0
  14. data/examples/{example-getsetsyx.rb → getsetsyx.rb} +2 -2
  15. data/examples/globals.rb +38 -0
  16. data/examples/hello.rb +34 -0
  17. data/examples/hello.rbc +638 -0
  18. data/examples/hellowide.rb +59 -0
  19. data/examples/keys.rb +27 -0
  20. data/examples/{example-mouse.rb → mouse.rb} +2 -2
  21. data/examples/multiterm.rb +120 -0
  22. data/examples/ncurses/LICENSES_for_examples +26 -0
  23. data/examples/{ncurses-example.rb → ncurses/example.rb} +13 -80
  24. data/examples/ncurses/hello_ncurses.rb +57 -0
  25. data/examples/ncurses/rain.rb +220 -0
  26. data/examples/ncurses/read_line.rb +67 -0
  27. data/examples/ncurses/subwin.rb +71 -0
  28. data/examples/ncurses/tclock.rb +227 -0
  29. data/examples/newterm.rb +65 -0
  30. data/examples/panel_simple.rb +82 -0
  31. data/examples/{example-printw-variadic.rb → printw-variadic.rb} +1 -1
  32. data/examples/ripoffline.rb +86 -0
  33. data/examples/run-all.sh +14 -0
  34. data/examples/{example-softkeys.rb → softkeys.rb} +0 -0
  35. data/examples/{example-stdscr.rb → stdscr.rb} +2 -1
  36. data/examples/temp_leave.rb +99 -0
  37. data/examples/viewer.rb +350 -0
  38. data/examples/wacs_chars.rb +64 -0
  39. data/examples/windows.rb +73 -0
  40. data/ffi-ncurses.gemspec +39 -52
  41. data/lib/ffi-ncurses.rb +214 -474
  42. data/lib/ffi-ncurses/acs.rb +150 -0
  43. data/lib/ffi-ncurses/bool_wrappers.rb +66 -0
  44. data/lib/ffi-ncurses/functions.rb +450 -0
  45. data/lib/ffi-ncurses/keydefs.rb +136 -99
  46. data/lib/ffi-ncurses/mouse.rb +106 -106
  47. data/lib/ffi-ncurses/ncurses.rb +176 -0
  48. data/lib/ffi-ncurses/{ord-shim.rb → ord_shim.rb} +0 -0
  49. data/lib/ffi-ncurses/panel.rb +21 -0
  50. data/lib/ffi-ncurses/typedefs.rb +35 -0
  51. data/lib/ffi-ncurses/version.rb +7 -0
  52. data/lib/ffi-ncurses/widechars.rb +137 -0
  53. data/lib/ffi-ncurses/winstruct.rb +55 -33
  54. data/spec/attached_functions_spec.rb +42 -0
  55. metadata +95 -85
  56. data/examples/example-colour.rb +0 -63
  57. data/examples/example-cursor.rb +0 -22
  58. data/examples/example-hello.rb +0 -24
  59. data/examples/example-jruby.rb +0 -14
  60. data/examples/example-keys.rb +0 -25
  61. data/examples/example-windows.rb +0 -24
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8; -*-
3
+ require 'ffi-ncurses'
4
+
5
+ include FFI::NCurses
6
+
7
+ def main
8
+ begin
9
+ initscr
10
+
11
+ # FIXME: This isn't working in 1.8.x
12
+ def addwch(ch)
13
+ cchar = WinStruct::CCharT.new
14
+ cchar[:chars][0] = ch
15
+ # cchar[:attr] = WA_REVERSE
16
+ # chars = [ch].pack('S')
17
+ # padding = 5 - chars.size
18
+ # cchar = [WA_REVERSE].pack('L') + chars + ([0] * padding).pack('S')
19
+ wadd_wch(stdscr, cchar)
20
+ end
21
+
22
+ addstr("Upper left corner "); addwch(WACS_ULCORNER); addstr("\n");
23
+ addstr("Lower left corner "); addwch(WACS_LLCORNER); addstr("\n");
24
+ addstr("Lower right corner "); addwch(WACS_LRCORNER); addstr("\n");
25
+ addstr("Tee pointing right "); addwch(WACS_LTEE); addstr("\n");
26
+ addstr("Tee pointing left "); addwch(WACS_RTEE); addstr("\n");
27
+ addstr("Tee pointing up "); addwch(WACS_BTEE); addstr("\n");
28
+ addstr("Tee pointing down "); addwch(WACS_TTEE); addstr("\n");
29
+ addstr("Horizontal line "); addwch(WACS_HLINE); addstr("\n");
30
+ addstr("Vertical line "); addwch(WACS_VLINE); addstr("\n");
31
+ addstr("Large Plus or cross over "); addwch(WACS_PLUS); addstr("\n");
32
+ addstr("Scan Line 1 "); addwch(WACS_S1); addstr("\n");
33
+ addstr("Scan Line 3 "); addwch(WACS_S3); addstr("\n");
34
+ addstr("Scan Line 7 "); addwch(WACS_S7); addstr("\n");
35
+ addstr("Scan Line 9 "); addwch(WACS_S9); addstr("\n");
36
+ addstr("Diamond "); addwch(WACS_DIAMOND); addstr("\n");
37
+ addstr("Checker board (stipple) "); addwch(WACS_CKBOARD); addstr("\n");
38
+ addstr("Degree Symbol "); addwch(WACS_DEGREE); addstr("\n");
39
+ addstr("Plus/Minus Symbol "); addwch(WACS_PLMINUS); addstr("\n");
40
+ addstr("Bullet "); addwch(WACS_BULLET); addstr("\n");
41
+ addstr("Arrow Pointing Left "); addwch(WACS_LARROW); addstr("\n");
42
+ addstr("Arrow Pointing Right "); addwch(WACS_RARROW); addstr("\n");
43
+ addstr("Arrow Pointing Down "); addwch(WACS_DARROW); addstr("\n");
44
+ addstr("Arrow Pointing Up "); addwch(WACS_UARROW); addstr("\n");
45
+ addstr("Board of squares "); addwch(WACS_BOARD); addstr("\n");
46
+ addstr("Lantern Symbol "); addwch(WACS_LANTERN); addstr("\n");
47
+ addstr("Solid Square Block "); addwch(WACS_BLOCK); addstr("\n");
48
+ addstr("Less/Equal sign "); addwch(WACS_LEQUAL); addstr("\n");
49
+ addstr("Greater/Equal sign "); addwch(WACS_GEQUAL); addstr("\n");
50
+ addstr("Pi "); addwch(WACS_PI); addstr("\n");
51
+ addstr("Not equal "); addwch(WACS_NEQUAL); addstr("\n");
52
+ addstr("UK pound sign "); addwch(WACS_STERLING); addstr("\n");
53
+
54
+ refresh
55
+ getch
56
+ rescue => e
57
+ endwin
58
+ raise
59
+ ensure
60
+ endwin
61
+ end
62
+ end
63
+
64
+ main
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Sean O'Halpin, 2009-02-15
4
+ #
5
+ require 'ffi-ncurses'
6
+ require 'ffi-ncurses/widechars'
7
+ include FFI::NCurses
8
+
9
+ def log(*a)
10
+ addstr a.inspect + "\n"
11
+ touchwin(stdscr)
12
+ # STDERR.puts a.inspect
13
+ end
14
+
15
+ begin
16
+ initscr
17
+ curs_set 0
18
+ raw
19
+ noecho
20
+ keypad stdscr, true
21
+ scrollok stdscr, true
22
+ txt = "Press cursor keys to move window"
23
+ win = newwin(7, txt.size + 4, 4, 15)
24
+ box(win, 0, 0)
25
+ inner_win = derwin(win, 4, txt.size + 2, 2, 2)
26
+ wmove(inner_win, 0, 0)
27
+ waddstr(inner_win, txt)
28
+ wmove(inner_win, 2, 0)
29
+ waddstr(inner_win, "Press Ctrl-Q to quit")
30
+
31
+ y, x = getbegyx(win)
32
+ move 0, 0
33
+ log :y, y, :x, x
34
+ refresh
35
+ wrefresh(win)
36
+ wrefresh(inner_win)
37
+
38
+ ch = 0
39
+ while (ch = getch) != KEY_CTRL_Q
40
+ y, x = getbegyx(win)
41
+ old_y, old_x = y, x
42
+ log :y, y, :x, x, :ch, ch, keyname(ch)
43
+ # move 0, 0
44
+ # addstr "y %d x %d" % [y, x]
45
+ case ch
46
+ when KEY_RIGHT
47
+ x += 1
48
+ when KEY_LEFT
49
+ x -= 1
50
+ when KEY_UP
51
+ y -= 1
52
+ when KEY_DOWN
53
+ y += 1
54
+ end
55
+ rv = mvwin(win, y, x)
56
+ log :y1, y, :x1, x, :rv, rv
57
+ if rv == ERR
58
+ # put the window back
59
+ rv = mvwin(win, old_y, old_x)
60
+ end
61
+
62
+ # tell ncurses we want to refresh stdscr (to erase win's frame)
63
+ touchwin(stdscr)
64
+ refresh
65
+ wrefresh(win)
66
+ end
67
+
68
+ rescue Object => e
69
+ endwin
70
+ puts e
71
+ ensure
72
+ endwin
73
+ end
@@ -1,57 +1,44 @@
1
- # -*- encoding: utf-8 -*-
1
+ # -*- coding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
3
 
3
- Gem::Specification.new do |s|
4
- s.name = %q{ffi-ncurses}
5
- s.version = "0.3.3"
6
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
- s.authors = ["Sean O'Halpin"]
8
- s.date = %q{2009-02-24}
9
- s.description = <<-EOT
10
- A wrapper for ncurses 5.x. Tested on Ubuntu 8.04 to 10.04 and Mac OS X
11
- 10.4 (Tiger) with ruby 1.8.6, 1.8.7 and 1.9.x using ffi (>= 0.6.3) and
12
- JRuby 1.5.1.
4
+ require 'ffi-ncurses/version'
5
+
6
+ date = "2011-09-25"
7
+ authors = ["Sean O'Halpin"]
8
+ email = "sean.ohalpin@gmail.com"
9
+ project = FFI::NCurses
10
+ description = "An FFI wrapper around ncursesw 5.x for MRI Ruby 1.8.x, 1.9.x and JRuby."
11
+ dependencies = [
12
+ ["ffi", ">= 1.0.9"],
13
+ ["ffi-locale", ">= 1.0.0"],
14
+ ]
13
15
 
14
- The API is a transliteration of the C API rather than an attempt to
15
- provide an idiomatic Ruby object-oriented API.
16
+ Gem::Specification.new do |s|
17
+ s.authors = authors
18
+ s.email = email
19
+ s.date = date
20
+ s.description = description
21
+ dependencies.each do |dep|
22
+ s.add_dependency *dep
23
+ end
24
+ s.files =
25
+ [
26
+ "#{project::NAME}.gemspec",
27
+ "lib/#{project::NAME}.rb",
28
+ "COPYING",
29
+ "History.txt",
30
+ "README.rdoc",
31
+ "Rakefile",
32
+ "Gemfile",
33
+ "Gemfile.lock",
34
+ ] +
35
+ Dir["examples/**/*"] +
36
+ Dir["lib/**/*.rb"] +
37
+ Dir["spec/**/*.rb"]
16
38
 
17
- See the examples directory for real working examples.
18
- EOT
19
- s.email = %q{sean.ohalpin@gmail.com}
20
- s.extra_rdoc_files = ["History.txt", "README.rdoc"]
21
- s.files = [
22
- "History.txt",
23
- "README.rdoc",
24
- "examples/doc-eg1.rb",
25
- "examples/doc-eg2.rb",
26
- "examples/doc-eg3.rb",
27
- "examples/example-attributes.rb",
28
- "examples/example-colour.rb",
29
- "examples/example-cursor.rb",
30
- "examples/example-getsetsyx.rb",
31
- "examples/example-hello.rb",
32
- "examples/example-jruby.rb",
33
- "examples/example-keys.rb",
34
- "examples/example-mouse.rb",
35
- "examples/example-printw-variadic.rb",
36
- "examples/example-softkeys.rb",
37
- "examples/example-stdscr.rb",
38
- "examples/example-windows.rb",
39
- "examples/example.rb",
40
- "examples/ncurses-example.rb",
41
- "ffi-ncurses.gemspec",
42
- "lib/ffi-ncurses.rb",
43
- "lib/ffi-ncurses/darwin.rb",
44
- "lib/ffi-ncurses/keydefs.rb",
45
- "lib/ffi-ncurses/mouse.rb",
46
- "lib/ffi-ncurses/ord-shim.rb",
47
- "lib/ffi-ncurses/winstruct.rb"
48
- ]
49
- s.has_rdoc = true
50
- s.homepage = %q{http://github.com/seanohalpin/ffi-ncurses}
51
- s.rdoc_options = ["--main", "README.rdoc"]
39
+ s.name = project::NAME
40
+ s.version = project::VERSION
41
+ s.homepage = "http://github.com/seanohalpin/#{project::NAME}"
42
+ s.summary = s.description
52
43
  s.require_paths = ["lib"]
53
- s.rubyforge_project = %q{ffi-ncurses}
54
- s.rubygems_version = %q{1.3.1}
55
- s.summary = %q{FFI wrapper for ncurses}
56
- s.add_dependency("ffi", ">= 0.6.3")
57
44
  end
@@ -1,437 +1,137 @@
1
- # ruby-ffi wrapper for ncurses
2
- # Sean O'Halpin
3
- # version 0.1.0 - 2008-12-04
4
- # version 0.2.0 - 2009-01-18
5
- # version 0.3.0 - 2009-01-31
6
- # - added stdscr, newscr, curscr
7
- # version 0.3.3 - 2010-08-24
8
- # - compatible with ffi-0.6.3
9
- # - example working with ruby 1.9.x (using "q"[0].ord instead of ?q)
10
- # requires ruby-ffi >= 0.6.3 or jruby >= 1.1.6
11
- # tested with
12
- # - ruby 1.8.7, 1.9.x
13
- # - jruby 1.5.1
14
- # on
15
- # - Ubuntu 8.04, 9.04, 9.10, 10.04 (ncurses 5.7)
16
- # - Mac OS X 10.4 (ncurses 5.4)
17
-
1
+ # -*- coding: utf-8; -*-
2
+ # ruby-ffi wrapper for ncurses.
3
+ #
4
+ # Sean O'Halpin, 2008-2011
5
+ #
6
+ # repo & docs: http://github.com/seanohalpin/ffi-ncurses
7
+ #
8
+ # - version 0.1.0 - 2008-12-04
9
+ # - version 0.2.0 - 2009-01-18
10
+ # - version 0.3.0 - 2009-01-31
11
+ # - version 0.3.3 - 2010-08-24
12
+ # - version 0.3.4 - 2010-08-28
13
+ # - version 0.3.5 - 2011-01-05
14
+ # - version 0.4.0 - 2011-09-25
15
+ #
18
16
  require 'ffi'
17
+ require 'ffi-locale'
18
+
19
+ if RUBY_VERSION < '1.9.0'
20
+ # 1.8.x doesn't set the locale - we need this to handle UTF-8 input
21
+ FFI::Locale.setlocale(FFI::Locale::LC_ALL, "")
22
+ end
23
+
24
+ # Load version.
25
+ require 'ffi-ncurses/version'
26
+
27
+ # Load typedefs.
28
+ require 'ffi-ncurses/typedefs'
29
+
30
+ # Load autogenerated function signatures.
31
+ require 'ffi-ncurses/functions'
19
32
 
20
- # would like to check FFI version here rather than use gem but there
21
- # doesn't appear to be a version specified in the ffi lib
33
+ # Load alternative character set definitions.
34
+ require 'ffi-ncurses/acs'
22
35
 
36
+ # Declare module.
23
37
  module FFI
24
38
  module NCurses
25
- VERSION = "0.3.3"
26
39
  extend FFI::Library
40
+ # FFI overwrites the signatures when you call =attach_function= so
41
+ # I keep an untouched deep copy here (used in the Ncurses
42
+ # compatibility layer).
43
+
44
+ FUNCTION_SIGNATURES = Marshal.load(Marshal.dump(FUNCTIONS))
45
+ FUNCTION_SIGNATURES.each do |fsig|
46
+ if fsig[0].to_s == "_wrapped_#{fsig[1]}"
47
+ fsig.shift
48
+ end
49
+ end
50
+
51
+ # Make all instance methods module methods too.
52
+ extend self
27
53
 
28
- # use RUBY_FFI_NCURSES_LIB to specify exactly which lib you want, e.g. ncursesw, XCurses (from PDCurses)
54
+ # Use `RUBY_FFI_NCURSES_LIB` to specify a colon-separated list of
55
+ # libs you want to try to load, e.g.
56
+ #
57
+ # RUBY_FFI_NCURSES_LIB=XCurses:ncurses
58
+ #
59
+ # to try to load XCurses (from PDCurses) first, then ncurses.
60
+ LIB_HANDLE = { }
29
61
  if ENV["RUBY_FFI_NCURSES_LIB"].to_s != ""
30
- LIB_HANDLE = ffi_lib( ENV["RUBY_FFI_NCURSES_LIB"] ).first
62
+ LIB_HANDLE[:ncurses] = ffi_lib(ENV["RUBY_FFI_NCURSES_LIB"].split(/:/)).first
31
63
  else
32
- LIB_HANDLE = ffi_lib(['ncursesw', 'ncurses']).first
64
+ LIB_HANDLE[:ncurses] = ffi_lib(['ncursesw', 'libncursesw', 'ncurses', 'libcurses']).first
33
65
  end
66
+ LIB_HANDLE[:panel] = ffi_lib(['panelw', 'libpanelw', 'panel', 'libpanel']).first
34
67
 
35
68
  begin
36
- symbols = [ "stdscr", "curscr", "newscr" ]
37
- if LIB_HANDLE.respond_to?(:find_symbol)
38
- # these symbols are defined in ncurses.h
39
- SYMBOLS = Hash[*symbols.map { |sym| [sym, LIB_HANDLE.find_symbol(sym)]}.compact.flatten ]
40
- SYMBOLS.keys.each do |sym|
41
- # note that the symbol table entry in a dll for an exported
42
- # variable contains a ~pointer to the address~ of the variable
43
- # which will be initialized in the process's bss (uninitialized)
44
- # data segment when the process is initialized
45
-
46
- # this is unlike methods, where the symbol table entry points to
47
- # the entry point of the method itself
48
-
49
- # variables need another level of indirection because they are
50
- # ~not~ shared between process instances - the sharing is of
51
- # code only
52
- define_method sym do
53
- SYMBOLS[sym].read_pointer
69
+ # These global variables are defined in `ncurses.h`:
70
+ #
71
+ # chtype acs_map[];
72
+ # WINDOW * curscr;
73
+ # WINDOW * newscr;
74
+ # WINDOW * stdscr;
75
+ # char ttytype[];
76
+ # int COLORS;
77
+ # int COLOR_PAIRS;
78
+ # int COLS;
79
+ # int ESCDELAY;
80
+ # int LINES;
81
+ # int TABSIZE;
82
+ #
83
+ # Note that the symbol table entry in a shared lib for an
84
+ # exported variable contains a *pointer to the address* of
85
+ # the variable which will be initialized in the process's
86
+ # bss (uninitialized) data segment when the process is
87
+ # initialized.
88
+
89
+ # This is unlike methods, where the symbol table entry points to
90
+ # the entry point of the method itself.
91
+
92
+ # Variables need another level of indirection because they are
93
+ # *not* shared between process instances - only code is shared.
94
+
95
+ # So we define convenience methods to perform the lookup for
96
+ # us. We can't just stash the value returned by
97
+ # `read_pointer` at load time because it's not initialized
98
+ # until after `initscr` has been called.
99
+ symbols = [
100
+ ["curscr", :pointer],
101
+ ["newscr", :pointer],
102
+ ["stdscr", :pointer],
103
+ ["ttytype", :string],
104
+ ["COLORS", :int],
105
+ ["COLOR_PAIRS", :int],
106
+ ["COLS", :int],
107
+ ["ESCDELAY", :int],
108
+ ["LINES", :int],
109
+ ["TABSIZE", :int],
110
+ ]
111
+ if LIB_HANDLE[:ncurses].respond_to?(:find_symbol)
112
+ symbols.each do |sym, type|
113
+ if handle = LIB_HANDLE[:ncurses].find_symbol(sym)
114
+ define_method sym do
115
+ handle.send("read_#{type}")
116
+ end
117
+ module_function sym
118
+ else
119
+ warn "#{self.name}: #{sym.inspect} not defined"
120
+ end
121
+ end
122
+ # `acs_map` is a special case
123
+ if handle = LIB_HANDLE[:ncurses].find_symbol("acs_map")
124
+ define_method :acs_map do
125
+ handle.get_array_of_uint(0, 128)
54
126
  end
55
- module_function sym
56
127
  end
57
128
  else
58
129
  warn "#find_symbol not available - #{symbols.inspect} not defined"
59
130
  end
60
- rescue Object => e
131
+ rescue => e
61
132
  end
62
133
 
63
- # this list of function signatures was generated by the file
64
- # generate-ffi-ncurses-function-signatures.rb and inserted here by hand
65
- # then edited a bit :)
66
- functions =
67
- [
68
- [:COLOR_PAIR, [:int], :int],
69
- [:PAIR_NUMBER, [:int], :int],
70
- # these functions are only in the debug version of ncurses
71
- # [:_nc_tracebits, [], :string],
72
- # [:_nc_visbuf, [:string], :string],
73
- # [:_traceattr2, [:int, :uint], :string],
74
- # [:_traceattr, [:uint], :string],
75
- # [:_tracecchar_t2, [:int, :pointer], :string],
76
- # [:_tracecchar_t, [:pointer], :string],
77
- # [:_tracechar, [:int], :string],
78
- # [:_tracechtype2, [:int, :uint], :string],
79
- # [:_tracechtype, [:uint], :string],
80
- # [:_tracedump, [:string, :pointer], :void],
81
- # [:_tracef, [:string, :varargs], :void],
82
- # [:_tracemouse, [:pointer], :string],
83
- [:add_wchnstr, [:pointer, :int], :int],
84
- [:add_wch, [:pointer], :int],
85
- [:add_wchstr, [:pointer], :int],
86
- [:addchnstr, [:pointer, :int], :int],
87
- [:addchstr, [:pointer], :int],
88
- [:addch, [:uint], :int],
89
- [:addnstr, [:string, :int], :int],
90
- [:addstr, [:string], :int],
91
- [:assume_default_colors, [:int, :int], :int],
92
- [:attr_get, [:pointer, :pointer, :pointer], :int],
93
- [:attr_off, [:uint, :pointer], :int],
94
- [:attr_on, [:uint, :pointer], :int],
95
- [:attr_set, [:uint, :short, :pointer], :int],
96
- [:attroff, [:uint], :int],
97
- [:attron, [:uint], :int],
98
- [:attrset, [:uint], :int],
99
- [:baudrate, [], :int],
100
- [:beep, [], :int],
101
- [:bkgdset, [:uint], :void],
102
- [:bkgd, [:uint], :int],
103
- [:bkgrnd, [:pointer], :int],
104
- [:bkgrndset, [:pointer], :void],
105
- [:border_set, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int],
106
- [:border, [:uint, :uint, :uint, :uint, :uint, :uint, :uint, :uint], :int],
107
- [:box_set, [:pointer, :pointer, :pointer], :int],
108
- [:box, [:pointer, :uint, :uint], :int],
109
- [:can_change_color, [], :int],
110
- [:cbreak, [], :int],
111
- [:chgat, [:int, :uint, :short, :pointer], :int],
112
- [:clear, [], :int],
113
- [:clearok, [:pointer, :int], :int],
114
- [:clrtobot, [], :int],
115
- [:clrtoeol, [], :int],
116
- [:color_content, [:short, :pointer, :pointer, :pointer], :int],
117
- [:color_set, [:short, :pointer], :int],
118
- [:copywin, [:pointer, :pointer, :int, :int, :int, :int, :int, :int, :int], :int],
119
- [:curs_set, [:int], :int],
120
- [:curses_version, [], :string],
121
- [:def_prog_mode, [], :int],
122
- [:def_shell_mode, [], :int],
123
- [:define_key, [:string, :int], :int],
124
- [:delay_output, [:int], :int],
125
- [:delch, [], :int],
126
- [:deleteln, [], :int],
127
- [:delscreen, [:pointer], :void],
128
- [:delwin, [:pointer], :int],
129
- [:derwin, [:pointer, :int, :int, :int, :int], :pointer],
130
- [:doupdate, [], :int],
131
- [:dupwin, [:pointer], :pointer],
132
- [:echo_wchar, [:pointer], :int],
133
- [:echochar, [:uint], :int],
134
- [:echo, [], :int],
135
- [:endwin, [], :int],
136
- [:erasechar, [], :char],
137
- [:erase, [], :int],
138
- [:filter, [], :void],
139
- [:flash, [], :int],
140
- [:flushinp, [], :int],
141
- [:getbkgd, [:pointer], :uint],
142
- [:getbkgrnd, [:pointer], :int],
143
- [:getch, [], :int],
144
-
145
- [:getattrs, [:pointer], :int],
146
- [:getcurx, [:pointer], :int],
147
- [:getcury, [:pointer], :int],
148
- [:getbegx, [:pointer], :int],
149
- [:getbegy, [:pointer], :int],
150
- [:getmaxx, [:pointer], :int],
151
- [:getmaxy, [:pointer], :int],
152
- [:getparx, [:pointer], :int],
153
- [:getpary, [:pointer], :int],
154
-
155
- # this is defined in mouse.rb
156
- # [:getmouse, [:pointer], :int],
157
- [:getnstr, [:string, :int], :int],
158
- [:getstr, [:string], :int],
159
- [:getwin, [:pointer], :pointer],
160
- [:halfdelay, [:int], :int],
161
- [:has_colors, [], :int],
162
- [:has_ic, [], :int],
163
- [:has_il, [], :int],
164
- [:has_key, [:int], :int],
165
- [:hline_set, [:pointer, :int], :int],
166
- [:hline, [:uint, :int], :int],
167
- [:idcok, [:pointer, :int], :void],
168
- [:idlok, [:pointer, :int], :int],
169
- [:immedok, [:pointer, :int], :void],
170
- [:in_wchnstr, [:pointer, :int], :int],
171
- [:in_wch, [:pointer], :int],
172
- [:in_wchstr, [:pointer], :int],
173
- [:inchnstr, [:pointer, :int], :int],
174
- [:inchstr, [:pointer], :int],
175
- [:inch, [], :uint],
176
- [:init_color, [:short, :short, :short, :short], :int],
177
- [:init_pair, [:short, :short, :short], :int],
178
- # need to intercept this to get stdscr for JRuby (for the moment)
179
- ["_initscr", :initscr, [], :pointer],
180
- [:innstr, [:string, :int], :int],
181
- [:ins_wch, [:pointer], :int],
182
- [:insch, [:uint], :int],
183
- [:insdelln, [:int], :int],
184
- [:insertln, [], :int],
185
- [:insnstr, [:string, :int], :int],
186
- [:insstr, [:string], :int],
187
- [:instr, [:string], :int],
188
- [:intrflush, [:pointer, :int], :int],
189
- [:is_linetouched, [:pointer, :int], :int],
190
- [:is_term_resized, [:int, :int], :int],
191
- [:is_wintouched, [:pointer], :int],
192
- [:isendwin, [], :int],
193
- [:key_defined, [:string], :int],
194
- [:keybound, [:int, :int], :string],
195
- [:keyname, [:int], :string],
196
- [:keyok, [:int, :int], :int],
197
- [:keypad, [:pointer, :int], :int],
198
- [:killchar, [], :char],
199
- [:leaveok, [:pointer, :int], :int],
200
- [:longname, [], :string],
201
- [:mcprint, [:string, :int], :int],
202
- [:meta, [:pointer, :int], :int],
203
- [:mouse_trafo, [:pointer, :pointer, :int], :int],
204
- [:mouseinterval, [:int], :int],
205
- [:mousemask, [:uint, :pointer], :uint],
206
- [:move, [:int, :int], :int],
207
- [:mvadd_wch, [:int, :int, :pointer], :int],
208
- [:mvadd_wchnstr, [:int, :int, :pointer, :int], :int],
209
- [:mvadd_wchstr, [:int, :int, :pointer], :int],
210
- [:mvaddch, [:int, :int, :uint], :int],
211
- [:mvaddchnstr, [:int, :int, :pointer, :int], :int],
212
- [:mvaddchstr, [:int, :int, :pointer], :int],
213
- [:mvaddnstr, [:int, :int, :string, :int], :int],
214
- [:mvaddstr, [:int, :int, :string], :int],
215
- [:mvchgat, [:int, :int, :int, :uint, :short, :pointer], :int],
216
- [:mvcur, [:int, :int, :int, :int], :int],
217
- [:mvdelch, [:int, :int], :int],
218
- [:mvderwin, [:pointer, :int, :int], :int],
219
- [:mvgetch, [:int, :int], :int],
220
- [:mvgetnstr, [:int, :int, :string, :int], :int],
221
- [:mvgetstr, [:int, :int, :string], :int],
222
- [:mvhline_set, [:int, :int, :pointer, :int], :int],
223
- [:mvhline, [:int, :int, :uint, :int], :int],
224
- [:mvin_wch, [:int, :int, :pointer], :int],
225
- [:mvin_wchnstr, [:int, :int, :pointer, :int], :int],
226
- [:mvin_wchstr, [:int, :int, :pointer], :int],
227
- [:mvinch, [:int, :int], :uint],
228
- [:mvinchnstr, [:int, :int, :pointer, :int], :int],
229
- [:mvinchstr, [:int, :int, :pointer], :int],
230
- [:mvinnstr, [:int, :int, :string, :int], :int],
231
- [:mvins_wch, [:int, :int, :pointer], :int],
232
- [:mvinsch, [:int, :int, :uint], :int],
233
- [:mvinsnstr, [:int, :int, :string, :int], :int],
234
- [:mvinsstr, [:int, :int, :string], :int],
235
- [:mvinstr, [:int, :int, :string], :int],
236
- [:mvprintw, [:int, :int, :string, :varargs], :int],
237
- [:mvscanw, [:int, :int, :string, :varargs], :int],
238
- [:mvvline_set, [:int, :int, :pointer, :int], :int],
239
- [:mvvline, [:int, :int, :uint, :int], :int],
240
- [:mvwadd_wchnstr, [:pointer, :int, :int, :pointer, :int], :int],
241
- [:mvwadd_wch, [:pointer, :int, :int, :pointer], :int],
242
- [:mvwadd_wchstr, [:pointer, :int, :int, :pointer], :int],
243
- [:mvwaddchnstr, [:pointer, :int, :int, :pointer, :int], :int],
244
- [:mvwaddch, [:pointer, :int, :int, :uint], :int],
245
- [:mvwaddchstr, [:pointer, :int, :int, :pointer], :int],
246
- [:mvwaddnstr, [:pointer, :int, :int, :string, :int], :int],
247
- [:mvwaddstr, [:pointer, :int, :int, :string], :int],
248
- [:mvwchgat, [:pointer, :int, :int, :int, :uint, :short, :pointer], :int],
249
- [:mvwdelch, [:pointer, :int, :int], :int],
250
- [:mvwgetch, [:pointer, :int, :int], :int],
251
- [:mvwgetnstr, [:pointer, :int, :int, :string, :int], :int],
252
- [:mvwgetstr, [:pointer, :int, :int, :string], :int],
253
- [:mvwhline_set, [:pointer, :int, :int, :pointer, :int], :int],
254
- [:mvwhline, [:pointer, :int, :int, :uint, :int], :int],
255
- [:mvwin_wchnstr, [:pointer, :int, :int, :pointer, :int], :int],
256
- [:mvwin_wch, [:pointer, :int, :int, :pointer], :int],
257
- [:mvwin_wchstr, [:pointer, :int, :int, :pointer], :int],
258
- [:mvwinchnstr, [:pointer, :int, :int, :pointer, :int], :int],
259
- [:mvwinch, [:pointer, :int, :int], :uint],
260
- [:mvwinchstr, [:pointer, :int, :int, :pointer], :int],
261
- [:mvwinnstr, [:pointer, :int, :int, :string, :int], :int],
262
- [:mvwin, [:pointer, :int, :int], :int],
263
- [:mvwins_wch, [:pointer, :int, :int, :pointer], :int],
264
- [:mvwinsch, [:pointer, :int, :int, :uint], :int],
265
- [:mvwinsnstr, [:pointer, :int, :int, :string, :int], :int],
266
- [:mvwinsstr, [:pointer, :int, :int, :string], :int],
267
- [:mvwinstr, [:pointer, :int, :int, :string], :int],
268
- [:mvwprintw, [:pointer, :int, :int, :string, :varargs], :int],
269
- [:mvwscanw, [:pointer, :int, :int, :string, :varargs], :int],
270
- [:mvwvline_set, [:pointer, :int, :int, :pointer, :int], :int],
271
- [:mvwvline, [:pointer, :int, :int, :uint, :int], :int],
272
- [:napms, [:int], :int],
273
- [:newpad, [:int, :int], :pointer],
274
- [:newterm, [:string, :pointer, :pointer], :pointer],
275
- [:newwin, [:int, :int, :int, :int], :pointer],
276
- [:nl, [], :int],
277
- [:nocbreak, [], :int],
278
- [:nodelay, [:pointer, :int], :int],
279
- [:noecho, [], :int],
280
- [:nonl, [], :int],
281
- [:noqiflush, [], :void],
282
- [:noraw, [], :int],
283
- [:notimeout, [:pointer, :int], :int],
284
- [:overlay, [:pointer, :pointer], :int],
285
- [:overwrite, [:pointer, :pointer], :int],
286
- [:pair_content, [:short, :pointer, :pointer], :int],
287
- [:pecho_wchar, [:pointer, :pointer], :int],
288
- [:pechochar, [:pointer, :uint], :int],
289
- [:pnoutrefresh, [:pointer, :int, :int, :int, :int, :int, :int], :int],
290
- [:prefresh, [:pointer, :int, :int, :int, :int, :int, :int], :int],
291
- [:printw, [:string, :varargs], :int],
292
- [:putp, [:string], :int],
293
- [:putwin, [:pointer, :pointer], :int],
294
- [:qiflush, [], :void],
295
- [:raw, [], :int],
296
- [:redrawwin, [:pointer], :int],
297
- [:refresh, [], :int],
298
- [:reset_prog_mode, [], :int],
299
- [:reset_shell_mode, [], :int],
300
- [:resetty, [], :int],
301
- [:resize_term, [:int, :int], :int],
302
- [:resizeterm, [:int, :int], :int],
303
- [:ripoffline, [:int, :pointer], :int],
304
- [:savetty, [], :int],
305
- [:scanw, [:string, :varargs], :int],
306
- [:scr_dump, [:string], :int],
307
- [:scr_init, [:string], :int],
308
- [:scr_restore, [:string], :int],
309
- [:scr_set, [:string], :int],
310
- [:scrl, [:int], :int],
311
- [:scrollok, [:pointer, :int], :int],
312
- [:scroll, [:pointer], :int],
313
- [:set_term, [:pointer], :pointer],
314
- [:setscrreg, [:int, :int], :int],
315
- [:slk_attr_off, [:uint, :pointer], :int],
316
- [:slk_attr_on, [:uint, :pointer], :int],
317
- [:slk_attr_set, [:uint, :short, :pointer], :int],
318
- [:slk_attroff, [:uint], :int],
319
- [:slk_attron, [:uint], :int],
320
- [:slk_attrset, [:uint], :int],
321
- [:slk_attr, [], :uint],
322
- [:slk_clear, [], :int],
323
- [:slk_color, [:short], :int],
324
- [:slk_init, [:int], :int],
325
- [:slk_label, [:int], :string],
326
- [:slk_noutrefresh, [], :int],
327
- [:slk_refresh, [], :int],
328
- [:slk_restore, [], :int],
329
- [:slk_set, [:int, :string, :int], :int],
330
- [:slk_touch, [], :int],
331
- [:standend, [], :int],
332
- [:standout, [], :int],
333
- [:start_color, [], :int],
334
- [:subpad, [:pointer, :int, :int, :int, :int], :pointer],
335
- [:subwin, [:pointer, :int, :int, :int, :int], :pointer],
336
- [:syncok, [:pointer, :int], :int],
337
- [:term_attrs, [], :uint],
338
- [:termattrs, [], :uint],
339
- [:termname, [], :string],
340
- [:tigetflag, [:string], :int],
341
- [:tigetnum, [:string], :int],
342
- [:tigetstr, [:string], :string],
343
- [:timeout, [:int], :void],
344
- [:touchline, [:pointer, :int, :int], :int],
345
- [:touchwin, [:pointer], :int],
346
- [:tparm, [:string, :varargs], :string],
347
- # [:trace, [:uint], :void],
348
- [:typeahead, [:int], :int],
349
- [:ungetch, [:int], :int],
350
- # moved into mouse
351
- # [:ungetmouse, [:pointer], :int],
352
- [:untouchwin, [:pointer], :int],
353
- [:use_default_colors, [], :int],
354
- [:use_env, [:int], :void],
355
- [:use_extended_names, [:int], :int],
356
- [:vid_attr, [:uint, :short, :pointer], :int],
357
- [:vid_puts, [:uint, :short, :pointer, :pointer], :int],
358
- [:vidattr, [:uint], :int],
359
- [:vidputs, [:uint, :pointer], :int],
360
- [:vline_set, [:pointer, :int], :int],
361
- [:vline, [:uint, :int], :int],
362
- [:wadd_wchnstr, [:pointer, :pointer, :int], :int],
363
- [:wadd_wch, [:pointer, :pointer], :int],
364
- [:wadd_wchstr, [:pointer, :pointer], :int],
365
- [:waddchnstr, [:pointer, :pointer, :int], :int],
366
- [:waddch, [:pointer, :uint], :int],
367
- [:waddchstr, [:pointer, :pointer], :int],
368
- [:waddnstr, [:pointer, :string, :int], :int],
369
- [:waddstr, [:pointer, :string], :int],
370
- [:wattr_get, [:pointer, :pointer, :pointer, :pointer], :int],
371
- [:wattr_off, [:pointer, :uint, :pointer], :int],
372
- [:wattr_on, [:pointer, :uint, :pointer], :int],
373
- [:wattr_set, [:pointer, :uint, :short, :pointer], :int],
374
- [:wattroff, [:pointer, :int], :int],
375
- [:wattron, [:pointer, :int], :int],
376
- [:wattrset, [:pointer, :int], :int],
377
- [:wbkgd, [:pointer, :uint], :int],
378
- [:wbkgdset, [:pointer, :uint], :void],
379
- [:wbkgrnd, [:pointer, :pointer], :int],
380
- [:wbkgrndset, [:pointer, :pointer], :void],
381
- [:wborder_set, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int],
382
- [:wborder, [:pointer, :uint, :uint, :uint, :uint, :uint, :uint, :uint, :uint], :int],
383
- [:wchgat, [:pointer, :int, :uint, :short, :pointer], :int],
384
- [:wclear, [:pointer], :int],
385
- [:wclrtobot, [:pointer], :int],
386
- [:wclrtoeol, [:pointer], :int],
387
- [:wcolor_set, [:pointer, :short, :pointer], :int],
388
- [:wcursyncup, [:pointer], :void],
389
- [:wdelch, [:pointer], :int],
390
- [:wdeleteln, [:pointer], :int],
391
- [:wecho_wchar, [:pointer, :pointer], :int],
392
- [:wechochar, [:pointer, :uint], :int],
393
- [:wenclose, [:pointer, :int, :int], :int],
394
- [:werase, [:pointer], :int],
395
- [:wgetbkgrnd, [:pointer, :pointer], :int],
396
- [:wgetch, [:pointer], :int],
397
- [:wgetnstr, [:pointer, :string, :int], :int],
398
- [:wgetstr, [:pointer, :string], :int],
399
- [:whline_set, [:pointer, :pointer, :int], :int],
400
- [:whline, [:pointer, :uint, :int], :int],
401
- [:win_wchnstr, [:pointer, :pointer, :int], :int],
402
- [:win_wch, [:pointer, :pointer], :int],
403
- [:win_wchstr, [:pointer, :pointer], :int],
404
- [:winchnstr, [:pointer, :pointer, :int], :int],
405
- [:winch, [:pointer], :uint],
406
- [:winchstr, [:pointer, :pointer], :int],
407
- [:winnstr, [:pointer, :string, :int], :int],
408
- [:wins_wch, [:pointer, :pointer], :int],
409
- [:winsch, [:pointer, :uint], :int],
410
- [:winsdelln, [:pointer, :int], :int],
411
- [:winsertln, [:pointer], :int],
412
- [:winsnstr, [:pointer, :string, :int], :int],
413
- [:winsstr, [:pointer, :string], :int],
414
- [:winstr, [:pointer, :string], :int],
415
- [:wmove, [:pointer, :int, :int], :int],
416
- [:wnoutrefresh, [:pointer], :int],
417
- [:wprintw, [:pointer, :string, :varargs], :int],
418
- [:wredrawln, [:pointer, :int, :int], :int],
419
- [:wrefresh, [:pointer], :int],
420
- [:wresize, [:pointer, :int, :int], :int],
421
- [:wscanw, [:pointer, :string, :varargs], :int],
422
- [:wscrl, [:pointer, :int], :int],
423
- [:wsetscrreg, [:pointer, :int, :int], :int],
424
- [:wstandend, [:pointer], :int],
425
- [:wstandout, [:pointer], :int],
426
- [:wsyncdown, [:pointer], :void],
427
- [:wsyncup, [:pointer], :void],
428
- [:wtimeout, [:pointer, :int], :void],
429
- [:wtouchln, [:pointer, :int, :int, :int], :int],
430
- [:wvline_set, [:pointer, :pointer, :int], :int],
431
- [:wvline, [:pointer, :uint, :int], :int]
432
- ]
433
- # end of autogenerated function list
434
-
134
+ # This is used for debugging.
435
135
  @unattached_functions = []
436
136
  class << self
437
137
  def unattached_functions
@@ -439,17 +139,16 @@ module FFI
439
139
  end
440
140
  end
441
141
 
442
- # attach functions
443
- functions.each do |func|
142
+ # Attach functions.
143
+ FUNCTIONS.each do |func|
444
144
  begin
445
145
  attach_function(*func)
446
146
  rescue Object => e
447
- # for debugging
448
147
  unattached_functions << func[0]
449
148
  end
450
149
  end
451
150
 
452
- module Colour
151
+ module Color
453
152
  COLOR_BLACK = BLACK = 0
454
153
  COLOR_RED = RED = 1
455
154
  COLOR_GREEN = GREEN = 2
@@ -459,31 +158,11 @@ module FFI
459
158
  COLOR_CYAN = CYAN = 6
460
159
  COLOR_WHITE = WHITE = 7
461
160
  end
462
- Color = Colour
463
- include Colour
464
-
465
- # FIXME: remove this code when JRuby gets find_sym
466
- # fixup for JRuby 1.1.6 - doesn't have find_sym
467
- # can hack for stdscr but not curscr or newscr (no methods return them)
468
- # this will all be removed when JRuby 1.1.7 is released
469
- module FixupInitscr
470
- if !NCurses.respond_to?(:stdscr)
471
- def initscr
472
- @stdscr = NCurses._initscr
473
- end
474
- def stdscr
475
- @stdscr
476
- end
477
- else
478
- def initscr
479
- NCurses._initscr
480
- end
481
- end
482
- end
483
- include FixupInitscr
161
+ include Color
484
162
 
485
163
  module Attributes
486
- # following definitions have been copied (almost verbatim) from ncurses.h
164
+ # The following definitions have been copied (almost verbatim)
165
+ # from `ncurses.h`.
487
166
  NCURSES_ATTR_SHIFT = 8
488
167
  def self.NCURSES_BITS(mask, shift)
489
168
  ((mask) << ((shift) + NCURSES_ATTR_SHIFT))
@@ -512,9 +191,6 @@ module FFI
512
191
  include Attributes
513
192
 
514
193
  module Constants
515
- FALSE = 0
516
- TRUE = 1
517
-
518
194
  ERR = -1
519
195
  OK = 0
520
196
  end
@@ -523,42 +199,82 @@ module FFI
523
199
  require 'ffi-ncurses/winstruct'
524
200
  include WinStruct
525
201
 
526
- module EmulatedFunctions
527
-
528
- # these 'functions' are implemented as macros in ncurses
202
+ require 'ffi-ncurses/panel'
203
+ include PanelStruct
529
204
 
530
- # I'm departing from the NCurses API here - makes no sense to
531
- # force people to use pointer return values when these are
532
- # implemented as macros to make them easy to use in C when we have
533
- # multiple return values in Ruby for that exact same purpose
534
- def getyx(win)
535
- [NCurses.getcury(win), NCurses.getcurx(win)]
205
+ # These following functions are implemented as macros in ncurses.
206
+ module EmulatedFunctions
207
+ # Note that I'm departing from the NCurses API here - it makes
208
+ # no sense to force people to use pointer return values when
209
+ # these methods have been implemented as macros to make them
210
+ # easy to use in *C*. We have multiple return values in Ruby, so
211
+ # let's use them. Call like this:
212
+ #
213
+ # y, x = getyx(win)
214
+ #
215
+ # For compatibility with the existing Ncurses lib, you can also
216
+ # call these functions like so:
217
+ #
218
+ # y = [nil]
219
+ # x = [nil]
220
+ # getyx(win, y, x)
221
+ #
222
+ def getyx(win, y = nil, x = nil)
223
+ res = [NCurses.getcury(win), NCurses.getcurx(win)]
224
+ if y && y.kind_of?(Array) && x.kind_of?(Array)
225
+ y.replace([res[0]])
226
+ x.replace([res[1]])
227
+ end
228
+ res
536
229
  end
537
- def getbegyx(win)
538
- [NCurses.getbegy(win), NCurses.getbegx(win)]
230
+
231
+ def getbegyx(win, y = nil, x = nil)
232
+ res = [NCurses.getbegy(win), NCurses.getbegx(win)]
233
+ if y && y.kind_of?(Array) && x.kind_of?(Array)
234
+ y.replace([res[0]])
235
+ x.replace([res[1]])
236
+ end
237
+ res
539
238
  end
540
- def getparyx(win)
541
- [NCurses.getpary(win), NCurses.getparx(win)]
239
+
240
+ def getparyx(win, y = nil, x = nil)
241
+ res = [NCurses.getpary(win), NCurses.getparx(win)]
242
+ if y && y.kind_of?(Array) && x.kind_of?(Array)
243
+ y.replace([res[0]])
244
+ x.replace([res[1]])
245
+ end
246
+ res
542
247
  end
543
- def getmaxyx(win)
544
- [NCurses.getmaxy(win), NCurses.getmaxx(win)]
248
+
249
+ def getmaxyx(win, y = nil, x = nil)
250
+ res = [NCurses.getmaxy(win), NCurses.getmaxx(win)]
251
+ if y && y.kind_of?(Array) && x.kind_of?(Array)
252
+ y.replace([res[0]])
253
+ x.replace([res[1]])
254
+ end
255
+ res
545
256
  end
546
257
 
547
- # transliterated from ncurses.h
548
- # note: had to spell out NCurses::TRUE - will look into this
549
- def getsyx
550
- if (is_leaveok(newscr) == NCurses::TRUE)
551
- [-1, -1]
258
+ # These have been transliterated from `ncurses.h`.
259
+ def getsyx(y = nil, x = nil)
260
+ if is_leaveok(newscr)
261
+ res = [-1, -1]
552
262
  else
553
- getyx(newscr)
263
+ res = getyx(newscr)
264
+ end
265
+ if y && y.kind_of?(Array) && x.kind_of?(Array)
266
+ y.replace([res[0]])
267
+ x.replace([res[1]])
554
268
  end
269
+ res
555
270
  end
271
+
556
272
  def setsyx(y, x)
557
273
  if y == -1 && x == -1
558
- leaveok(newscr, NCurses::TRUE)
274
+ leaveok(newscr, true)
559
275
  else
560
- leaveok(newscr, NCurses::FALSE)
561
- wmove(newscr, y, x)
276
+ leaveok(newscr, false)
277
+ wmove(newscr, y, x)
562
278
  end
563
279
  end
564
280
 
@@ -568,7 +284,7 @@ module FFI
568
284
  end
569
285
  end
570
286
 
571
- # hack for XCurses (PDCurses 3.3) - many more to come I suspect :)
287
+ # Hack for XCurses (PDCurses 3.3) - many more to come I suspect.
572
288
  fixup :getch do
573
289
  def getch
574
290
  wgetch(stdscr)
@@ -576,17 +292,41 @@ module FFI
576
292
  end
577
293
  end
578
294
  include EmulatedFunctions
295
+ extend EmulatedFunctions
579
296
 
580
- # fixes for Mac OS X (mostly macros directly referencing the WINDOW struct)
581
- if ::FFI::Platform::OS == "darwin"
297
+ # Include fixes for Mac OS X (mostly macros directly referencing
298
+ # the `WINDOW` struct).
299
+ #
300
+ # FIXME: Might need these for BSD too.
301
+ if defined?(::FFI::Platform::OS) && ::FFI::Platform::OS == "darwin"
582
302
  require 'ffi-ncurses/darwin'
583
303
  include NCurses::Darwin
584
304
  end
585
305
 
586
- # make all those instance methods module methods too
587
- extend self
306
+ # We need to define our own `initscr` so we can add the ACS
307
+ # constants dynamically.
308
+ private :_wrapped_initscr
309
+ private :_wrapped_newterm
588
310
 
311
+ def initscr
312
+ _wrapped_initscr
313
+ NCurses.define_acs_constants
314
+ stdscr
315
+ end
316
+
317
+ def newterm(name, out_filep, in_filep)
318
+ rv = _wrapped_newterm(name, out_filep, in_filep)
319
+ NCurses.define_acs_constants
320
+ rv
321
+ end
589
322
  end
590
323
  end
591
324
 
325
+ # Include wrappers for functions with bool arguments.
326
+ require 'ffi-ncurses/bool_wrappers'
327
+
328
+ # Include key definitions.
592
329
  require 'ffi-ncurses/keydefs'
330
+
331
+ # Include mouse functions and key definitions.
332
+ require 'ffi-ncurses/mouse'