commit 392f469830c29fcf8c3e09e993bd61a86b891a8f
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Thu, 31 Dec 2009 18:32:03 -0800
import ncurses-ruby 1.2.4
Diffstat:
| A |
COPYING |
| |
515 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
Changes |
| |
53 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
MANIFEST |
| |
28 |
++++++++++++++++++++++++++++
|
| A |
README |
| |
355 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
THANKS |
| |
15 |
+++++++++++++++
|
| A |
TODO |
| |
15 |
+++++++++++++++
|
| A |
VERSION |
| |
1 |
+
|
| A |
examples/LICENSES_for_examples |
| |
26 |
++++++++++++++++++++++++++
|
| A |
examples/example.rb |
| |
129 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/form.rb |
| |
82 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/form2.rb |
| |
184 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/hello_ncurses.rb |
| |
57 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/rain.rb |
| |
219 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/read_line.rb |
| |
67 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/tclock.rb |
| |
227 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
examples/test_scanw.rb |
| |
27 |
+++++++++++++++++++++++++++
|
| A |
extconf.rb |
| |
137 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
form_wrap.c |
| |
1449 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
form_wrap.h |
| |
61 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
lib/ncurses.rb |
| |
344 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
make_dist.rb |
| |
45 |
+++++++++++++++++++++++++++++++++++++++++++++
|
| A |
menu_wrap.c |
| |
1144 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
menu_wrap.h |
| |
49 |
+++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
ncurses_wrap.c |
| |
2768 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
ncurses_wrap.h |
| |
101 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
panel_wrap.c |
| |
256 |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
| A |
panel_wrap.h |
| |
32 |
++++++++++++++++++++++++++++++++
|
27 files changed, 8386 insertions(+), 0 deletions(-)
diff --git a/COPYING b/COPYING
@@ -0,0 +1,515 @@
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+^L
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+^L
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control
+compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+^L
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+^L
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+^L
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+^L
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply, and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License
+may add an explicit geographical distribution limitation excluding those
+countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+^L
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+^L
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library.
+It is safest to attach them to the start of each source file to most
+effectively convey the exclusion of warranty; and each file should
+have at least the "copyright" line and a pointer to where the full
+notice is found.
+
+
+ <one line to give the library's name and a brief idea of what it
+does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper
+mail.
+
+You should also get your employer (if you work as a programmer) or
+your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James
+Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/Changes b/Changes
@@ -0,0 +1,53 @@
+ncurses-ruby-1.1
+* Bugfixes by T. Sutherland in _tracef and _tracedump.
+
+ncurses-ruby-1.0
+* Mousemask bugfix from P.Duncan.
+* Solved timing problems that affected visual smoothness of reactions
+ to user input
+* Each SCREEN got back its own "halfdelay" and "cbreak" settings
+
+ncurses-ruby-0.9.2
+ * Preventing getch and wgetch functions from blocking other ruby threads.
+ * Previously ncurses-ruby installed two files named "ncurses.rb" and
+ "ncurses.so". The "ncurses.so" is now renamed to "ncurses_bin.so"
+ to prevent "require 'ncurses'" from accidentally loading only the
+ binary file in case that this is found first in ruby's load path.
+ * Reintroduced ability to "include" Ncurses functions:
+ Use "include Ncurses::Namespace" for that. This is implemented via
+ method_missing, so that ncurses functions (some of which have very
+ common names) will not hide other functions defined in the extended
+ scope. (Any existing method_missing function is properly aliased and
+ called after an unsuccessful lookup.)
+
+ncurses-ruby-0.9.1
+ * Bugfix in *in*str functions (Hiroshi Sainohira)
+ * Fix linking error on Mac OS X and some other platforms (Andreas Schwarz)
+
+ncurses-ruby-0.9:
+ * Forms wrapper contributed by Simon Kaczor
+ * ncurses-ruby now also works with ncurses-4.2
+ (an old release from 1998, needed for Zaurus-port)
+ * First binary package for Sharp Zaurus (arm-linux)
+
+ncurses-ruby-0.8:
+ * Bugfix: Calls into the ncurses library prior to calling
+ Ncurses::initscr or Ncurses::newterm had previously crashed
+ the Ruby interpreter.
+ Fixed by delaying the binding of most Ncurses functions
+ until after Ncurses::initscr or Ncurses::newterm have been
+ called.
+ * Replaced module functions with singleton functions. This
+ means that
+ include Ncurses
+ initscr
+ is no longer possible. Instead, use
+ Ncurses.initscr
+ Reasons: - Consistency. The shortcut has never been possible
+ with all ncurses functions.
+ - Namespace pollution. Some ncurses functions have
+ too common names.
+
+ncurses-ruby-0.7.2:
+ * reintroduced Ncurses::pechochar and Ncurses::redrawwin in the ncurses build.
+ These had been removed by mistake because they did not work with PDCurses.
diff --git a/MANIFEST b/MANIFEST
@@ -0,0 +1,28 @@
+Changes
+COPYING
+MANIFEST
+README
+THANKS
+TODO
+VERSION
+examples/example.rb
+examples/form.rb
+examples/form2.rb
+examples/hello_ncurses.rb
+examples/LICENSES_for_examples
+examples/rain.rb
+examples/tclock.rb
+examples/read_line.rb
+examples/test_scanw.rb
+extconf.rb
+form_wrap.c
+form_wrap.h
+make_dist.rb
+ncurses_wrap.c
+ncurses_wrap.h
+lib/ncurses.rb
+panel_wrap.c
+panel_wrap.h
+menu_wrap.c
+menu_wrap.h
+
diff --git a/README b/README
@@ -0,0 +1,355 @@
+$Id: README,v 1.16 2009/05/03 14:13:27 t-peters Exp $
+------------------------------------------------------------------------
+This directory contains a ruby module for accessing the FSF's ncurses
+library.
+(C) 2002, 2003, 2004 Tobias Peters <t-peters@users.berlios.de>
+(C) 2004 Simon Kaczor <skaczor@cox.net>
+(C) 2005 2006 Tobias Herzke <t-peters@users.berlios.de>
+
+This module is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This module is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this module; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+------------------------------------------------------------------------
+
+Overview
+========
+
+This README file explains how to use the ncurses ruby interface. It is
+assumed that the reader has a rough understanding of what the ncurses
+library is and how to use it from the C language. It then goes into
+detail, explaining what is covered by the ruby interface, and the
+rules that were followed in translating the C interface into a ruby
+interface.
+
+This ncurses interface provides access to the functions, macros,
+global variables and constants of the ncurses library. These are
+mapped to a Ruby Module named "Ncurses": Functions and external
+variables are implemented as singleton functions of the Module
+Ncurses.
+
+This README is organized into the following parts:
+- Overview
+- Installation and Usage
+- External Variables
+- Constants
+- Functions (and their Interfaces)
+- Module / Class Hierarchie
+- The WINDOW class
+- The panel Library
+- The form Library
+- The menu Library
+- Locale handling
+- Ncurses and Ruby Threads
+- Example programs
+
+General Ncurses Literature
+--------------------------
+
+If you don't know how to use ncurses from C, then please read an
+introduction to ncurses before continuing with this README. Eric
+Raymond has written an introduction that should be part of the ncurses
+development package installed on your computer.
+If you'd like a gentler introduction, then you have two options:
+(1) there is a part of a chapter in "The Linux Programmer's Guide" dealing
+ with ncurses, available from www.tldp.org. It is quite old by now,
+ but the ncurses interface has not changed since then, regarding the
+ scope of covered functions, so it is still a very good read.
+(2) There is also an up-to-date "NCURSES-Programming-HOWTO" in the HOWTO
+ collection of the Linux Documentation Project, also available at
+ www.tldp.org, which is worth a read.
+
+You will also appreciate the extensive man-pages of ncurses, a useful
+reference while coding.
+
+
+Installation and Usage
+======================
+
+ruby extconf.rb
+make
+make install
+
+In your programs:
+require "ncurses.rb"
+
+If your programs use the scanw functions (most unlikely) you will have to
+install the scanf library for ruby (http://www.rubyhacker.com/code/scanf).
+
+Most ncurses functions are only available after either Ncurses.initscr or
+Ncurses.newterm has returned successfully.
+
+External Variables
+==================
+
+External variables are accessed read-only, by module functions taking no
+arguments. They are spelled exactly like their C counterparts. Sometimes, this
+leads to module functions beginning with an uppercase letter (e.g.
+Ncurses.LINES).
+
+One of these external variables, ESCDELAY, is also settable with a ruby method
+(Ncurses.ESCDELAY=).
+
+Another external variable, Ncurses.RESIZEDELAY is introduced by this wrapper.
+It contains the maximum milliseconds delay with which terminal resizesings are
+recognized.
+
+Constants
+=========
+(static C Preprocessor macros)
+
+Constants are implemented as module constants in the Ncurses module, if
+possible. Ruby constants can not start with an underscore, so these constants
+have been renamed (they lost the leading underscore). There are,however,
+module functions with the same name as these constants, that also return
+the constant's value, when invoked (e.g. "Ncurses._ENDLINE" returns the value
+of the constant "Ncurses::ENDLINE", which has the same value as the C constant
+"_ENDLINE").
+
+Note: The ncurses macros starting with ACS_ are not constants, their value
+depends on the terminal in use. Nevertheless, they are implemented as
+constants of the Ncurses module, but since they depend on the terminal, they
+are not initialized before initscr() has been called. If you need more than
+one terminal in a single program, you can access the ACS_ values through member
+functions of class SCREEN.
+
+
+Functions (and their Interfaces)
+================================
+
+Functions (also those only implemented by macros in C) can be accessed
+as module functions of the Module Ncurses. They take exactly the same
+arguments as their C counterparts. Some of the C functions return additional
+arguments through pointer arguments. These are implemented as follows:
+
+
+Functions expecting pointers to integer types
+---------------------------------------------
+
+When the C-function expects a pointer to int, short, chtype, or attr_type,
+You should use a variable containing an empty array as the argument to the ruby
+function. This is because ruby passes these types (ints) "by value" instead of
+"by reference"; but arrays are passed by reference, so that you can see the
+changes to them.
+Attention: some macro-only functions like getsyx accept variables of type int,
+but, being macros, they write values to their arguments. Thus, they also need
+empty array arguments when called from ruby.
+Example:
+ color_pair_number = 4
+ foreground_color = []
+ background_color = []
+ if (Ncurses.pair_content(color_pair_number, foreground_color,
+ background_color) != Ncurses::ERR)
+ "color pair number #{color_pair_number} contains color number " +
+ "#{foreground_color[0]} as the foreground color, and color " +
+ "number #{background_color[0]} as the background color")
+ end
+
+There are 2 functions that read a value from the location pointed to by a
+pointer to int, and store another value at those locations. These functions are
+mouse_trafo and wmouse_trafo. When calling these functions, you have to provide
+2 arrays, each filled with exacly one Integer. The values contained in these
+arrays will then be changed by the ruby module function.
+
+
+Functions expecting (non-const) pointers to char
+------------------------------------------------
+
+When the C-function expects a pointer to char, you should use a variable
+containing an empty string as the argument to the ruby function.
+Example:
+ line2 = ""
+ if (Ncurses.mvwinnstr(Ncurses.stdscr, y=2, x=0, line2,
+ Ncurses.getmaxx(Ncurses.stdscr)) == Ncurses::ERR)
+ raise "could not scan 3rd line"
+ else
+ Ncurses.beep if line2.index("|")
+ end
+The string that the C function would store at the pointer-to-char location
+will be appended to the given string.
+
+Functions expecting const pointers to char do not modify the string they
+receive, you can pass any string to them.
+
+
+
+Functions expecting pointers to structs
+---------------------------------------------------
+
+When the C-function expects a pointer to WINDOW, SCREEN, MEVENT,
+PANEL, FORM, FIELD or FIELDTYPE then simply pass it the corresponding,
+already existing ruby object.
+
+
+scanf style functions expecting various pointers
+---------------------------------------------------
+
+namely scanw, mvscanw, wscanw, mvwscanw. Use an array after the format string.
+The scanned values will be placed there. Remember, you need scanf for ruby
+installed for these functions to work.
+
+Module / Class Hierarchie
+=========================
+
+module Ncurses
+ class WINDOW; end
+ class SCREEN; end
+ class MEVENT; end
+ module Panel
+ class PANEL; end
+ end
+ module Form
+ class FORM; end
+ class FIELD; end
+ class FIELDTYPE; end
+ end
+ module Menu
+ class MENU; end
+ class ITEM; end
+ end
+end
+
+
+The WINDOW class
+================
+
+The class WINDOW implements method_missing and tries to map invoked
+methods to Ncurses module functions using a simple heuristic:
+
+If the method name starts with "mv", it looks for a Ncurses module
+function that starts with "mvw", and if it exists, adds itself to the
+argument list and calls this function.
+If no such module function exists, or the name of the invoked method
+does not start with "mv", it looks if there is a module function with
+the name "w" + methodname, and if it exists, adds itself again to the
+argument list and calls this function.
+If this module function did not exist either, then, as a last step, it
+invokes a module function with the same name as the method, adding
+itself to the argument list.
+
+Example: If you invoke win.mvaddch(y,x,ch) on an Ncurses::WINDOW
+object, it will delegate the method call to
+Ncurses.mvwaddch(win,y,x,ch).
+
+Other examples:
+
+ win.printw("hello") => Ncurses.wprintw(win, "hello")
+
+ win.getmaxyx(y=[],
+ x=[]) => Ncurses.getmaxyx(win,y,x)
+
+ win.delwin() => Ncurses.delwin(win) # win cannot be used
+ # after this call
+
+
+The panel Library
+=================
+
+The panel library has also been wrapped. All panel functions are
+implemented as module functions of the module Ncurses::Panel.
+
+Most of these functions are also implemented as methods of class
+Ncurses::Panel::PANEL, once with their original name and once with the
+subword "panel" and an adjacent underscore removed.
+
+The form Library
+================
+
+The form library was wrapped inside the Ncurses:Form module. All
+form functions are implemented as module functions on the module
+Ncurses::Form. In addition, all function for which the first
+parameter is one of the objects are also implemented as an instance
+method of the respective class. For example, instead of calling
+post_form(form), you can use form.post_form().
+
+Three objects are defined in the Ncurses:Form module:
+ 1. FORM
+ 2. FIELD
+ 3. FIELDTYPE
+
+They are wrapping actual ncurses pointers and should be use whenever a
+pointer to one of these types is expected in function calls.
+
+All form constants are defined in the module as Ruby constants with
+the same name as the curses constants.
+
+Constructors for FORM, FIELD and FIELDTYPE objects are also provided,
+and they expect the same parameters as new_form, new_field and
+new_fieldtype curses functions.
+
+Field validation is implemented using Ruby Proc objects. You must
+provide a Ruby block whenever a function pointer is expected in curses
+function arguments. See the example form2.rb for more details.
+
+The functions form_userptr and field_userptr are not supported. Use
+form.user_object and field.user_object to store Ruby objects instead.
+
+The menu Library
+================
+
+The menu library was wrapped inside the Ncurses:Menu module. All
+menu functions are implemented as module functions in the module
+Ncurses::Menu. In addition, all functions for which the first
+parameter is one of the objects are also implemented as an instance
+method of the respective class. For example, instead of calling
+post_menu(menu), you can use menu.post_menu().
+
+Two objects are defined in the Ncurses:Menu module:
+ 1. MENU
+ 2. ITEM
+
+They are wrapping actual ncurses pointers and should be use whenever a
+pointer to one of these types is expected in function calls.
+
+All menu constants are defined in the module as Ruby constants with
+the same name as the curses constants.
+
+Constructors for MENU and ITEM objects are also provided, and they
+expect the same parameters as new_menu and new_item curses functions.
+
+You must provide a Ruby block whenever a function pointer is expected
+in curses function arguments.
+
+The functions menu_userptr and item_userptr are not supported. Use
+menu.user_object and item.user_object to store Ruby objects instead.
+
+Locale handling
+===============
+
+The C library function setlocale is not technically an Ncurses function.
+However, it is used by many ncurses programs, and for this purpose,
+a wrapper for this function is also included in ncurses-ruby.
+
+The function is implemented as a module function Ncurses.ruby, and
+expects two arguments, an Integer and a String. It returns a string.
+The constants that can be used as the Integer argument are also wrapped
+as constants in the Ncurses module. See the manual page for setlocale
+for documentation of this function.
+
+Ncurses and Ruby Threads
+========================
+
+The ncurses library is not thread-safe. Your application must properly
+serialize calls into ncurses.
+
+Prior to release 0.9.2, the getch and wgetch calls used to block the
+complete ruby interpreter, all threads. This is no longer so. Other
+threads should now continue to run during blocking calls to getch and
+wgetch.
+
+Example programs
+================
+
+Directory "examples" contains a few example programs demonstrating how
+to use the ncurses library with ruby. Be sure to read the file
+"examples/LICENSES_for_examples".
+
diff --git a/THANKS b/THANKS
@@ -0,0 +1,15 @@
+$Id: THANKS,v 1.9 2009/05/03 10:37:54 t-peters Exp $
+
+A list of people that helped me with ncurses-ruby
+
+Akinori MUSHA (knu at idaemons dot org)
+Jan Becvar (jan dot becvar at solnet dot cz)
+Juergen Daubert
+Doug Kearns
+Simon Kaczor (skaczor at cox dut net)
+Hiroshi Sainohira
+Andreas Schwarz
+Simon Strandgaard
+Paul Duncan
+Tim Sutherland
+Earle Clubb
diff --git a/TODO b/TODO
@@ -0,0 +1,15 @@
+$Id: TODO,v 1.6 2003/03/22 22:55:27 t-peters Exp $
+
+This is the complete list of functions present in ncurses that have not yet
+been wrapped by ncurses-ruby:
+
+terminfo functions: setupterm, setterm, set_curterm, del_curterm, restartterm,
+ tparm, tputs, vidputs
+
+termcap fuctions: tgetent, tgetflag, tgetnum, tgetstr, tgoto
+
+ncurses
+kernel functions: ripoffline
+
+No sense in
+wrapping these: vw_printw, vwprintw, vwscanw
diff --git a/VERSION b/VERSION
@@ -0,0 +1 @@
+1.2.4
diff --git a/examples/LICENSES_for_examples b/examples/LICENSES_for_examples
@@ -0,0 +1,26 @@
+$Id: LICENSES_for_examples,v 1.6 2004/05/13 21:55:17 t-peters Exp $
+
+Ideally, an example program on how to use a library should be in the public
+domain.
+
+Some of the example programs contained in this dircectory have not been put in
+the public domain, however.
+
+The reason is because I did not write all programs completely myself -- I've
+adapted the following example programs from ncurses programs in other
+programming languages, or I have included example programs contributed by
+other authors, and I have to respect their original licenses:
+- rain.rb is adapted from rain.c from the ncurses library distribution.
+- example.rb is adapted from an example program for the python ncurses binding.
+- tclock.rb is adapted from tclock.c from the ncurses library distribution.
+- form.rb anf form2.rb have been written by Simon Kaczor, who has adapted them
+ from sample code from the NCurses Programming HOWTO.
+
+See the comments in the source files for restrictions imposed on copying and
+modifying these.
+
+That said, I suppose you may still look at their source code and learn how
+ncurses programs generally work, as long as you dont start your own programs
+by loading the example program into your editor and modify it to your needs.
+
+Tobias Peters <t-peters@users.berlios.de>
diff --git a/examples/example.rb b/examples/example.rb
@@ -0,0 +1,129 @@
+#!/usr/bin/env ruby
+
+# $Id: example.rb,v 1.4 2002/03/04 13:24:29 t-peters Exp $
+
+# This file provides an example for the usage of the ncurses-ruby module.
+# Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
+#
+# The following license applys only to this file. It is less restrictive
+# than the license for the rest of the ncurses-ruby distribution.
+# I've adapted this file from someone else, see below.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this file
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+
+# this file is adapted from an example of the python ncurses binding
+# pyncurses (http://pyncurses.sf.net/), which has the following copyright
+# statement:
+
+# Copyright (c) 2000 by Harry Henry Gebel
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+
+require "ncurses"
+
+def moving(scr)
+ scr.clear() # clear screen
+ scr.move(5,5) # move cursor
+ scr.addstr("move(5,5)")
+ scr.refresh() # update screen
+ sleep(2)
+ scr.move(2,2)
+ scr.addstr("move(2,2)")
+ scr.refresh()
+ sleep(2)
+ scr.move(10, 2)
+ scr.addstr("Press a key to continue")
+ scr.getch()
+end
+
+def border(scr)
+ scr.clear()
+ scr.border(*([0]*8)) # calls WINDOW#border(0, 0, 0, 0, 0, 0, 0, 0)
+ scr.move(3,3)
+ scr.addstr("Press a key to continue")
+ scr.getch()
+end
+
+def two_borders()
+ # make a new window as tall as the screen and half as wide, in the left half
+ # of the screen
+ one = Ncurses::WINDOW.new(0, Ncurses.COLS() / 2, 0, 0)
+ # make one for the right half
+ two = Ncurses::WINDOW.new(0, Ncurses.COLS() - (Ncurses.COLS() / 2),
+ 0, Ncurses.COLS() / 2)
+ one.border(*([0]*8))
+ two.border(*([0]*8))
+ one.move(3,3)
+ two.move(2,5)
+ one.addstr("move(3,3)")
+ two.addstr("move(2,5)")
+ two.move(5,3)
+ two.addstr("Press a key to continue")
+ one.noutrefresh() # copy window to virtual screen, don't update real screen
+ two.noutrefresh()
+ Ncurses.doupdate() # update read screen
+ two.getch()
+end
+
+begin
+ # initialize ncurses
+ Ncurses.initscr
+ Ncurses.cbreak # provide unbuffered input
+ Ncurses.noecho # turn off input echoing
+ Ncurses.nonl # turn off newline translation
+ Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt
+ Ncurses.stdscr.keypad(true) # turn on keypad mode
+
+ Ncurses.stdscr.addstr("Press a key to continue") # output string
+ Ncurses.stdscr.getch # get a charachter
+
+ moving(Ncurses.stdscr) # demo of moving cursor
+ border(Ncurses.stdscr) # demo of borders
+ two_borders() # demo of two windows with borders
+
+ensure
+ Ncurses.echo
+ Ncurses.nocbreak
+ Ncurses.nl
+ Ncurses.endwin
+end
diff --git a/examples/form.rb b/examples/form.rb
@@ -0,0 +1,82 @@
+#!/usr/bin/ruby
+# Copyright (c) 2004 by Simon Kaczor <skaczor@cox.net>
+# Example from the NCurses Programming HOWTO
+# This example uses module functions that are documented in the ncurses man page.
+# For a more rubyish approach that uses Ruby objects see form2.rb
+#
+# The original example contained the following copyright:
+# Copyright (c) 2001 by Pradeep Padala. This document may be distributed
+# under the terms set forth in the LDP license at linuxdoc.org/COPYRIGHT.html.
+
+require 'ncurses.rb'
+
+begin
+ scr = Ncurses.initscr()
+ Ncurses.cbreak()
+ Ncurses.noecho()
+ Ncurses.keypad(scr, true)
+
+ #create some fields
+ fields = Array.new
+ fields.push(Ncurses::Form.new_field(1,10,4,18,0,0))
+ fields.push(Ncurses::Form.new_field(1,10,6,18,0,0))
+
+ # set field options
+ Ncurses::Form.set_field_back(fields[0], Ncurses::A_UNDERLINE)
+ Ncurses::Form.field_opts_off(fields[0], Ncurses::Form::O_AUTOSKIP)
+
+ Ncurses::Form.set_field_back(fields[1], Ncurses::A_UNDERLINE)
+ Ncurses::Form.field_opts_off(fields[1], Ncurses::Form::O_AUTOSKIP)
+
+
+ # create a form
+ form = Ncurses::Form.new_form(fields)
+
+ # post the form and refresh the screen
+ Ncurses::Form.post_form(form)
+ scr.refresh()
+
+ Ncurses.mvprintw(4, 10, "Value 1:")
+ Ncurses.mvprintw(6, 10, "Value 2:")
+ scr.refresh()
+
+ # Loop through to get user requests
+ while((ch = scr.getch()) != Ncurses::KEY_F1) do
+ case(ch)
+ when Ncurses::KEY_DOWN
+ # Go to next field
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_NEXT_FIELD)
+ # Go to the end of the present buffer
+ # Leaves nicely at the last character
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_END_LINE)
+
+ when Ncurses::KEY_UP
+ #Go to previous field
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_PREV_FIELD)
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_END_LINE);
+ else
+ # If this is a normal character, it gets Printed
+ Ncurses::Form.form_driver(form, ch)
+ end
+ end
+
+ # unpost and free form
+ Ncurses::Form.unpost_form(form);
+ Ncurses::Form.free_form(form)
+ Ncurses::Form.free_field(fields[0]);
+ Ncurses::Form.free_field(fields[1]);
+
+
+ #using class methods this time
+# form = Ncurses::Form::FORM.new(fields)
+# puts "Created form: #{form.inspect}\n"
+# form.free()
+
+ensure
+ # put the screen back in its normal state
+ Ncurses.echo()
+ Ncurses.nocbreak()
+ Ncurses.nl()
+ Ncurses.endwin()
+end
+
diff --git a/examples/form2.rb b/examples/form2.rb
@@ -0,0 +1,184 @@
+#!/usr/bin/ruby
+# Copyright (c) 2004 by Simon Kaczor <skaczor@cox.net>
+# Simple example of a form in action, based on the NCURSES Programming HOWTO:
+# http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/
+#
+# All standard field types are created in the form.
+# Additionnally a custom field is created to illustrate
+# custom field validation using Ruby Proc objects, as shown in the example.
+#
+# The original example contained the following copyright:
+# Copyright (c) 2001 by Pradeep Padala. This document may be distributed
+# under the terms set forth in the LDP license at linuxdoc.org/COPYRIGHT.html.
+
+require 'ncurses'
+
+include Ncurses
+include Ncurses::Form
+
+def print_in_middle(win, starty, startx, width, string, color)
+
+ if(win == nil)
+ win = stdscr;
+ end
+ x = Array.new
+ y = Array.new
+ Ncurses.getyx(win, y, x);
+ if(startx != 0)
+ x[0] = startx;
+ end
+ if(starty != 0)
+ y[0] = starty;
+ end
+ if(width == 0)
+ width = 80;
+ end
+ length = string.length;
+ temp = (width - length)/ 2;
+ x[0] = startx + temp.floor;
+ win.attron(color);
+ win.mvprintw(y[0], x[0], "%s", string);
+ win.attroff(color);
+ Ncurses.refresh();
+end
+
+fields = Array.new
+
+states = {"MI" => "Michigan",
+ "VA" => "Virginia",
+ "VE" => "Vermont"}
+fieldcheck = proc { |afield|
+ val = afield.field_buffer(0)
+ val.strip!
+ if (states[val] != nil)
+ afield.set_field_buffer(0,states[val])
+ return true
+ else
+ return false
+ end
+}
+charcheck = proc { |ch|
+ if (('A'..'Z').include?(ch))
+ return true
+ else
+ return false
+ end
+}
+
+# Initialize curses
+begin
+ stdscr = Ncurses.initscr();
+ Ncurses.start_color();
+ Ncurses.cbreak();
+ Ncurses.noecho();
+ Ncurses.keypad(stdscr, true);
+
+ # Initialize few color pairs
+ Ncurses.init_pair(1, COLOR_RED, COLOR_BLACK);
+ Ncurses.init_pair(2, COLOR_BLACK, COLOR_WHITE);
+ Ncurses.init_pair(3, COLOR_BLACK, COLOR_BLUE);
+ stdscr.bkgd(Ncurses.COLOR_PAIR(2));
+
+ # Initialize the fields
+ (1..9).each { |i|
+ field = FIELD.new(1, 10, i*2, 1, 0, 0)
+ field.set_field_back(A_UNDERLINE)
+ fields.push(field)
+ }
+
+ customtype = FIELDTYPE.new(fieldcheck, charcheck);
+
+ fields[1].set_field_type(TYPE_ALNUM, 0);
+ fields[2].set_field_type(TYPE_ALPHA, 0);
+ fields[3].set_field_type(TYPE_INTEGER, 0, 0, 1000);
+ fields[4].set_field_type(TYPE_NUMERIC, 2, 0, 1000);
+ fields[5].set_field_type(TYPE_ENUM, ["one","two","three"], false, false);
+ fields[6].set_field_type(TYPE_REGEXP, "^ *[0-9]* *$");
+ fields[7].set_field_type(TYPE_IPV4);
+ fields[8].set_field_type(customtype);
+
+
+ # Create the form and post it
+ my_form = FORM.new(fields);
+
+ my_form.user_object = "My identifier"
+
+ # Calculate the area required for the form
+ rows = Array.new()
+ cols = Array.new()
+ my_form.scale_form(rows, cols);
+
+ # Create the window to be associated with the form
+ my_form_win = WINDOW.new(rows[0] + 3, cols[0] + 14, 1, 1);
+ my_form_win.bkgd(Ncurses.COLOR_PAIR(3));
+ my_form_win.keypad(TRUE);
+
+ # Set main window and sub window
+ my_form.set_form_win(my_form_win);
+ my_form.set_form_sub(my_form_win.derwin(rows[0], cols[0], 2, 12));
+
+ # Print a border around the main window and print a title */
+ my_form_win.box(0, 0);
+ print_in_middle(my_form_win, 1, 0, cols[0] + 14, "My Form", Ncurses.COLOR_PAIR(1));
+
+ my_form.post_form();
+
+ # Print field types
+ my_form_win.mvaddstr(4, 2, "No Type")
+ my_form_win.mvaddstr(6, 2, "Alphanum")
+ my_form_win.mvaddstr(8, 2, "Alpha")
+ my_form_win.mvaddstr(10, 2, "Integer")
+ my_form_win.mvaddstr(12, 2, "Numeric")
+ my_form_win.mvaddstr(14, 2, "Enum")
+ my_form_win.mvaddstr(16, 2, "Regexp")
+ my_form_win.mvaddstr(18, 2, "IP")
+ my_form_win.mvaddstr(20, 2, "Custom")
+
+ my_form_win.wrefresh();
+
+ stdscr.mvprintw(Ncurses.LINES - 2, 28, "Use UP, DOWN arrow keys to switch between fields");
+ stdscr.mvprintw(Ncurses.LINES - 1, 28, "Press F1 to quit");
+ stdscr.refresh();
+
+ # Loop through to get user requests
+ while((ch = my_form_win.getch()) != KEY_F1)
+ case ch
+ when KEY_DOWN
+ # Go to next field */
+ my_form.form_driver(REQ_VALIDATION);
+ my_form.form_driver(REQ_NEXT_FIELD);
+ # Go to the end of the present buffer
+ # Leaves nicely at the last character
+ my_form.form_driver(REQ_END_LINE);
+
+ when KEY_UP
+ # Go to previous field
+ my_form.form_driver(REQ_VALIDATION);
+ my_form.form_driver(REQ_PREV_FIELD);
+ my_form.form_driver(REQ_END_LINE);
+
+ when KEY_LEFT
+ # Go to previous field
+ my_form.form_driver(REQ_PREV_CHAR);
+
+ when KEY_RIGHT
+ # Go to previous field
+ my_form.form_driver(REQ_NEXT_CHAR);
+
+ when KEY_BACKSPACE
+ my_form.form_driver(REQ_DEL_PREV);
+ else
+ # If this is a normal character, it gets Printed
+ my_form.form_driver(ch);
+ end
+ end
+ # Un post form and free the memory
+ my_form.unpost_form();
+ my_form.free_form();
+ fields.each {|f| f.free_field()}
+
+
+ensure
+ Ncurses.endwin();
+end
+
diff --git a/examples/hello_ncurses.rb b/examples/hello_ncurses.rb
@@ -0,0 +1,57 @@
+#!/usr/bin/env ruby
+
+# $Id: hello_ncurses.rb,v 1.3 2002/02/28 13:50:03 t-peters Exp $
+
+# this ncurses-ruby program follows an ancient tradition of example
+# computer programs: When invoked, it prints a friendly greeting on the
+# screen and exits.
+#
+# Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
+#
+# You may use, modify, and redistribute this file without restriction.
+
+
+
+# First, we have to tell Ruby to use the Ncurses extension module:
+
+require "ncurses"
+
+
+
+# Second, every program using ncurses must initialize the ncurses library
+# before the first call to any ncurses function:
+
+Ncurses.initscr
+
+
+
+# Now the program can use ncurses facilities for screen output. It will print
+# a greeting to the 5th line on the screen, starting at column 20
+
+Ncurses.mvaddstr(4, 19, "Hello, world!");
+
+# Note that ncurses counts lines and columns starting from 0, and that it
+# expects the line number first and the column number second every time it
+# expects a coordinate pair.
+
+
+
+# The previous function call did not alter the screen at all. Ncurses makes
+# all changes first to an internal buffer. The contents of this buffer is
+# copied to the screen with the following function call:
+
+Ncurses.refresh
+
+
+# Now pause for a short while, enough time for the program user to read the
+# greeting and greet back.
+
+sleep(2.5)
+
+
+# The program has almost finished its task. It only needs to put the screen
+# back to its normal state:
+
+Ncurses.endwin
+
+
diff --git a/examples/rain.rb b/examples/rain.rb
@@ -0,0 +1,219 @@
+#!/usr/bin/env ruby
+
+# $Id: rain.rb,v 1.6 2005/08/22 21:41:49 t-peters Exp $
+
+# This program is a translation of the popular rain.c demo program from the
+# ncurses library distribution.
+#
+# Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
+#
+# I do not impose any additional restrictions over the copyright of the
+# ncurses library distribution. It has the following Copyright notice
+
+#/****************************************************************************
+# * Copyright (c) 1998 Free Software Foundation, Inc. *
+# * *
+# * Permission is hereby granted, free of charge, to any person obtaining a *
+# * copy of this software and associated documentation files (the *
+# * "Software"), to deal in the Software without restriction, including *
+# * without limitation the rights to use, copy, modify, merge, publish, *
+# * distribute, distribute with modifications, sublicense, and/or sell *
+# * copies of the Software, and to permit persons to whom the Software is *
+# * furnished to do so, subject to the following conditions: *
+# * *
+# * The above copyright notice and this permission notice shall be included *
+# * in all copies or substantial portions of the Software. *
+# * *
+# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+# * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+# * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+# * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+# * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+# * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+# * *
+# * Except as contained in this notice, the name(s) of the above copyright *
+# * holders shall not be used in advertising or otherwise to promote the *
+# * sale, use or other dealings in this Software without prior written *
+# * authorization. *
+# ****************************************************************************/
+
+
+
+require "ncurses"
+
+
+# A class responsible for raindrop drawing
+class Raindrop
+ def initialize (window, color_pair = nil)
+ @window = window
+ @color_pair = color_pair
+ lines = []
+ columns = []
+ window.getmaxyx(lines,columns)
+ lines = (lines[0] <= 4) ? 1 : (lines[0] - 4)
+ columns = (columns[0] <= 4) ? 1 : (columns[0] - 4)
+ @current_phase = 0
+ @x = rand(columns)+2
+ @y = rand(lines)+2
+ end
+
+ # draw_next_phase draws the next phase of a raindrop. If this was the last
+ # phase, returns 0, otherwise returns the raindrop.
+ def draw_next_phase
+ if (@color_pair)
+ if Ncurses.respond_to?(:color_set)
+ @window.color_set(@color_pair, nil)
+ else
+ @window.attrset(Ncurses.COLOR_PAIR(@color_pair))
+ end
+ end
+ if (DRAWING_PROCS[@current_phase].call(@window,@y,@x))
+ @current_phase += 1
+ self
+ end
+ end
+
+ DRAWING_PROCS = [
+ Proc.new{|window,y,x|
+ window.mvaddstr(y,x, ".")
+ },
+ Proc.new{|window,y,x|
+ window.mvaddstr(y, x, "o")
+ },
+ Proc.new{|window,y,x|
+ window.mvaddstr(y, x, "O")
+ },
+ Proc.new{|window,y,x|
+ window.mvaddstr(y-1, x, "-")
+ window.mvaddstr(y, x-1, "|.|")
+ window.mvaddstr(y+1, x, "-")
+ },
+ Proc.new{|window,y,x|
+ window.mvaddstr(y-2, x, "-")
+ window.mvaddstr(y-1, x-1, "/ \\")
+ window.mvaddstr(y, x-2, "| O |")
+ window.mvaddstr(y+1, x-1, "\\ /")
+ window.mvaddstr(y+2, x, "-")
+ },
+ Proc.new{|window,y,x|
+ window.mvaddstr(y-2, x, " ")
+ window.mvaddstr(y-1, x-1, " ")
+ window.mvaddstr(y, x-2, " ")
+ window.mvaddstr(y+1, x-1, " ")
+ window.mvaddstr(y+2, x, " ")
+ nil # signal the last raindrop phase
+ }
+ ]
+ NUMBER_OF_PHASES = DRAWING_PROCS.size - 1
+end
+
+
+# This class creates raindrops and tells them to draw on the screen
+class Rain
+ AVERAGE_RAINDROP_SPACE = 475.1 # 4 simultaneous raindrops in a 80x24 Window
+
+ def Rain.sigwinch_handler(sig = nil)
+ ObjectSpace.each_object(Rain){|rain|
+ rain.window_size_changed = true
+ }
+ end
+
+ attr_writer :window_size_changed
+
+ def initialize(window)
+ @window = window
+ @window_size_changed = true
+ @raindrops = []
+ @has_colors = Ncurses.has_colors?
+ if (@has_colors)
+ @current_color = 1
+ end
+ end
+
+ def fall_for_a_moment
+ adjust_to_new_window_size if (@window_size_changed)
+
+ current_number_of_new_raindrops.times{
+ if (@has_colors)
+ @raindrops.push(Raindrop.new(@window, @current_color))
+ @current_color = 3 - @current_color # alternate between 1 and 2
+ else
+ @raindrops.push(Raindrop.new(@window))
+ end
+ }
+
+ @raindrops = @raindrops.collect{|raindrop|
+ raindrop.draw_next_phase
+ }.compact # erase raindrops that have expired from the list
+ end
+
+ def adjust_to_new_window_size
+ @window_size_changed = false
+ window_size = @window.getmaxx * @window.getmaxy
+ average_number_of_raindrops = window_size / AVERAGE_RAINDROP_SPACE
+ @average_number_of_new_raindrops =
+ average_number_of_raindrops / Raindrop::NUMBER_OF_PHASES
+ end
+
+ def current_number_of_new_raindrops
+ num_floor = @average_number_of_new_raindrops.floor
+ num_ceil = @average_number_of_new_raindrops.ceil
+ chance = @average_number_of_new_raindrops - num_floor
+ if (rand > chance)
+ num_floor
+ else
+ num_ceil
+ end
+ end
+
+ def fall(pause = 0.1)
+ begin
+ fall_for_a_moment
+ @window.refresh
+ sleep(pause)
+ end while (true)
+ end
+end
+
+Ncurses.initscr
+begin
+ if (Ncurses.has_colors?)
+ bg = Ncurses::COLOR_BLACK
+ Ncurses.start_color
+ if (Ncurses.respond_to?("use_default_colors"))
+ if (Ncurses.use_default_colors == Ncurses::OK)
+ bg = -1
+ end
+ end
+ Ncurses.init_pair(1, Ncurses::COLOR_BLUE, bg);
+ Ncurses.init_pair(2, Ncurses::COLOR_CYAN, bg);
+ end
+ Ncurses.nl()
+ Ncurses.noecho()
+ Ncurses.curs_set(0)
+ Ncurses.stdscr.nodelay(true)
+
+ rain = Rain.new(Ncurses.stdscr)
+
+ begin
+ case(Ncurses.getch())
+ when 'q'[0], 'Q'[0]
+ Ncurses.curs_set(1)
+ Ncurses.endwin()
+ exit
+ when 's'[0]
+ Ncurses.stdscr.nodelay(false)
+ when ' '[0]
+ Ncurses.stdscr.nodelay(true)
+ when Ncurses::KEY_RESIZE
+ Rain.sigwinch_handler
+ end
+ sleep(0.050)
+ rain.fall_for_a_moment
+ Ncurses.refresh
+ end while true
+ensure
+ Ncurses.curs_set(1)
+ Ncurses.endwin()
+end
diff --git a/examples/read_line.rb b/examples/read_line.rb
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+# Emacs: This is -*- ruby -*- code!
+#
+# Unfinished read_line function
+#
+# Written 2003, 2004 by Tobias Peters
+# No warranties
+# Share and enjoy!
+
+require "ncurses"
+
+# read_line returns an array
+# [string, last_cursor_position_in_string, keycode_of_terminating_enter_key].
+# Complete the "when" clauses before including in your app!
+def read_line(y, x,
+ window = Ncurses.stdscr,
+ max_len = (window.getmaxx - x - 1),
+ string = "",
+ cursor_pos = 0)
+ loop do
+ window.mvaddstr(y,x,string)
+ window.move(y,x+cursor_pos)
+ ch = window.getch
+ case ch
+ when Ncurses::KEY_LEFT
+ cursor_pos = [0, cursor_pos-1].max
+ when Ncurses::KEY_RIGHT
+ # similar, implement yourself !
+ when Ncurses::KEY_ENTER, ?\n, ?\r
+ return string, cursor_pos, ch # Which return key has been used?
+ when Ncurses::KEY_BACKSPACE
+ string = string[0...([0, cursor_pos-1].max)] + string[cursor_pos..-1]
+ cursor_pos = [0, cursor_pos-1].max
+ window.mvaddstr(y, x+string.length, " ")
+ # when etc...
+ when " "[0]..255 # remaining printables
+ if (cursor_pos < max_len)
+ string[cursor_pos,0] = ch.chr
+ cursor_pos += 1
+ else
+ Ncurses.beep
+ end
+ else
+ Ncurses.beep
+ end
+ end
+end
+
+if (__FILE__ == $0) then begin
+ # demo mode
+ Ncurses.initscr
+ Ncurses.cbreak
+ Ncurses.noecho
+
+ # recognize KEY_ENTER, KEY_BACKSPACE etc
+ Ncurses.keypad(Ncurses.stdscr, true)
+
+ y = 10
+ x = 2
+ prompt = "Hallo > "
+ Ncurses.mvaddstr(y,x, prompt)
+ s = read_line(y, x + prompt.length)
+
+ensure
+ Ncurses.endwin
+end end
+p s
diff --git a/examples/tclock.rb b/examples/tclock.rb
@@ -0,0 +1,227 @@
+#!/usr/bin/env ruby
+
+# $Id: tclock.rb,v 1.6 2002/02/28 13:50:10 t-peters Exp $
+
+# tclock - analog/digital clock for curses, translated to ruby
+# Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
+# This file was adapted from the C program tclock.c from the ncurses
+# distribution, which bears the following copyright statement:
+
+# tclock - analog/digital clock for curses.
+# If it gives you joy, then
+# (a) I'm glad
+# (b) you need to get out more :-)
+#
+# This program is copyright Howard Jones, September 1994
+# (ha.jones@ic.ac.uk). It may be freely distributed as
+# long as this copyright message remains intact, and any
+# modifications are clearly marked as such. [In fact, if
+# you modify it, I wouldn't mind the modifications back,
+# especially if they add any nice features. A good one
+# would be a precalc table for the 60 hand positions, so
+# that the floating point stuff can be ditched. As I said,
+# it was a 20 hackup minute job.]
+#
+# COMING SOON: tfishtank. Be the envy of your mac-owning
+# colleagues.
+
+###########################################################################
+# The translation of this program to ruby is a modification and is hereby #
+# clearly marked as such. #
+###########################################################################
+
+require "ncurses"
+PI = Math::PI
+
+def sign(_x)
+ (_x<0?-1:1)
+end
+
+ASPECT = 2.2
+
+def a2x(angle,radius)
+ (ASPECT * radius * Math::sin(angle)).round
+end
+def a2y(angle,radius)
+ (radius * Math::cos(angle)).round
+end
+
+# Plot a point
+def plot(x, y, c)
+ Ncurses.mvaddch(y, x, c[0])
+end
+
+# Draw a diagonal(arbitrary) line using Bresenham's alogrithm.
+def dline(pair, from_x, from_y, x2, y2, ch)
+ if (Ncurses.has_colors?)
+ Ncurses.attrset(Ncurses.COLOR_PAIR(pair))
+ end
+
+ dx = x2 - from_x;
+ dy = y2 - from_y;
+
+ ax = (dx * 2).abs
+ ay = (dy * 2).abs
+
+ sx = sign(dx);
+ sy = sign(dy);
+
+ x = from_x;
+ y = from_y;
+
+ if (ax > ay)
+ d = ay - (ax / 2);
+
+ while (1)
+ plot(x, y, ch);
+ if (x == x2)
+ return nil
+ end
+ if (d >= 0)
+ y += sy;
+ d -= ax;
+ end
+ x += sx;
+ d += ay;
+ end
+ else
+ d = ax - (ay / 2);
+
+ while (1)
+ plot(x, y, ch);
+ if (y == y2)
+ return nil;
+ end
+ if (d >= 0)
+ x += sx;
+ d -= ay;
+ end
+ y += sy;
+ d += ax;
+ end
+ end
+end
+
+begin
+ # int i, cx, cy;
+ # double mradius, hradius, mangle, hangle;
+ # double sangle, sradius, hours;
+ # int hdx, hdy;
+ # int mdx, mdy;
+ # int sdx, sdy;
+ # int ch;
+
+
+ lastbeep = -1;
+ my_bg = Ncurses::COLOR_BLACK;
+
+ Ncurses::initscr();
+ Ncurses::noecho();
+ Ncurses::cbreak();
+ Ncurses::nodelay(Ncurses::stdscr, TRUE);
+ Ncurses::curs_set(0);
+
+ if (Ncurses::has_colors?())
+ Ncurses::start_color();
+
+ Ncurses::init_pair(1, Ncurses::COLOR_RED, my_bg);
+ Ncurses::init_pair(2, Ncurses::COLOR_MAGENTA, my_bg);
+ Ncurses::init_pair(3, Ncurses::COLOR_GREEN, my_bg);
+ end
+ Ncurses::keypad(Ncurses::stdscr, TRUE);
+
+ while (:restart)
+ cx = (Ncurses.COLS - 1) / 2; #/* 39 */
+ cy = Ncurses.LINES / 2; #/* 12 */
+ ch = (cx > cy) ? cy : cx; #/* usually cy */
+ mradius = ((3 * cy) / 4).to_f; #/* 9 */
+ hradius = (cy / 2).to_f; #/* 6 */
+ sradius = ((2 * cy) / 3).to_f; #/* 8 */
+
+ for i in (0...12)
+ sangle = (i + 1) * (2.0 * PI) / 12.0;
+ sradius = ((5 * cy) / 6).to_f; #/* 10 */
+ sdx = a2x(sangle, sradius);
+ sdy = a2y(sangle, sradius);
+ szChar = sprintf("%d", i + 1);
+
+ Ncurses::mvaddstr(cy - sdy, cx + sdx, szChar);
+ end
+
+ Ncurses::mvaddstr(0, 0,
+ "ASCII Clock by Howard Jones (ha.jones@ic.ac.uk),1994");
+
+ sradius -=2
+ sradius = 1 if sradius < 1
+ window_size_changed = false
+ while (window_size_changed == false)
+ sleep(0.100);
+
+ hours = Time.now.hour + Time.now.min / 60.0;
+ if (hours > 12.0)
+ hours -= 12.0;
+ end
+
+ mangle = Time.now.min * (2 * PI) / 60.0;
+ mdx = a2x(mangle, mradius);
+ mdy = a2y(mangle, mradius);
+
+ hangle = ((hours) * (2.0 * PI) / 12.0);
+ hdx = a2x(hangle, hradius);
+ hdy = a2y(hangle, hradius);
+
+ sangle = ((Time.now.sec) * (2.0 * PI) / 60.0);
+ sdx = a2x(sangle, sradius);
+ sdy = a2y(sangle, sradius);
+
+ dline(3, cx, cy, cx + mdx, cy - mdy, '#');
+
+ Ncurses::attrset(Ncurses::A_REVERSE);
+ dline(2, cx, cy, cx + hdx, cy - hdy, '.');
+ Ncurses::attroff(Ncurses::A_REVERSE);
+
+ if (Ncurses::has_colors?())
+ Ncurses::attrset(Ncurses::COLOR_PAIR(1));
+ end
+ plot(cx + sdx, cy - sdy, 'O');
+
+ if (Ncurses::has_colors?())
+ Ncurses::attrset(Ncurses::COLOR_PAIR(0));
+ end
+ Ncurses::mvaddstr(Ncurses.LINES - 2, 0, Time.now.to_s);
+ Ncurses::refresh();
+ if ((Time.now.sec % 5) == 0 &&
+ Time.now.sec != lastbeep)
+ lastbeep = Time.now.sec;
+ Ncurses::beep();
+ end
+
+ if ((ch = Ncurses::getch()) != Ncurses::ERR)
+ if (ch == Ncurses::KEY_RESIZE)
+ Ncurses::erase();
+ window_size_changed = true;
+ else
+ break;
+ end
+ end
+
+ plot(cx + sdx, cy - sdy, ' ');
+ dline(0, cx, cy, cx + hdx, cy - hdy, ' ');
+ dline(0, cx, cy, cx + mdx, cy - mdy, ' ');
+
+ end
+
+ if ! window_size_changed
+ $stderr.puts "! window_size_changed"
+ break
+ end
+ end
+ensure
+ Ncurses::curs_set(1);
+ Ncurses::endwin();
+end
+
+
+
+
+
diff --git a/examples/test_scanw.rb b/examples/test_scanw.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+# $Id: test_scanw.rb,v 1.1 2003/03/22 22:55:00 t-peters Exp $
+#
+# Test of the scanw function. Should really not be used in any serious curses
+# program. To use it, install scanf for ruby.
+
+# Copyright (C) 2003 Tobias Peters <t-peters@users.berlios.de>
+#
+# No warranties. Share and enjoy.
+
+require "ncurses"
+begin
+ Ncurses.initscr
+ Ncurses.mvaddstr(4, 19, "Give me a number: ")
+ Ncurses.refresh
+ num = []
+ Ncurses.scanw("%d", num)
+
+ Ncurses.mvprintw(6, 19, "You gave: %d", num[0])
+ Ncurses.refresh
+ sleep 1
+ensure
+ Ncurses.endwin
+end
+
+puts("You gave: #{num[0]}")
diff --git a/extconf.rb b/extconf.rb
@@ -0,0 +1,137 @@
+#!/usr/bin/env ruby
+
+# ncurses-ruby is a ruby module for accessing the FSF's ncurses library
+# (C) 2002, 2004 Tobias Peters <t-peters@users.berlios.de>
+# (C) 2005, 2009 Tobias Herzke
+#
+# This module is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+# $Id: extconf.rb,v 1.14 2009/05/03 14:13:27 t-peters Exp $
+
+require "mkmf"
+
+$CFLAGS += " -g"
+$CXXFLAGS = $CFLAGS
+
+have_header("unistd.h")
+have_header("locale.h")
+
+if have_header("ncurses.h")
+ curses_header = "ncurses.h"
+elsif have_header("ncurses/curses.h")
+ curses_header = "ncurses/curses.h"
+elsif have_header("curses.h")
+ curses_header = "curses.h"
+else
+ raise "ncurses header file not found"
+end
+
+if have_library("ncurses", "wmove")
+ curses_lib = "ncurses"
+elsif have_library("pdcurses", "wmove")
+ curses_lib = "pdcurses"
+else
+ raise "ncurses library not found"
+end
+
+have_func("newscr")
+have_func("TABSIZE")
+have_func("ESCDELAY")
+have_func("keybound")
+have_func("curses_version")
+have_func("tigetstr")
+have_func("getwin")
+have_func("putwin")
+have_func("ungetmouse")
+have_func("mousemask")
+have_func("wenclose")
+have_func("mouseinterval")
+have_func("wmouse_trafo")
+have_func("mcprint")
+have_func("has_key")
+
+have_func("delscreen")
+have_func("define_key")
+have_func("keyok")
+have_func("resizeterm")
+have_func("use_default_colors")
+have_func("use_extended_names")
+have_func("wresize")
+have_func("attr_on")
+have_func("attr_off")
+have_func("attr_set")
+have_func("chgat")
+have_func("color_set")
+have_func("filter")
+have_func("intrflush")
+have_func("mvchgat")
+have_func("mvhline")
+have_func("mvvline")
+have_func("mvwchgat")
+have_func("mvwhline")
+have_func("mvwvline")
+have_func("noqiflush")
+have_func("putp")
+have_func("qiflush")
+have_func("scr_dump")
+have_func("scr_init")
+have_func("scr_restore")
+have_func("scr_set")
+have_func("slk_attr_off")
+have_func("slk_attr_on")
+have_func("slk_attr")
+have_func("slk_attr_set")
+have_func("slk_color")
+have_func("tigetflag")
+have_func("tigetnum")
+have_func("use_env")
+have_func("vidattr")
+have_func("vid_attr")
+have_func("wattr_on")
+have_func("wattr_off")
+have_func("wattr_set")
+have_func("wchgat")
+have_func("wcolor_set")
+have_func("getattrs")
+
+puts "checking which debugging functions to wrap..."
+have_func("_tracef")
+have_func("_tracedump")
+have_func("_nc_tracebits")
+have_func("_traceattr")
+have_func("_traceattr2")
+have_func("_tracechar")
+have_func("_tracechtype")
+have_func("_tracechtype2")
+have_func("_tracemouse")
+
+puts "checking for other functions that appeared after ncurses version 5.0..."
+have_func("assume_default_colors")
+have_func("attr_get")
+
+puts "checking for the panel library..."
+if have_header("panel.h")
+ have_library("panel", "panel_hidden")
+end
+puts "checking for the form library..."
+if have_header("form.h")
+ have_library("form", "new_form")
+end
+puts "checking for the menu library..."
+if have_header("menu.h")
+ have_library("menu", "new_menu")
+end
+
+create_makefile('ncurses_bin')
diff --git a/form_wrap.c b/form_wrap.c
@@ -0,0 +1,1449 @@
+/*
+ * This is a curses forms wrapper as part of ncurses-ruby
+ * Contributed by Simon Kaczor <skaczor@cox.net>
+ * Prognosoft Inc. <http://www.prognosoft.biz>
+ * Copyright 2004
+ *
+ * Changes:
+ * (C) 2004 Tobias Peters
+ * (C) 2005 2009 Tobias Herzke
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#ifdef HAVE_FORM_H
+
+#include "form_wrap.h"
+#include "ncurses_wrap.h"
+
+VALUE mForm;
+VALUE cFIELD;
+VALUE cFIELDTYPE;
+VALUE cFORM;
+
+void init_err_codes()
+{
+ /* The routine succeeded. */
+ FORM_DEF_CONST(E_OK);
+ /* The field is already connected to a form. */
+ FORM_DEF_CONST(E_CONNECTED);
+ /* System error occurred (see errno). */
+ FORM_DEF_CONST(E_SYSTEM_ERROR);
+ /* Routine detected an incorrect or out-of-range argument. */
+ FORM_DEF_CONST(E_BAD_ARGUMENT);
+ /* The form is already posted. */
+ FORM_DEF_CONST(E_POSTED);
+ /* Routine was called from an initialization or termination function. */
+ FORM_DEF_CONST(E_BAD_STATE);
+ /* Form is too large for its window. */
+ FORM_DEF_CONST(E_NO_ROOM);
+ /* The form has not been posted. */
+ FORM_DEF_CONST(E_NOT_POSTED);
+ /* The form driver code saw an unknown request code. */
+ FORM_DEF_CONST(E_UNKNOWN_COMMAND);
+ /* Contents of a field are not valid. */
+ FORM_DEF_CONST(E_INVALID_FIELD);
+ /* No fields are connected to the form. */
+ FORM_DEF_CONST(E_NOT_CONNECTED);
+ /* The form driver could not process the request.} */
+ FORM_DEF_CONST(E_REQUEST_DENIED);
+}
+
+/*
+ * Form driver request characters listed in form_driver(3x) man page
+ */
+void init_req_constants() {
+ /* Move to the next page */
+ FORM_DEF_CONST(REQ_NEXT_PAGE);
+ /* Move to the previous page. */
+ FORM_DEF_CONST(REQ_PREV_PAGE);
+ /* Move to the first page. */
+ FORM_DEF_CONST(REQ_FIRST_PAGE);
+ /* Move to the last field. */
+ FORM_DEF_CONST(REQ_LAST_PAGE);
+ /* Move to the next field. */
+ FORM_DEF_CONST(REQ_NEXT_FIELD);
+ /* Move to the previous field. */
+ FORM_DEF_CONST(REQ_PREV_FIELD);
+ /* Move to the first field. */
+ FORM_DEF_CONST(REQ_FIRST_FIELD);
+ /* Move to the last field. */
+ FORM_DEF_CONST(REQ_LAST_FIELD);
+ /* Move to the sorted next field. */
+ FORM_DEF_CONST(REQ_SNEXT_FIELD);
+ /* Move to the sorted previous field. */
+ FORM_DEF_CONST(REQ_SPREV_FIELD);
+ /* Move to the sorted first field. */
+ FORM_DEF_CONST(REQ_SFIRST_FIELD);
+ /* Move to the sorted last field. */
+ FORM_DEF_CONST(REQ_SLAST_FIELD);
+ /* Move left to a field. */
+ FORM_DEF_CONST(REQ_LEFT_FIELD);
+ /* Move right to a field. */
+ FORM_DEF_CONST(REQ_RIGHT_FIELD);
+ /* Move up to a field. */
+ FORM_DEF_CONST(REQ_UP_FIELD);
+ /* Move down to a field. */
+ FORM_DEF_CONST(REQ_DOWN_FIELD);
+ /* Move to the next char. */
+ FORM_DEF_CONST(REQ_NEXT_CHAR);
+ /* Move to the previous char. */
+ FORM_DEF_CONST(REQ_PREV_CHAR);
+ /* Move to the next line. */
+ FORM_DEF_CONST(REQ_NEXT_LINE);
+ /* Move to the previous line. */
+ FORM_DEF_CONST(REQ_PREV_LINE);
+ /* Move to the next word. */
+ FORM_DEF_CONST(REQ_NEXT_WORD);
+ /* Move to the previous word. */
+ FORM_DEF_CONST(REQ_PREV_WORD);
+ /* Move to the beginning of the field. */
+ FORM_DEF_CONST(REQ_BEG_FIELD);
+ /* Move to the end of the field. */
+ FORM_DEF_CONST(REQ_END_FIELD);
+ /* Move to the beginning of the line. */
+ FORM_DEF_CONST(REQ_BEG_LINE);
+ /* Move to the end of the line. */
+ FORM_DEF_CONST(REQ_END_LINE);
+ /* Move left in the field. */
+ FORM_DEF_CONST(REQ_LEFT_CHAR);
+ /* Move right in the field. */
+ FORM_DEF_CONST(REQ_RIGHT_CHAR);
+ /* Move up in the field. */
+ FORM_DEF_CONST(REQ_UP_CHAR);
+ /* Move down in the field. */
+ FORM_DEF_CONST(REQ_DOWN_CHAR);
+ /* Insert or overlay a new line. */
+ FORM_DEF_CONST(REQ_NEW_LINE);
+ /* Insert a blank at the cursor. */
+ FORM_DEF_CONST(REQ_INS_CHAR);
+ /* Insert a blank line at the cursor. */
+ FORM_DEF_CONST(REQ_INS_LINE);
+ /* Delete character at the cursor. */
+ FORM_DEF_CONST(REQ_DEL_CHAR);
+ /* Delete character before the cursor. */
+ FORM_DEF_CONST(REQ_DEL_PREV);
+ /* Delete line at the cursor. */
+ FORM_DEF_CONST(REQ_DEL_LINE);
+ /* Delete blank-delimited word at the cursor. */
+ FORM_DEF_CONST(REQ_DEL_WORD);
+ /* Clear to end of line from cursor. */
+ FORM_DEF_CONST(REQ_CLR_EOL);
+ /* Clear to end of field from cursor. */
+ FORM_DEF_CONST(REQ_CLR_EOF);
+ /* Clear the entire field. */
+ FORM_DEF_CONST(REQ_CLR_FIELD);
+ /* Enter overlay mode. */
+ FORM_DEF_CONST(REQ_OVL_MODE);
+ /* Enter insert mode. */
+ FORM_DEF_CONST(REQ_INS_MODE);
+ /* Scroll the field forward a line. */
+ FORM_DEF_CONST(REQ_SCR_FLINE);
+ /* Scroll the field backward a line. */
+ FORM_DEF_CONST(REQ_SCR_BLINE);
+ /* Scroll the field forward a page. */
+ FORM_DEF_CONST(REQ_SCR_FPAGE);
+ /* Scroll the field backward a page. */
+ FORM_DEF_CONST(REQ_SCR_BPAGE);
+ /* Scroll the field forward half a page. */
+ FORM_DEF_CONST(REQ_SCR_FHPAGE);
+ /* Scroll the field backward half a page. */
+ FORM_DEF_CONST(REQ_SCR_BHPAGE);
+ /* Scroll the field forward a character. */
+ FORM_DEF_CONST(REQ_SCR_FCHAR);
+ /* Scroll the field backward a character. */
+ FORM_DEF_CONST(REQ_SCR_BCHAR);
+ /* Horizontal scroll the field forward a line. */
+ FORM_DEF_CONST(REQ_SCR_HFLINE);
+ /* Horizontal scroll the field backward a line. */
+ FORM_DEF_CONST(REQ_SCR_HBLINE);
+ /* Horizontal scroll the field forward half a line. */
+ FORM_DEF_CONST(REQ_SCR_HFHALF);
+ /* Horizontal scroll the field backward half a line. */
+ FORM_DEF_CONST(REQ_SCR_HBHALF);
+ /* Validate field. */
+ FORM_DEF_CONST(REQ_VALIDATION);
+ /* Display next field choice. */
+ FORM_DEF_CONST(REQ_NEXT_CHOICE);
+ /* Display previous field choice. */
+ FORM_DEF_CONST(REQ_PREV_CHOICE);
+}
+
+/*
+ * field justification constants
+ */
+void init_just_constants() {
+ FORM_DEF_CONST(NO_JUSTIFICATION);
+ FORM_DEF_CONST(JUSTIFY_RIGHT);
+ FORM_DEF_CONST(JUSTIFY_LEFT);
+ FORM_DEF_CONST(JUSTIFY_CENTER);
+}
+
+/*
+ * field options constants
+ */
+void init_opts_constants() {
+ FORM_DEF_CONST(O_VISIBLE);
+ FORM_DEF_CONST(O_ACTIVE);
+ FORM_DEF_CONST(O_PUBLIC);
+ FORM_DEF_CONST(O_EDIT);
+ FORM_DEF_CONST(O_WRAP);
+ FORM_DEF_CONST(O_BLANK);
+ FORM_DEF_CONST(O_AUTOSKIP);
+ FORM_DEF_CONST(O_NULLOK);
+ FORM_DEF_CONST(O_STATIC);
+ FORM_DEF_CONST(O_PASSOK);
+}
+
+void init_form_opts_constants() {
+ FORM_DEF_CONST(O_NL_OVERLOAD);
+ FORM_DEF_CONST(O_BS_OVERLOAD);
+}
+
+/*
+ * _PAGE wrapper
+ */
+/* static VALUE wrap_page(_PAGE* page) */
+/* { */
+/* if (page == 0) return Qnil; */
+/* { */
+/* VALUE pages_hash = rb_iv_get(mForm, "@pages_hash"); */
+/* VALUE page_adress = INT2NUM((long)(page)); */
+/* VALUE rb_page = rb_hash_aref(pages_hash, page_adress); */
+/* if (rb_page == Qnil) { */
+/* rb_page = Data_Wrap_Struct(cPAGE, 0, 0, page); */
+/* rb_iv_set(rb_page, "@destroyed", Qfalse); */
+/* rb_hash_aset(pages_hash, page_adress, rb_page); */
+/* } */
+/* return rb_page; */
+/* } */
+/* } */
+/* static _PAGE* get_page(VALUE rb_page) */
+/* { */
+/* _PAGE* page; */
+/* if (rb_page == Qnil) return 0; */
+/* if (rb_iv_get(rb_page, "@destroyed") == Qtrue) { */
+/* rb_raise(rb_eRuntimeError, "Attempt to access a destroyed page"); */
+/* return 0; */
+/* } */
+/* Data_Get_Struct(rb_page, _PAGE, page); */
+/* return page; */
+/* } */
+
+/*
+ * FIELD wrapper
+ */
+static VALUE wrap_field(FIELD* field)
+{
+ if (field == 0) return Qnil;
+ {
+ VALUE fields_hash = rb_iv_get(mForm, "@fields_hash");
+ VALUE field_adress = INT2NUM((long)(field));
+ VALUE rb_field = rb_hash_aref(fields_hash, field_adress);
+ if (rb_field == Qnil) {
+ rb_field = Data_Wrap_Struct(cFIELD, 0, 0, field);
+ rb_iv_set(rb_field, "@destroyed", Qfalse);
+ rb_hash_aset(fields_hash, field_adress, rb_field);
+ }
+ return rb_field;
+ }
+}
+static FIELD* get_field(VALUE rb_field)
+{
+ FIELD* field;
+ if (rb_field == Qnil) return 0;
+ if (rb_iv_get(rb_field, "@destroyed") == Qtrue) {
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed field");
+ return 0;
+ }
+ Data_Get_Struct(rb_field, FIELD, field);
+ return field;
+}
+
+/*
+ * FIELDTYPE wrapper
+ */
+static VALUE wrap_fieldtype(FIELDTYPE* fieldtype)
+{
+ if (fieldtype == NULL) return Qnil;
+ {
+ VALUE fieldtypes_hash = rb_iv_get(mForm, "@fieldtypes_hash");
+ VALUE fieldtype_adress = INT2NUM((long)(fieldtype));
+ VALUE rb_fieldtype = rb_hash_aref(fieldtypes_hash, fieldtype_adress);
+ if (rb_fieldtype == Qnil) {
+ rb_fieldtype = Data_Wrap_Struct(cFIELDTYPE, 0, 0, fieldtype);
+ rb_iv_set(rb_fieldtype, "@destroyed", Qfalse);
+ rb_hash_aset(fieldtypes_hash, fieldtype_adress, rb_fieldtype);
+ }
+ return rb_fieldtype;
+ }
+}
+static FIELDTYPE* get_fieldtype(VALUE rb_fieldtype)
+{
+ FIELDTYPE* fieldtype;
+ if (rb_fieldtype == Qnil) return 0;
+ if (rb_iv_get(rb_fieldtype, "@destroyed") == Qtrue) {
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed fieldtype");
+ return 0;
+ }
+ Data_Get_Struct(rb_fieldtype, FIELDTYPE, fieldtype);
+ return fieldtype;
+}
+
+/*
+ * FORM wrapper
+ */
+static VALUE wrap_form(FORM* form)
+{
+ if (form == 0) return Qnil;
+ {
+ VALUE forms_hash = rb_iv_get(mForm, "@forms_hash");
+ VALUE form_adress = INT2NUM((long)(form));
+ VALUE rb_form = rb_hash_aref(forms_hash, form_adress);
+ if (rb_form == Qnil) {
+ rb_form = Data_Wrap_Struct(cFORM, 0, 0, form);
+ rb_iv_set(rb_form, "@destroyed", Qfalse);
+ rb_hash_aset(forms_hash, form_adress, rb_form);
+ }
+ return rb_form;
+ }
+}
+static FORM* get_form(VALUE rb_form)
+{
+ FORM* form;
+ if (rb_form == Qnil) return 0;
+ if (rb_iv_get(rb_form, "@destroyed") == Qtrue) {
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed form");
+ return 0;
+ }
+ Data_Get_Struct(rb_form, FORM, form);
+ return form;
+}
+
+/*
+ * Proc objects are registered using hashes (one for each type of hook)
+ * The key in the hash is the address of the ncurses "object" and the value is
+ * the Proc object.
+ */
+#define FIELD_INIT_HOOK 0
+#define FIELD_TERM_HOOK 1
+#define FORM_INIT_HOOK 2
+#define FORM_TERM_HOOK 3
+#define FIELDTYPE_FIELD_CHECK_HOOK 4
+#define FIELDTYPE_CHAR_CHECK_HOOK 5
+#define FIELDTYPE_NEXT_CHOICE_HOOK 6
+#define FIELDTYPE_PREV_CHOICE_HOOK 7
+#define FIELDTYPE_ARGS 8
+#define PROC_HASHES_COUNT 9
+static VALUE get_proc_hash(int hook) {
+ VALUE arr = rb_iv_get(mForm, "@proc_hashes");
+ VALUE hash = rb_ary_entry(arr, (long)hook);
+ if (hash == Qnil) {
+ rb_raise(rb_eRuntimeError, "Invalid proc hash.");
+ }
+ return hash;
+}
+
+/*
+ * Returns an existing Ruby Proc for a given owning "object" and hook type.
+ * Qnil will be returned if no Proc was associated with the owner
+ */
+static VALUE get_proc(void* owner, int hook) {
+ if (owner == 0) return Qnil;
+ {
+ VALUE owner_adress = INT2NUM((long)(owner));
+ VALUE proc_hash = get_proc_hash(hook);
+ VALUE proc = rb_hash_aref(proc_hash, owner_adress);
+ return proc;
+ }
+}
+/*
+ * Registers the Proc object with a given owner "object" and hook type.
+ * If proc is Qnil, the hook is unregistered instead.
+ */
+static void reg_proc(void* owner, int hook, VALUE proc) {
+ if (owner == NULL) return;
+ {
+ VALUE proc_hash = get_proc_hash(hook);
+ VALUE owner_address = INT2NUM((long)(owner));
+ if (proc == Qnil) {
+ rb_hash_delete(proc_hash, owner_address);
+ }
+ else {
+ rb_hash_aset(proc_hash, owner_address, proc);
+ }
+ }
+}
+
+/*
+ * Form creation/destruction functions
+ */
+static VALUE rbncurs_m_new_form(VALUE dummy, VALUE rb_field_array)
+{
+ long n = rbncurs_array_length(rb_field_array);
+ /* Will ncurses free this array? If not, must do it after calling free_form(). */
+ FIELD** fields = ALLOC_N(FIELD*, (n+1));
+ long i;
+ for (i=0; i<n; i++){
+ fields[i] = get_field(rb_ary_entry(rb_field_array, i));
+ }
+ fields[n] = NULL;
+ return wrap_form(new_form(fields));
+}
+
+static VALUE rbncurs_c_free_form(VALUE rb_form) {
+ VALUE forms_hash = rb_iv_get(mForm, "@forms_hash");
+ FORM* form = get_form(rb_form);
+ VALUE form_adress = INT2NUM((long)(form));
+ rb_funcall(forms_hash, rb_intern("delete"), 1, form_adress);
+ rb_iv_set(rb_form, "@destroyed", Qtrue);
+ return INT2NUM(free_form(form));
+}
+static VALUE rbncurs_m_free_form(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_free_form(rb_form); }
+
+/*
+ * form_post
+ */
+static VALUE rbncurs_c_post_form(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(post_form(form));
+}
+static VALUE rbncurs_m_post_form(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_post_form(rb_form); }
+
+static VALUE rbncurs_c_unpost_form(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(unpost_form(form));
+}
+static VALUE rbncurs_m_unpost_form(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_unpost_form(rb_form); }
+
+/*
+ * Form driver
+ */
+static VALUE rbncurs_c_form_driver(VALUE rb_form, VALUE c) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(form_driver(form, NUM2INT(c)));
+}
+static VALUE rbncurs_m_form_driver(VALUE dummy, VALUE rb_form, VALUE c)
+{ return rbncurs_c_form_driver(rb_form, c); }
+
+/*
+ * form_page(3x)
+ */
+static VALUE rbncurs_c_set_current_field(VALUE rb_form, VALUE rb_field) {
+ FORM* form = get_form(rb_form);
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_current_field(form, field));
+}
+static VALUE rbncurs_m_set_current_field(VALUE dummy, VALUE rb_form, VALUE rb_field)
+{ return rbncurs_c_set_current_field(rb_form, rb_field); }
+
+static VALUE rbncurs_c_current_field(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return wrap_field(current_field(form));
+}
+static VALUE rbncurs_m_current_field(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_current_field(rb_form); }
+
+static VALUE rbncurs_c_set_form_page(VALUE rb_form, VALUE n) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(set_form_page(form, NUM2INT(n)));
+}
+static VALUE rbncurs_m_set_form_page(VALUE dummy, VALUE rb_form, VALUE n)
+{ return rbncurs_c_set_form_page(rb_form, n); }
+
+static VALUE rbncurs_c_form_page(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(form_page(form));
+}
+static VALUE rbncurs_m_form_page(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_page(rb_form); }
+
+static VALUE rbncurs_c_field_index(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(field_index(field));
+}
+static VALUE rbncurs_m_field_index(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_index(rb_field); }
+
+/*
+ * form_data(3x)
+ */
+static VALUE rbncurs_c_data_ahead(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return (data_ahead(form)) ? Qtrue: Qfalse;
+}
+static VALUE rbncurs_m_data_ahead(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_data_ahead(rb_form); }
+
+static VALUE rbncurs_c_data_behind(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return (data_behind(form)) ? Qtrue: Qfalse;
+}
+static VALUE rbncurs_m_data_behind(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_data_behind(rb_form); }
+
+
+
+/*
+ * Field functions (form_field_new(3x))
+ */
+static VALUE rbncurs_m_new_field(VALUE dummy,
+ VALUE height, VALUE width,
+ VALUE toprow, VALUE leftcol,
+ VALUE offscreen, VALUE nbuffers) {
+ return wrap_field(new_field(NUM2INT(height), NUM2INT(width),
+ NUM2INT(toprow), NUM2INT(leftcol),
+ NUM2INT(offscreen), NUM2INT(nbuffers)));
+}
+
+static VALUE rbncurs_c_dup_field(VALUE rb_field, VALUE toprow, VALUE leftcol) {
+ FIELD* field = get_field(rb_field);
+ return wrap_field(dup_field(field, NUM2INT(toprow),NUM2INT(leftcol)));
+}
+static VALUE rbncurs_m_dup_field(VALUE dummy, VALUE rb_field, VALUE toprow, VALUE leftcol)
+{ return rbncurs_c_dup_field(rb_field, toprow, leftcol); }
+
+static VALUE rbncurs_c_link_field(VALUE rb_field, VALUE toprow, VALUE leftcol) {
+ FIELD* field = get_field(rb_field);
+ return wrap_field(link_field(field, NUM2INT(toprow),NUM2INT(leftcol)));
+}
+static VALUE rbncurs_m_link_field(VALUE dummy, VALUE rb_field, VALUE toprow, VALUE leftcol)
+{ return rbncurs_c_link_field(rb_field, toprow, leftcol); }
+
+static VALUE rbncurs_c_free_field(VALUE rb_field) {
+ VALUE fields_hash = rb_iv_get(mForm, "@fields_hash");
+ FIELD* field = get_field(rb_field);
+ VALUE field_adress = INT2NUM((long)(field));
+ rb_funcall(fields_hash, rb_intern("delete"), 1, field_adress);
+ rb_iv_set(rb_field, "@destroyed", Qtrue);
+ return INT2NUM(free_field(field));
+}
+static VALUE rbncurs_m_free_field(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_free_field(rb_field); }
+
+
+/*
+ * form_field_info(3x)
+ */
+static VALUE rbncurs_c_field_info(VALUE rb_field, VALUE rows, VALUE cols,
+ VALUE frow, VALUE fcol, VALUE nrow, VALUE nbuf) {
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(cols, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(frow, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(fcol, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(nrow, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(nbuf, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "rows, cols, frow, fcol, nrow and nbuf arguments must be empty Arrays");
+ return Qnil;
+ }
+ else {
+ FIELD* field = get_field(rb_field);
+ int vals[6] = {0,0,0,0,0,0};
+
+ int result = field_info(field, &vals[0],&vals[1],&vals[2],&vals[3],&vals[4],&vals[5]);
+ rb_ary_push(rows, INT2NUM(vals[0]));
+ rb_ary_push(cols, INT2NUM(vals[1]));
+ rb_ary_push(frow, INT2NUM(vals[2]));
+ rb_ary_push(fcol, INT2NUM(vals[3]));
+ rb_ary_push(nrow, INT2NUM(vals[4]));
+ rb_ary_push(nbuf, INT2NUM(vals[5]));
+ return INT2NUM(result);
+ }
+}
+static VALUE rbncurs_m_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
+ VALUE frow, VALUE fcol, VALUE nrow, VALUE nbuf)
+{ return rbncurs_c_field_info(rb_field, rows, cols, frow, fcol, nrow, nbuf); }
+
+static VALUE rbncurs_c_dynamic_field_info(VALUE rb_field, VALUE rows, VALUE cols,
+ VALUE max) {
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(cols, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(max, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "rows, cols and max arguments must be empty Arrays");
+ return Qnil;
+ }
+ else {
+ FIELD* field = get_field(rb_field);
+ int vals[3] = {0,0,0};
+
+ int result = dynamic_field_info(field, &vals[0],&vals[1],&vals[2]);
+ rb_ary_push(rows, INT2NUM(vals[0]));
+ rb_ary_push(cols, INT2NUM(vals[1]));
+ rb_ary_push(max, INT2NUM(vals[2]));
+ return INT2NUM(result);
+ }
+}
+static VALUE rbncurs_m_dynamic_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
+ VALUE max)
+{ return rbncurs_c_dynamic_field_info(rb_field, rows, cols, max); }
+/*
+ * field_validation
+ */
+static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
+ VALUE rb_fieldtype, arg3, arg4, arg5;
+ FIELD* field = get_field(rb_field);
+ FIELDTYPE* ftype = NULL;
+
+ rb_scan_args(argc, argv, "13", &rb_fieldtype, &arg3, &arg4, &arg5);
+ ftype = get_fieldtype(rb_fieldtype);
+
+ if (ftype == TYPE_ALNUM ||
+ ftype == TYPE_ALPHA) {
+ if (argc != 2)
+ rb_raise(rb_eArgError, "TYPE_ALNUM and TYPE_ALPHA require one additional argument");
+ return INT2NUM(set_field_type(field, ftype,
+ NUM2INT(arg3)));
+ }
+ if (ftype == TYPE_ENUM) {
+ if (argc != 4) {
+ rb_raise(rb_eArgError, "TYPE_ENUM requires three additional arguments");
+ }
+ else {
+ int n = rbncurs_array_length(arg3);
+ /* Will ncurses free this array of strings in free_field()? */
+ char** list = ALLOC_N(char*, n+1);
+ int i;
+ for (i = 0; i < n; i++) {
+ list[i] = STR2CSTR(rb_ary_entry(arg3, (long)i));
+ }
+ list[n] = NULL;
+ return INT2NUM(set_field_type(field, ftype,
+ list,
+ RTEST(arg4),
+ RTEST(arg5)));
+ }
+ }
+ else if (ftype == TYPE_INTEGER) {
+ if (argc != 4)
+ rb_raise(rb_eArgError, "TYPE_INTEGER requires three additional arguments");
+ return INT2NUM(set_field_type(field, ftype,
+ NUM2INT(arg3),
+ NUM2LONG(arg4),
+ NUM2LONG(arg5)));
+ }
+ else if (ftype == TYPE_NUMERIC) {
+ if (argc != 4)
+ rb_raise(rb_eArgError, "TYPE_NUMERIC requires three additional arguments");
+ return INT2NUM(set_field_type(field, ftype,
+ NUM2INT(arg3),
+ NUM2DBL(arg4),
+ NUM2DBL(arg5)));
+ }
+ else if (ftype == TYPE_REGEXP){
+ if (argc != 2)
+ rb_raise(rb_eArgError, "TYPE_REGEXP requires one additional argument");
+ return INT2NUM(set_field_type(field, ftype,
+ STR2CSTR(arg3)));
+ }
+ else if (ftype == TYPE_IPV4){
+ if (argc != 1)
+ rb_raise(rb_eArgError, "TYPE_IPV4 has no additional arguments");
+ return INT2NUM(set_field_type(field, ftype));
+ }
+ else {
+ /* It is a user-defined field type. */
+ /* Will store the arguments associated with this field */
+ /* for use in the callback function. */
+ VALUE rest;
+ rb_scan_args(argc, argv, "1*", &rb_fieldtype, &rest);
+ reg_proc(field, FIELDTYPE_ARGS, rest);
+ /* Pass field as an optional parameter so that make_arg can create */
+ /* the block-argument used in finding the appropriate Ruby Proc */
+ return INT2NUM(set_field_type(field, ftype, field));
+ }
+
+}
+static VALUE rbncurs_m_set_field_type(int argc, VALUE* argv, VALUE dummy)
+{ return rbncurs_c_set_field_type(argc-1, argv+1, argv[0]); }
+
+static VALUE rbncurs_c_field_type(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return wrap_fieldtype(field_type(field));
+}
+static VALUE rbncurs_m_field_type(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_type(rb_field); }
+/* What is this function doing??? */
+static VALUE rbncurs_c_field_arg(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ field_arg(field);
+ return Qfalse;
+}
+static VALUE rbncurs_m_field_arg(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_arg(rb_field); }
+
+/*
+ * field_attributes
+ */
+static VALUE rbncurs_c_set_field_fore(VALUE rb_field, VALUE attr) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_fore(field, NUM2ULONG(attr)));
+}
+static VALUE rbncurs_m_set_field_fore(VALUE dummy, VALUE rb_field, VALUE attr)
+{ return rbncurs_c_set_field_fore(rb_field, attr); }
+
+static VALUE rbncurs_c_field_fore(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return ULONG2NUM(field_fore(field));
+}
+static VALUE rbncurs_m_field_fore(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_fore(rb_field); }
+
+static VALUE rbncurs_c_set_field_back(VALUE rb_field, VALUE attr) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_back(field, NUM2ULONG(attr)));
+}
+static VALUE rbncurs_m_set_field_back(VALUE dummy, VALUE rb_field, VALUE attr)
+{ return rbncurs_c_set_field_back(rb_field, attr); }
+
+static VALUE rbncurs_c_field_back(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return ULONG2NUM(field_back(field));
+}
+static VALUE rbncurs_m_field_back(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_back(rb_field); }
+
+static VALUE rbncurs_c_set_field_pad(VALUE rb_field, VALUE pad) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_pad(field, NUM2INT(pad)));
+}
+static VALUE rbncurs_m_set_field_pad(VALUE dummy, VALUE rb_field, VALUE pad)
+{ return rbncurs_c_set_field_pad(rb_field, pad); }
+
+static VALUE rbncurs_c_field_pad(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(field_pad(field));
+}
+static VALUE rbncurs_m_field_pad(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_pad(rb_field); }
+
+/*
+ * field_buffer
+ */
+static VALUE rbncurs_c_set_field_buffer(VALUE rb_field, VALUE buf, VALUE value) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_buffer(field, NUM2INT(buf), STR2CSTR(value)));
+}
+static VALUE rbncurs_m_set_field_buffer(VALUE dummy, VALUE rb_field, VALUE buf, VALUE value)
+{ return rbncurs_c_set_field_buffer(rb_field, buf, value); }
+
+static VALUE rbncurs_c_field_buffer(VALUE rb_field, VALUE buffer) {
+ FIELD* field = get_field(rb_field);
+ return rb_str_new2(field_buffer(field, NUM2INT(buffer)));
+}
+static VALUE rbncurs_m_field_buffer(VALUE dummy, VALUE rb_field, VALUE buffer)
+{ return rbncurs_c_field_buffer(rb_field, buffer); }
+
+static VALUE rbncurs_c_set_field_status(VALUE rb_field, VALUE status) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_status(field, RTEST(status)));
+}
+static VALUE rbncurs_m_set_field_status(VALUE dummy, VALUE rb_field, VALUE status)
+{ return rbncurs_c_set_field_status(rb_field, status); }
+
+static VALUE rbncurs_c_field_status(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return (field_status(field)) ? Qtrue: Qfalse;
+}
+static VALUE rbncurs_m_field_status(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_status(rb_field); }
+
+static VALUE rbncurs_c_set_max_field(VALUE rb_field, VALUE max) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_max_field(field, NUM2INT(max)));
+}
+static VALUE rbncurs_m_set_max_field(VALUE dummy, VALUE rb_field, VALUE max)
+{ return rbncurs_c_set_max_field(rb_field, max); }
+
+/*
+ * form_field
+ */
+static VALUE rbncurs_c_set_form_fields(VALUE rb_form, VALUE rb_field_array) {
+ long n = rbncurs_array_length(rb_field_array);
+ /* If ncurses does not free memory used by the previous array of strings, */
+ /* we will have to do it now. */
+ FIELD** fields = ALLOC_N(FIELD*, (n+1));
+ long i;
+ FORM* form = NULL;
+ for (i=0; i<n; i++){
+ fields[i] = get_field(rb_ary_entry(rb_field_array, i));
+ }
+ fields[n] = NULL;
+ form = get_form(rb_form);
+ return INT2NUM(set_form_fields(form, fields));
+}
+static VALUE rbncurs_m_set_form_fields(VALUE dummy, VALUE rb_form, VALUE rb_field_array)
+{ return rbncurs_c_set_form_fields(rb_form, rb_field_array); }
+
+static VALUE rbncurs_c_form_fields(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ FIELD** fields = form_fields(form);
+ VALUE arr = Qundef;
+ int i;
+ if (fields == NULL)
+ rb_raise(rb_eRuntimeError, "Error retrieving form fields");
+ arr = rb_ary_new();
+ i=0;
+ while (fields[i] != NULL)
+ {
+ rb_ary_push(arr, wrap_field(fields[i++]));
+ }
+ return arr;
+}
+static VALUE rbncurs_m_form_fields(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_fields(rb_form); }
+
+static VALUE rbncurs_c_field_count(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(field_count(form));
+}
+static VALUE rbncurs_m_field_count(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_field_count(rb_form); }
+
+static VALUE rbncurs_c_move_field(VALUE rb_field, VALUE frow, VALUE fcol) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(move_field(field, NUM2INT(frow), NUM2INT(fcol)));
+}
+static VALUE rbncurs_m_move_field(VALUE dummy, VALUE rb_field, VALUE frow, VALUE fcol)
+{ return rbncurs_c_move_field(rb_field, frow, fcol); }
+
+
+/*
+ * form_hook
+ */
+static void field_init_hook(FORM* form) {
+ /* Find the Proc object associated with this form */
+ VALUE proc = get_proc(form, FIELD_INIT_HOOK);
+ if (proc != Qnil) {
+ VALUE rb_form = wrap_form(form);
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
+ }
+}
+static VALUE rbncurs_c_set_field_init(VALUE rb_form, VALUE proc) {
+ FORM* form = NULL;
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ form = get_form(rb_form);
+ reg_proc(form, FIELD_INIT_HOOK, proc);
+ if (proc != Qnil) {
+ return INT2NUM(set_field_init(form, field_init_hook));
+ }
+ else {
+ return INT2NUM(set_field_init(form, NULL));
+ }
+}
+static VALUE rbncurs_m_set_field_init(VALUE dummy, VALUE rb_form, VALUE proc)
+{ return rbncurs_c_set_field_init(rb_form, proc); }
+
+static VALUE rbncurs_c_field_init(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return get_proc(form, FIELD_INIT_HOOK);
+}
+static VALUE rbncurs_m_field_init(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_field_init(rb_form); }
+
+static void field_term_hook(FORM* form) {
+ /* Find the Proc object associated with this form */
+ VALUE proc = get_proc(form, FIELD_TERM_HOOK);
+ if (proc != Qnil) {
+ VALUE rb_form = wrap_form(form);
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
+ }
+}
+static VALUE rbncurs_c_set_field_term(VALUE rb_form, VALUE proc) {
+ FORM * form = NULL;
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ form = get_form(rb_form);
+ reg_proc(form, FIELD_TERM_HOOK, proc);
+ if (proc != Qnil) {
+ return INT2NUM(set_field_term(form, field_term_hook));
+ }
+ else {
+ return INT2NUM(set_field_term(form, NULL));
+ }
+}
+static VALUE rbncurs_m_set_field_term(VALUE dummy, VALUE rb_form, VALUE proc)
+{ return rbncurs_c_set_field_term(rb_form, proc); }
+
+static VALUE rbncurs_c_field_term(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return get_proc(form, FIELD_TERM_HOOK);
+}
+static VALUE rbncurs_m_field_term(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_field_term(rb_form); }
+
+static void form_init_hook(FORM* form) {
+ /* Find the Proc object associated with this form */
+ VALUE proc = get_proc(form, FORM_INIT_HOOK);
+ if (proc != Qnil) {
+ VALUE rb_form = wrap_form(form);
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
+ }
+}
+static VALUE rbncurs_c_set_form_init(VALUE rb_form, VALUE proc) {
+ FORM * form = NULL;
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ form = get_form(rb_form);
+ reg_proc(form, FORM_INIT_HOOK, proc);
+ if (proc != Qnil) {
+ return INT2NUM(set_form_init(form, form_init_hook));
+ }
+ else {
+ return INT2NUM(set_form_init(form, NULL));
+ }
+}
+static VALUE rbncurs_m_set_form_init(VALUE dummy, VALUE rb_form, VALUE proc)
+{ return rbncurs_c_set_form_init(rb_form, proc); }
+
+static VALUE rbncurs_c_form_init(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return get_proc(form, FORM_INIT_HOOK);
+}
+static VALUE rbncurs_m_form_init(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_init(rb_form); }
+
+static void form_term_hook(FORM* form) {
+ /* Find the Proc object associated with this form */
+ VALUE proc = get_proc(form, FORM_TERM_HOOK);
+ if (proc != Qnil) {
+ VALUE rb_form = wrap_form(form);
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
+ }
+}
+static VALUE rbncurs_c_set_form_term(VALUE rb_form, VALUE proc) {
+ FORM * form = NULL;
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ form = get_form(rb_form);
+ reg_proc(form, FORM_TERM_HOOK, proc);
+ if (proc != Qnil) {
+ return INT2NUM(set_form_term(form, form_term_hook));
+ }
+ else {
+ return INT2NUM(set_form_term(form, NULL));
+ }
+}
+static VALUE rbncurs_m_set_form_term(VALUE dummy, VALUE rb_form, VALUE proc)
+{ return rbncurs_c_set_form_term(rb_form, proc); }
+
+static VALUE rbncurs_c_form_term(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return get_proc(form, FORM_TERM_HOOK);
+}
+static VALUE rbncurs_m_form_term(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_term(rb_form); }
+
+/*
+ * form_field_just
+ */
+static VALUE rbncurs_c_set_field_just(VALUE rb_field, VALUE justification) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_just(field, NUM2INT(justification)));
+}
+static VALUE rbncurs_m_set_field_just(VALUE dummy, VALUE rb_field, VALUE justification)
+{ return rbncurs_c_set_field_just(rb_field, justification); }
+
+static VALUE rbncurs_c_field_just(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(field_just(field));
+}
+static VALUE rbncurs_m_field_just(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_just(rb_field); }
+
+/*
+ * form_field_opts
+ */
+static VALUE rbncurs_c_set_field_opts(VALUE rb_field, VALUE opts) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_field_opts(field, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_set_field_opts(VALUE dummy, VALUE rb_field, VALUE opts)
+{ return rbncurs_c_set_field_opts(rb_field, opts); }
+
+static VALUE rbncurs_c_field_opts_on(VALUE rb_field, VALUE opts) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(field_opts_on(field, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_field_opts_on(VALUE dummy, VALUE rb_field, VALUE opts)
+{ return rbncurs_c_field_opts_on(rb_field, opts); }
+
+static VALUE rbncurs_c_field_opts_off(VALUE rb_field, VALUE opts) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(field_opts_off(field, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_field_opts_off(VALUE dummy, VALUE rb_field, VALUE opts)
+{ return rbncurs_c_field_opts_off(rb_field, opts); }
+
+static VALUE rbncurs_c_field_opts(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(field_opts(field));
+}
+static VALUE rbncurs_m_field_opts(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_field_opts(rb_field); }
+
+/*
+ * form_opts
+ */
+static VALUE rbncurs_c_set_form_opts(VALUE rb_form, VALUE opts) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(set_form_opts(form, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_set_form_opts(VALUE dummy, VALUE rb_form, VALUE opts)
+{ return rbncurs_c_set_form_opts(rb_form, opts); }
+
+static VALUE rbncurs_c_form_opts_on(VALUE rb_form, VALUE opts) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(form_opts_on(form, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_form_opts_on(VALUE dummy, VALUE rb_form, VALUE opts)
+{ return rbncurs_c_form_opts_on(rb_form, opts); }
+
+static VALUE rbncurs_c_form_opts_off(VALUE rb_form, VALUE opts) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(form_opts_off(form, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_form_opts_off(VALUE dummy, VALUE rb_form, VALUE opts)
+{ return rbncurs_c_form_opts_off(rb_form, opts); }
+
+static VALUE rbncurs_c_form_opts(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(form_opts(form));
+}
+static VALUE rbncurs_m_form_opts(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_opts(rb_form); }
+
+/*
+ * form_requestname
+ */
+static VALUE rbncurs_c_form_request_name(VALUE request) {
+ return rb_str_new2(form_request_name(NUM2INT(request)));
+}
+static VALUE rbncurs_m_form_request_name(VALUE dummy, VALUE request)
+{ return rbncurs_c_form_request_name(request); }
+
+static VALUE rbncurs_c_form_request_by_name(VALUE name) {
+ return INT2NUM(form_request_by_name(STR2CSTR(name)));
+}
+static VALUE rbncurs_m_form_request_by_name(VALUE dummy, VALUE name)
+{ return rbncurs_c_form_request_by_name(name); }
+
+/*
+ * form_win
+ */
+static VALUE rbncurs_c_set_form_win(VALUE rb_form, VALUE rb_win) {
+ FORM* form = get_form(rb_form);
+ WINDOW* win = get_window(rb_win);
+ return INT2NUM(set_form_win(form, win));
+}
+static VALUE rbncurs_m_set_form_win(VALUE dummy, VALUE rb_form, VALUE rb_win)
+{ return rbncurs_c_set_form_win(rb_form, rb_win); }
+
+static VALUE rbncurs_c_form_win(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return wrap_window(form_win(form));
+}
+static VALUE rbncurs_m_form_win(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_win(rb_form); }
+
+static VALUE rbncurs_c_set_form_sub(VALUE rb_form, VALUE rb_sub) {
+ FORM* form = get_form(rb_form);
+ WINDOW* win = get_window(rb_sub);
+ return INT2NUM(set_form_sub(form, win));
+}
+static VALUE rbncurs_m_set_form_sub(VALUE dummy, VALUE rb_form, VALUE rb_sub)
+{ return rbncurs_c_set_form_sub(rb_form, rb_sub); }
+
+static VALUE rbncurs_c_form_sub(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return wrap_window(form_sub(form));
+}
+static VALUE rbncurs_m_form_sub(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_form_sub(rb_form); }
+
+static VALUE rbncurs_c_scale_form(VALUE rb_form, VALUE rows, VALUE columns) {
+ FORM* form = get_form(rb_form);
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(columns, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "rows and columns arguments must be empty Arrays");
+ return Qnil;
+ }
+ else {
+ int vals[2] = {0,0};
+ int result = scale_form(form, &vals[0],&vals[1]);
+ rb_ary_push(rows, INT2NUM(vals[0]));
+ rb_ary_push(columns, INT2NUM(vals[1]));
+ return INT2NUM(result);
+ }
+}
+static VALUE rbncurs_m_scale_form(VALUE dummy, VALUE rb_form, VALUE rows, VALUE columns)
+{ return rbncurs_c_scale_form(rb_form, rows, columns); }
+
+/*
+ * form_fieldtype
+ */
+static void* make_arg(va_list* ap) {
+ /* This method creates a list of arguments to be passed */
+ /* to the validation functions (char_check and field_check). */
+ FIELD* field = va_arg(*ap, FIELD*);
+ FIELDTYPE* fieldtype = field_type(field);
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
+ if (proc == Qnil) {
+ proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
+ }
+
+ /* Compare number of arguments in Ruby Proc with that of set_field_type */
+ if (proc != Qnil) {
+ VALUE argc = rb_funcall(proc, rb_intern("arity"),0);
+ VALUE args = get_proc(field, FIELDTYPE_ARGS);
+ if (args != Qnil) {
+ if (NUM2INT(argc)-1 != rbncurs_array_length(args)) {
+ char msg[500];
+ snprintf(msg, 500, "The validation functions for this field type need %d additional arguments.",NUM2INT(argc)-1);
+ msg[499]=0;
+ rb_raise(rb_eArgError, msg);
+ }
+ }
+ }
+ /* field will be the only argument in field_check/char_check callback */
+ /* and will be used to locate the appropriate Ruby Proc */
+ return field;
+}
+static bool field_check(FIELD* field, const void* argblock) {
+ FIELDTYPE* fieldtype = field_type(field);
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
+ if (proc != Qnil)
+ {
+ VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
+ rb_ary_unshift(args, wrap_field(field));
+ return RTEST(rb_apply(proc, rb_intern("call"), args));
+ }
+ return 1;
+}
+static bool char_check(int c, const void* argblock) {
+ FIELD* field = (FIELD*)argblock;
+ FIELDTYPE* fieldtype = field_type(field);
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
+ if (proc != Qnil) {
+ VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
+ char str[2];
+ str[0] = c;
+ str[1] = 0;
+ rb_ary_unshift(args, rb_str_new2(str));
+ return RTEST(rb_apply(proc, rb_intern("call"), args));
+ }
+ return 1;
+}
+static VALUE rbncurs_m_new_fieldtype(VALUE dummy, VALUE field_check_proc, VALUE char_check_proc)
+{
+ FIELDTYPE* fieldtype = new_fieldtype(field_check_proc == Qnil ? NULL : field_check,
+ char_check_proc == Qnil ? NULL : char_check);
+ set_fieldtype_arg(fieldtype, make_arg, NULL, NULL);
+ if (field_check_proc != Qnil) {
+ reg_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK, field_check_proc);
+ }
+ if (char_check_proc != Qnil) {
+ reg_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK, char_check_proc);
+ }
+
+ return wrap_fieldtype(fieldtype);
+}
+
+static VALUE rbncurs_c_free_fieldtype(VALUE rb_fieldtype) {
+ FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
+ return INT2NUM(free_fieldtype(fieldtype));
+}
+static VALUE rbncurs_m_free_fieldtype(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_free_fieldtype(rb_field); }
+
+static bool next_choice(FIELD* field, const void* argblock) {
+ FIELDTYPE* fieldtype = field_type(field);
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK);
+ if (proc != Qnil) {
+ /* Need to find out what exactly is argblock about... */
+ return RTEST(rb_funcall(proc, rb_intern("call"), 1, wrap_field(field)));
+ }
+ return 1;
+}
+static bool prev_choice(FIELD* field, const void* argblock) {
+ FIELDTYPE* fieldtype = field_type(field);
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK);
+ if (proc != Qnil) {
+ /* Need to find out what exactly is argblock about... */
+ return RTEST(rb_funcall(proc, rb_intern("call"), 1, wrap_field(field)));
+ }
+ return 1;
+}
+
+static VALUE rbncurs_c_set_fieldtype_choice(VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc) {
+ FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
+ int result = set_fieldtype_choice(fieldtype,
+ next_choice_proc == Qnil ? NULL : next_choice,
+ prev_choice_proc == Qnil ? NULL : prev_choice);
+ if (next_choice_proc != Qnil)
+ reg_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK, next_choice_proc);
+ if (prev_choice_proc != Qnil)
+ reg_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK, prev_choice_proc);
+ return INT2NUM(result);
+}
+static VALUE rbncurs_m_set_fieldtype_choice(VALUE dummy, VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc)
+{ return rbncurs_c_set_fieldtype_choice(rb_fieldtype, next_choice_proc, prev_choice_proc); }
+
+static VALUE rbncurs_c_link_fieldtype(VALUE rb_fieldtype1, VALUE rb_fieldtype2) {
+ FIELDTYPE* fieldtype1 = get_fieldtype(rb_fieldtype1);
+ FIELDTYPE* fieldtype2 = get_fieldtype(rb_fieldtype2);
+ return wrap_fieldtype(link_fieldtype(fieldtype1, fieldtype2));
+}
+static VALUE rbncurs_m_link_fieldtype(VALUE dummy, VALUE rb_fieldtype1, VALUE fieldtype2)
+{ return rbncurs_c_link_fieldtype(rb_fieldtype1, fieldtype2); }
+
+static VALUE rbncurs_c_set_new_page(VALUE rb_field, VALUE new_page_flag) {
+ FIELD* field = get_field(rb_field);
+ return INT2NUM(set_new_page(field, RTEST(new_page_flag)));
+}
+static VALUE rbncurs_m_set_new_page(VALUE dummy, VALUE rb_field, VALUE new_page_flag)
+{ return rbncurs_c_set_new_page(rb_field, new_page_flag); }
+
+static VALUE rbncurs_c_new_page(VALUE rb_field) {
+ FIELD* field = get_field(rb_field);
+ return (new_page(field))? Qtrue : Qfalse;
+}
+static VALUE rbncurs_m_new_page(VALUE dummy, VALUE rb_field)
+{ return rbncurs_c_new_page(rb_field); }
+
+/*
+ * form_cursor
+ */
+static VALUE rbncurs_c_pos_form_cursor(VALUE rb_form) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(pos_form_cursor(form));
+}
+static VALUE rbncurs_m_pos_form_cursor(VALUE dummy, VALUE rb_form)
+{ return rbncurs_c_pos_form_cursor(rb_form); }
+
+void init_form(void)
+{
+
+ mForm = rb_define_module_under(mNcurses, "Form");
+
+ FORM_SNG_FUNC(current_field,1);
+ FORM_SNG_FUNC(data_ahead,1);
+ FORM_SNG_FUNC(data_behind,1);
+ FORM_SNG_FUNC(dup_field,3);
+ FORM_SNG_FUNC(dynamic_field_info,4);
+ FORM_SNG_FUNC(field_arg,1);
+ FORM_SNG_FUNC(field_back,1);
+ FORM_SNG_FUNC(field_buffer,2);
+ FORM_SNG_FUNC(field_count,1);
+ FORM_SNG_FUNC(field_fore,1);
+ FORM_SNG_FUNC(field_index,1);
+ FORM_SNG_FUNC(field_info,7);
+ FORM_SNG_FUNC(field_init,1);
+ FORM_SNG_FUNC(field_just,1);
+ FORM_SNG_FUNC(field_opts,1);
+ FORM_SNG_FUNC(field_opts_off,2);
+ FORM_SNG_FUNC(field_opts_on,2);
+ FORM_SNG_FUNC(field_pad,1);
+ FORM_SNG_FUNC(field_status,1);
+ FORM_SNG_FUNC(field_term,1);
+ FORM_SNG_FUNC(field_type,1);
+ /* FORM_SNG_FUNC(field_userptr,1); */
+ FORM_SNG_FUNC(form_driver,2);
+ FORM_SNG_FUNC(form_fields,1);
+ FORM_SNG_FUNC(form_init,1);
+ FORM_SNG_FUNC(form_opts,1);
+ FORM_SNG_FUNC(form_opts_off,2);
+ FORM_SNG_FUNC(form_opts_on,2);
+ FORM_SNG_FUNC(form_page,1);
+ FORM_SNG_FUNC(form_request_by_name,1);
+ FORM_SNG_FUNC(form_request_name,1);
+ FORM_SNG_FUNC(form_sub,1);
+ FORM_SNG_FUNC(form_term,1);
+ /* FORM_SNG_FUNC(form_userptr,1); */
+ FORM_SNG_FUNC(form_win,1);
+ FORM_SNG_FUNC(free_field,1);
+ FORM_SNG_FUNC(free_fieldtype,1);
+ FORM_SNG_FUNC(free_form,1);
+ FORM_SNG_FUNC(link_field,3);
+ FORM_SNG_FUNC(link_fieldtype,2);
+ FORM_SNG_FUNC(move_field,3);
+ FORM_SNG_FUNC(new_field,6);
+ FORM_SNG_FUNC(new_fieldtype,2);
+ FORM_SNG_FUNC(new_form,1);
+ FORM_SNG_FUNC(new_page,1);
+ FORM_SNG_FUNC(pos_form_cursor,1);
+ FORM_SNG_FUNC(post_form,1);
+ FORM_SNG_FUNC(scale_form,3);
+ FORM_SNG_FUNC(set_current_field,2);
+ FORM_SNG_FUNC(set_field_back,2);
+ FORM_SNG_FUNC(set_field_buffer,3);
+ FORM_SNG_FUNC(set_field_fore,2);
+ FORM_SNG_FUNC(set_field_init,2);
+ FORM_SNG_FUNC(set_field_just,2);
+ FORM_SNG_FUNC(set_field_opts,2);
+ FORM_SNG_FUNC(set_field_pad,2);
+ FORM_SNG_FUNC(set_field_status,2);
+ FORM_SNG_FUNC(set_field_term,2);
+ FORM_SNG_FUNC(set_field_type,-1);
+ /* FORM_SNG_FUNC(set_field_userptr,2); */
+ FORM_SNG_FUNC(set_fieldtype_choice,3);
+ FORM_SNG_FUNC(set_form_fields,2);
+ FORM_SNG_FUNC(set_form_init,2);
+ FORM_SNG_FUNC(set_form_opts,2);
+ FORM_SNG_FUNC(set_form_page,2);
+ FORM_SNG_FUNC(set_form_sub,2);
+ FORM_SNG_FUNC(set_form_term,2);
+ /* FORM_SNG_FUNC(set_form_userptr,2); */
+ FORM_SNG_FUNC(set_form_win,2);
+ FORM_SNG_FUNC(set_max_field,2);
+ FORM_SNG_FUNC(set_new_page,2);
+ FORM_SNG_FUNC(unpost_form,1);
+
+ init_err_codes();
+ init_req_constants();
+ init_opts_constants();
+ init_just_constants();
+ init_form_opts_constants();
+
+ /* Hashes to store registered blocks (Proc) */
+ {
+ VALUE hashes = rb_iv_set(mForm, "@proc_hashes", rb_ary_new());
+ int i;
+ for (i = 0; i < PROC_HASHES_COUNT; i++)
+ {
+ rb_ary_push(hashes, rb_hash_new());
+ }
+ }
+
+ /* Forms */
+ rb_iv_set(mForm, "@forms_hash", rb_hash_new());
+ cFORM = rb_define_class_under(mForm, "FORM", rb_cObject);
+ rb_define_singleton_method(cFORM, "new",
+ (&rbncurs_m_new_form),
+ 1);
+ RB_CLASS_METH(cFORM, NULL, current_field,0);
+ RB_CLASS_METH(cFORM, NULL, data_ahead,0);
+ RB_CLASS_METH(cFORM, NULL, data_behind,0);
+ RB_CLASS_METH(cFORM, NULL, dup_field,2);
+ RB_CLASS_METH(cFORM, NULL, field_count,0);
+ RB_CLASS_METH(cFORM, NULL, field_init,0);
+ RB_CLASS_METH(cFORM, NULL, field_term,0);
+ RB_CLASS_METH(cFORM, "driver", form_driver,1);
+ RB_CLASS_METH(cFORM, "fields", form_fields,0);
+ RB_CLASS_METH(cFORM, "init", form_init,0);
+ RB_CLASS_METH(cFORM, "opts", form_opts,0);
+ RB_CLASS_METH(cFORM, "opts_off", form_opts_off,1);
+ RB_CLASS_METH(cFORM, "opts_on", form_opts_on,1);
+ RB_CLASS_METH(cFORM, "page", form_page,0);
+ RB_CLASS_METH(cFORM, "sub", form_sub,0);
+ RB_CLASS_METH(cFORM, "term", form_term,0);
+ /* RB_CLASS_METH(cFORM, "userptr", form_userptr,0); */
+ RB_CLASS_METH(cFORM, "win", form_win,0);
+ RB_CLASS_METH(cFORM, "free", free_form,0);
+ RB_CLASS_METH(cFORM, "pos_cursor", pos_form_cursor,0);
+ RB_CLASS_METH(cFORM, "post", post_form,0);
+ RB_CLASS_METH(cFORM, "scale", scale_form,2);
+ RB_CLASS_METH(cFORM, "current_field=", set_current_field,1);
+ RB_CLASS_METH(cFORM, "field_init=", set_field_init,1);
+ RB_CLASS_METH(cFORM, "field_term=", set_field_term,1);
+ RB_CLASS_METH(cFORM, "fields=", set_form_fields,1);
+ RB_CLASS_METH(cFORM, "init=", set_form_init,1);
+ RB_CLASS_METH(cFORM, "opts=", set_form_opts,1);
+ RB_CLASS_METH(cFORM, "page=", set_form_page,1);
+ RB_CLASS_METH(cFORM, "sub=", set_form_sub,1);
+ RB_CLASS_METH(cFORM, "term=", set_form_term,1);
+ /* RB_CLASS_METH(cFORM, "userptr=", set_form_userptr,1); */
+ RB_CLASS_METH(cFORM, "win=", set_form_win,1);
+ RB_CLASS_METH(cFORM, "unpost", unpost_form,0);
+
+ /* Fields */
+ rb_iv_set(mForm, "@fields_hash", rb_hash_new());
+ cFIELD = rb_define_class_under(mForm, "FIELD", rb_cObject);
+ rb_define_singleton_method(cFIELD, "new",
+ (&rbncurs_m_new_field),
+ 6);
+ RB_CLASS_METH(cFIELD, "dup", dup_field,2);
+ RB_CLASS_METH(cFIELD, "dynamic_info", dynamic_field_info,3);
+ RB_CLASS_METH(cFIELD, "arg", field_arg,0);
+ RB_CLASS_METH(cFIELD, "back", field_back,1);
+ RB_CLASS_METH(cFIELD, "buffer", field_buffer,1);
+ RB_CLASS_METH(cFIELD, "fore", field_fore,1);
+ RB_CLASS_METH(cFIELD, "index", field_index,0);
+ RB_CLASS_METH(cFIELD, "info", field_info,6);
+ RB_CLASS_METH(cFIELD, "just", field_just,0);
+ RB_CLASS_METH(cFIELD, "opts", field_opts,0);
+ RB_CLASS_METH(cFIELD, "opts_off", field_opts_off,1);
+ RB_CLASS_METH(cFIELD, "opts_on", field_opts_on,1);
+ RB_CLASS_METH(cFIELD, "pad", field_pad,1);
+ RB_CLASS_METH(cFIELD, "status", field_status,0);
+ RB_CLASS_METH(cFIELD, "type", field_type,0);
+ /* RB_CLASS_METH(cFIELD, "userptr", field_userptr,0); */
+ RB_CLASS_METH(cFIELD, "free", free_field,0);
+ RB_CLASS_METH(cFIELD, "link", link_field,2);
+ RB_CLASS_METH(cFIELD, "move", move_field,2);
+ RB_CLASS_METH(cFIELD, NULL, new_page,0);
+ RB_CLASS_METH(cFIELD, "back=", set_field_back,1);
+ RB_CLASS_METH(cFIELD, "set_buffer", set_field_buffer,2);
+ RB_CLASS_METH(cFIELD, "fore=", set_field_fore,1);
+ RB_CLASS_METH(cFIELD, "just=", set_field_just,1);
+ RB_CLASS_METH(cFIELD, "opts=", set_field_opts,1);
+ RB_CLASS_METH(cFIELD, "pad=", set_field_pad,1);
+ RB_CLASS_METH(cFIELD, "status=", set_field_status,1);
+ RB_CLASS_METH(cFIELD, "set_type", set_field_type,-1);
+ /* RB_CLASS_METH(cFIELD, "userptr=", set_field_userptr,1); */
+ RB_CLASS_METH(cFIELD, "max_field=", set_max_field,1);
+ RB_CLASS_METH(cFIELD, "new_page=", set_new_page,1);
+
+
+
+
+ /* Field types */
+ rb_iv_set(mForm, "@fieldtypes_hash", rb_hash_new());
+ cFIELDTYPE = rb_define_class_under(mForm, "FIELDTYPE", rb_cObject);
+ rb_define_singleton_method(cFIELDTYPE, "new",
+ (&rbncurs_m_new_fieldtype),
+ 2);
+ RB_CLASS_METH(cFIELDTYPE, "free", free_fieldtype,0);
+ RB_CLASS_METH(cFIELDTYPE, "link", link_fieldtype,1);
+ RB_CLASS_METH(cFIELDTYPE, "set_choice", set_fieldtype_choice,2);
+
+ /* Create predefined types */
+ rb_define_const(mForm, "TYPE_ALNUM", wrap_fieldtype(TYPE_ALNUM));
+ rb_define_const(mForm, "TYPE_ALPHA", wrap_fieldtype(TYPE_ALPHA));
+ rb_define_const(mForm, "TYPE_ENUM", wrap_fieldtype(TYPE_ENUM));
+ rb_define_const(mForm, "TYPE_INTEGER", wrap_fieldtype(TYPE_INTEGER));
+ rb_define_const(mForm, "TYPE_NUMERIC", wrap_fieldtype(TYPE_NUMERIC));
+ rb_define_const(mForm, "TYPE_REGEXP", wrap_fieldtype(TYPE_REGEXP));
+ rb_define_const(mForm, "TYPE_IPV4", wrap_fieldtype(TYPE_IPV4));
+
+}
+
+#endif
diff --git a/form_wrap.h b/form_wrap.h
@@ -0,0 +1,61 @@
+/*
+ * This is a curses forms wrapper as part of ncurses-ruby
+ * Contributed by Simon Kaczor <skaczor@cox.net>
+ * Prognosoft Inc. <http://www.prognosoft.biz>
+ * Copyright 2004
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#if !defined(FORM_HH) && defined(HAVE_FORM_H)
+#define FORM_HH
+
+#include <form.h>
+#include <ruby.h>
+
+extern VALUE mForm;
+extern VALUE cFIELD;
+extern VALUE cFIELDTYPE;
+extern VALUE cFORM;
+/*extern VALUE cPAGE;*/
+
+typedef struct {
+ bool (* field_check)(FIELD *,const void *);
+ FIELDTYPE* fieldtype;
+} FLDCHKFUNC;
+
+
+
+#define FORM_DEF_CONST(name) \
+ rb_define_const(mForm, #name, INT2NUM(name));
+
+#define FORM_SNG_FUNC(name, nargs) \
+ rb_define_singleton_method(mForm, \
+ #name, \
+ &rbncurs_m_ ## name, \
+ nargs)
+#define RB_CLASS_METH(class, alt_name, name, nargs) \
+ rb_define_method(class, #name, (&rbncurs_c_ ## name), nargs); \
+ if (alt_name != NULL) \
+ rb_define_method(class, alt_name, (&rbncurs_c_ ## name), nargs); \
+
+void init_req_constants();
+void init_just_constants();
+void init_opts_constants();
+
+void init_form(void);
+
+#endif
diff --git a/lib/ncurses.rb b/lib/ncurses.rb
@@ -0,0 +1,344 @@
+# ncurses-ruby is a ruby module for accessing the FSF's ncurses library
+# (C) 2002, 2003, 2004 Tobias Peters <t-peters@users.berlios.de>
+# (C) 2004 Simon Kaczor <skaczor@cox.net>
+# (C) 2005 Tobias Herzke
+#
+# This module is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+# $Id: ncurses.rb,v 1.8 2009/05/03 10:37:54 t-peters Exp $
+
+require "ncurses_bin.so"
+
+
+# Ncurses constants with leading underscore
+def Ncurses._XOPEN_CURSES
+ Ncurses::XOPEN_CURSES
+end
+def Ncurses._SUBWIN
+ Ncurses::SUBWIN
+end
+def Ncurses._ENDLINE
+ Ncurses::ENDLINE
+end
+def Ncurses._FULLWIN
+ Ncurses::FULLWIN
+end
+def Ncurses._SCROLLWIN
+ Ncurses::SCROLLWIN
+end
+def Ncurses._ISPAD
+ Ncurses::ISPAD
+end
+def Ncurses._HASMOVED
+ Ncurses::HASMOVED
+end
+def Ncurses._WRAPPED
+ Ncurses::WRAPPED
+end
+def Ncurses._NOCHANGE
+ Ncurses::NOCHANGE
+end
+def Ncurses._NEWINDEX
+ Ncurses::NEWINDEX
+end
+
+
+module Ncurses
+ module Destroy_checker; def destroyed?; @destroyed; end; end
+ class WINDOW
+ include Destroy_checker
+ def method_missing(name, *args)
+ name = name.to_s
+ if (name[0,2] == "mv")
+ test_name = name.dup
+ test_name[2,0] = "w" # insert "w" after"mv"
+ if (Ncurses.respond_to?(test_name))
+ return Ncurses.send(test_name, self, *args)
+ end
+ end
+ test_name = "w" + name
+ if (Ncurses.respond_to?(test_name))
+ return Ncurses.send(test_name, self, *args)
+ end
+ Ncurses.send(name, self, *args)
+ end
+ def respond_to?(name)
+ name = name.to_s
+ if (name[0,2] == "mv" && Ncurses.respond_to?("mvw" + name[2..-1]))
+ return true
+ end
+ Ncurses.respond_to?("w" + name) || Ncurses.respond_to?(name)
+ end
+ def del
+ Ncurses.delwin(self)
+ end
+ alias delete del
+ def WINDOW.new(*args)
+ Ncurses.newwin(*args)
+ end
+ end
+ class SCREEN
+ include Destroy_checker
+ def del
+ Ncurses.delscreen(self)
+ end
+ alias delete del
+ end
+ class MEVENT
+ attr_accessor :id, :x,:y,:z, :bstate
+ end
+ GETSTR_LIMIT = 1024
+
+ module Panel
+ class PANEL; end
+ end
+
+ module Form
+ class FORM
+ attr_reader :user_object
+
+ # This placeholder replaces the form_userptr function in curses
+ def user_object=(obj)
+ @user_object = obj
+ end
+ end
+
+ class FIELD
+ attr_reader :user_object
+
+ # This placeholder replaces the field_userptr function in curses
+ def user_object=(obj)
+ @user_object = obj
+ end
+ end
+
+ class FIELDTYPE
+ end
+ end
+
+ module Menu
+ class MENU
+ attr_reader :user_object
+
+ # This placeholder replaces the menu_userptr function in curses
+ def user_object=(obj)
+ @user_object = obj
+ end
+ end
+
+ class ITEM
+ attr_reader :user_object
+
+ # This placeholder replaces the item_userptr function in curses
+ def user_object=(obj)
+ @user_object = obj
+ end
+ end
+ end
+end
+def Ncurses.inchnstr(str,n)
+ Ncurses.winchnstr(Ncurses.stdscr, str, n)
+end
+def Ncurses.inchstr(str)
+ Ncurses.winchstr(Ncurses.stdscr, str)
+end
+def Ncurses.mvinchnstr(y,x, str, n)
+ Ncurses.mvwinchnstr(Ncurses.stdscr, y,x, str, n)
+end
+def Ncurses.mvinchstr(y,x, str)
+ Ncurses.mvwinchstr(Ncurses.stdscr, y,x, str)
+end
+def Ncurses.mvwinchnstr(win, y,x, str, n)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ Ncurses::ERR
+ else
+ Ncurses.winchnstr(win,str,n)
+ end
+end
+def Ncurses.mvwinchstr(win, y,x, str)
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
+ Ncurses.mvwinchnstr(win, y,x, str, maxx[0]+1)
+end
+def Ncurses.winchstr(win, str)
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
+ Ncurses.winchnstr(win, str, maxx[0]+1)
+end
+
+def Ncurses.getnstr(str,n)
+ Ncurses.wgetnstr(Ncurses.stdscr, str, n)
+end
+def Ncurses.mvgetnstr(y,x, str, n)
+ Ncurses.mvwgetnstr(Ncurses.stdscr, y,x, str, n)
+end
+def Ncurses.mvwgetnstr(win, y,x, str, n)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ Ncurses::ERR
+ else
+ Ncurses.wgetnstr(win,str,n)
+ end
+end
+
+def Ncurses.innstr(str,n)
+ Ncurses.winnstr(Ncurses.stdscr, str, n)
+end
+def Ncurses.instr(str)
+ Ncurses.winstr(Ncurses.stdscr, str)
+end
+def Ncurses.mvinnstr(y,x, str, n)
+ Ncurses.mvwinnstr(Ncurses.stdscr, y,x, str, n)
+end
+def Ncurses.mvinstr(y,x, str)
+ Ncurses.mvwinstr(Ncurses.stdscr, y,x, str)
+end
+def Ncurses.mvwinnstr(win, y,x, str, n)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ Ncurses::ERR
+ else
+ Ncurses.winnstr(win,str,n)
+ end
+end
+def Ncurses.mvwinstr(win, y,x, str)
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
+ Ncurses.mvwinnstr(win, y,x, str, maxx[0]+1)
+end
+def Ncurses.winstr(win, str)
+ maxy = []; maxx = []; getmaxyx(win, maxy,maxx)
+ return Ncurses::ERR if (maxx[0] == Ncurses::ERR)
+ Ncurses.winnstr(win, str, maxx[0]+1)
+end
+
+def Ncurses.mouse_trafo(pY, pX, to_screen)
+ Ncurses.wmouse_trafo(Ncurses.stdscr, pY, pX, to_screen)
+end
+
+def Ncurses.getcurx(win)
+ x = []; y = []; Ncurses.getyx(win, y,x); x[0]
+end
+def Ncurses.getcury(win)
+ x = []; y = []; Ncurses.getyx(win, y,x); y[0]
+end
+def Ncurses.getbegx(win)
+ x = []; y = []; Ncurses.getbegyx(win, y,x); x[0]
+end
+def Ncurses.getbegy(win)
+ x = []; y = []; Ncurses.getbegyx(win, y,x); y[0]
+end
+def Ncurses.getmaxx(win)
+ x = []; y = []; Ncurses.getmaxyx(win, y,x); x[0]
+end
+def Ncurses.getmaxy(win)
+ x = []; y = []; Ncurses.getmaxyx(win, y,x); y[0]
+end
+def Ncurses.getparx(win)
+ x = []; y = []; Ncurses.getparyx(win, y,x); x[0]
+end
+def Ncurses.getpary(win)
+ x = []; y = []; Ncurses.getparyx(win, y,x); y[0]
+end
+def Ncurses.erase
+ Ncurses.werase(Ncurses.stdscr)
+end
+def Ncurses.getstr(str)
+ Ncurses.getnstr(str, Ncurses::GETSTR_LIMIT)
+end
+def Ncurses.mvgetstr(y,x, str)
+ Ncurses.mvgetnstr(y,x, str, Ncurses::GETSTR_LIMIT)
+end
+def Ncurses.mvwgetstr(win, y,x, str)
+ Ncurses.mvwgetnstr(win, y,x, str, Ncurses::GETSTR_LIMIT)
+end
+def Ncurses.wgetstr(win, str)
+ Ncurses.wgetnstr(win, str, Ncurses::GETSTR_LIMIT)
+end
+
+def Ncurses.scanw(format, result)
+ Ncurses.wscanw(Ncurses.stdscr, format, result)
+end
+def Ncurses.mvscanw(y,x, format, result)
+ Ncurses.mvwscanw(Ncurses.stdscr, y,x, format, result)
+end
+def Ncurses.mvwscanw(win, y,x, format, result)
+ if (Ncurses.wmove(win, y,x) == Ncurses::ERR)
+ Ncurses::ERR
+ else
+ Ncurses.wscanw(win, format, result)
+ end
+end
+def Ncurses.wscanw(win, format, result)
+ str = ""
+ if (Ncurses.wgetstr(win, str) == Ncurses::ERR)
+ Ncurses::ERR
+ else
+ require "scanf.rb" # Use ruby's implementation of scanf
+ result.replace(str.scanf(format))
+ end
+end
+
+def Ncurses.mvprintw(*args)
+ Ncurses.mvwprintw(Ncurses.stdscr, *args)
+end
+def Ncurses.mvwprintw(win, y,x, *args)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ Ncurses::ERR
+ else
+ wprintw(win, *args)
+ end
+end
+def Ncurses.printw(*args)
+ Ncurses.wprintw(Ncurses.stdscr, *args)
+end
+def Ncurses.touchline(win, start, count)
+ Ncurses.wtouchln(win, start, count, 1)
+end
+def Ncurses.touchwin(win)
+ wtouchln(win, 0, getmaxy(win), 1)
+end
+
+module Ncurses
+ Ncurses = self # for accessing Ncurses from a Module that includes Ncurses
+
+ # Some users like to include ncurses names despite namespace pollution
+ # This module is for them
+ module Namespace
+ def self.append_features(target)
+ # include constants
+ unless target.ancestors.member?(Ncurses)
+ target.__send__(:include, Ncurses)
+ end
+
+ # make methods available
+ unless target.respond_to?(:pre_Ncurses_method_missing)
+ target.module_eval{
+ alias pre_Ncurses_method_missing method_missing
+ def method_missing(name, *args)
+ if Ncurses.respond_to?(name)
+ Ncurses.send(name, *args)
+ else
+ pre_Ncurses_method_missing(name, *args)
+ end
+ end
+ }
+ end
+ end
+ def self.entend_object(object)
+ class << object
+ self
+ end.__send__(:include, self)
+ end
+ end
+end
diff --git a/make_dist.rb b/make_dist.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+
+# $Id: make_dist.rb,v 1.6 2003/08/29 22:50:12 t-peters Exp $
+
+require "fileutils"
+
+def sys(i)
+ puts("\"#{i}\"")
+ system(i)
+end
+
+dir = File.dirname(__FILE__)
+base = File.basename(dir)
+base = "ncurses-ruby" if base == "."
+
+files = IO.readlines(dir + "/MANIFEST").collect{|filename|filename.chomp}
+
+Version = File.new("#{dir}/VERSION").readline.chomp!
+
+FileUtils.mkdir "#{base}-#{Version}"
+files.each{|filename|
+ if filename.index "/"
+ FileUtils.mkdir_p "#{base}-#{Version}/#{File.dirname(filename)}"
+ end
+ sys "cp #{dir}/#{filename} #{base}-#{Version}/#{filename}"
+}
+sys "tar cjf #{base}-#{Version}.tar.bz2 --owner=0 --group=0 #{base}-#{Version}"
+
+# check if we create a binary distribution for a mingw extension
+binary_description = `file ncurses.so`
+
+if ((binary_description =~ /\s(windows)\s/i) &&
+ (binary_description =~ /\s(pe)|(portable executable)\s/i) &&
+ (binary_description =~ /\s(dll)\s/i))
+ sys "cp ncurses.so README.binary #{base}-#{Version}"
+ Dir.glob("#{base}-#{Version}/README*").each{|textfile|
+ text = IO.readlines(textfile).map{|line|line.chomp + "\r\n"}
+ File.open(textfile + ".txt", "wb"){|outfd| outfd.write(text.join)}
+ sys "rm #{textfile}"
+ }
+ sys "rm #{base}-#{Version}/{MANIFEST,make_dist.rb}"
+ sys "zip -9 -r #{base}-#{Version}-i386-mswin32.zip #{base}-#{Version}"
+end
+
+sys "rm -r #{base}-#{Version}/"
diff --git a/menu_wrap.c b/menu_wrap.c
@@ -0,0 +1,1144 @@
+/*
+ * This is a curses menu wrapper as part of ncurses-ruby.
+ * It borrows heavily from form_wrap.c.
+ * Contributed by Earle Clubb <eclubb@valcom.com>
+ * Valcom Inc. <http://www.valcom.com>
+ * Copyright 2007
+ *
+ * Modifications
+ * (C) 2009 Tobias Herzke
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifdef HAVE_MENU_H
+
+#include "menu_wrap.h"
+#include "ncurses_wrap.h"
+
+VALUE mMenu;
+VALUE cITEM;
+VALUE cMENU;
+
+void init_menu_err_codes(void)
+{
+ /* The routine succeeded. */
+ MENU_DEF_CONST(E_OK);
+ /* System error occurred (see errno). */
+ MENU_DEF_CONST(E_SYSTEM_ERROR);
+ /* Routine detected an incorrect or out-of-range argument. */
+ MENU_DEF_CONST(E_BAD_ARGUMENT);
+ /* The menu is already posted. */
+ MENU_DEF_CONST(E_POSTED);
+ /* Routine was called from an initialization or termination function. */
+ MENU_DEF_CONST(E_BAD_STATE);
+ /* Menu is too large for its window. */
+ MENU_DEF_CONST(E_NO_ROOM);
+ /* The menu has not been posted. */
+ MENU_DEF_CONST(E_NOT_POSTED);
+ /* The menu driver code saw an unknown request code. */
+ MENU_DEF_CONST(E_UNKNOWN_COMMAND);
+ /* Character failed to match. */
+ MENU_DEF_CONST(E_NO_MATCH);
+ /* The designated item cannot be selected. */
+ MENU_DEF_CONST(E_NOT_SELECTABLE);
+ /* No items are connected to the menu. */
+ MENU_DEF_CONST(E_NOT_CONNECTED);
+ /* The menu driver could not process the request.} */
+ MENU_DEF_CONST(E_REQUEST_DENIED);
+}
+
+
+/*
+ * Menu driver request characters - menu_driver(3x) man page
+ */
+void init_menu_req_constants(void)
+{
+ /* Move left to an item. */
+ MENU_DEF_CONST(REQ_LEFT_ITEM);
+ /* Move right to an item. */
+ MENU_DEF_CONST(REQ_RIGHT_ITEM);
+ /* Move up to an item. */
+ MENU_DEF_CONST(REQ_UP_ITEM);
+ /* Move down to an item. */
+ MENU_DEF_CONST(REQ_DOWN_ITEM);
+ /* Scroll up a line. */
+ MENU_DEF_CONST(REQ_SCR_ULINE);
+ /* Scroll down a line. */
+ MENU_DEF_CONST(REQ_SCR_DLINE);
+ /* Scroll up a page. */
+ MENU_DEF_CONST(REQ_SCR_UPAGE);
+ /* Scroll down a page. */
+ MENU_DEF_CONST(REQ_SCR_DPAGE);
+ /* Move to the first item. */
+ MENU_DEF_CONST(REQ_FIRST_ITEM);
+ /* Move to the last item. */
+ MENU_DEF_CONST(REQ_LAST_ITEM);
+ /* Move to the next item. */
+ MENU_DEF_CONST(REQ_NEXT_ITEM);
+ /* Move to the previous item. */
+ MENU_DEF_CONST(REQ_PREV_ITEM);
+ /* Select/deselect an item. */
+ MENU_DEF_CONST(REQ_TOGGLE_ITEM);
+ /* Clear the menu pattern buffer. */
+ MENU_DEF_CONST(REQ_CLEAR_PATTERN);
+ /* Delete the previous character from the pattern buffer. */
+ MENU_DEF_CONST(REQ_BACK_PATTERN);
+ /* Move to the next item matching the pattern match. */
+ MENU_DEF_CONST(REQ_NEXT_MATCH);
+ /* Move to the previous item matching the pattern match. */
+ MENU_DEF_CONST(REQ_PREV_MATCH);
+}
+
+
+/*
+ * Item options - mitem_opts(3x) man page
+ */
+void init_item_opts_constants(void)
+{
+ /* Item may be selected during menu processing. */
+ MENU_DEF_CONST(O_SELECTABLE);
+}
+
+
+/*
+ * Menu options - menu_opts(3x) man page
+ */
+void init_menu_opts_constants(void)
+{
+ /* Only one item can be selected for this menu. */
+ MENU_DEF_CONST(O_ONEVALUE);
+ /* Display the item descriptions when the menu is posted. */
+ MENU_DEF_CONST(O_SHOWDESC);
+ /* Display the menu in row-major order. */
+ MENU_DEF_CONST(O_ROWMAJOR);
+ /* Ignore the case when pattern-matching. */
+ MENU_DEF_CONST(O_IGNORECASE);
+ /* Move the cursor to within the item name while pattern-matching. */
+ MENU_DEF_CONST(O_SHOWMATCH);
+ /* Don’t wrap around next-item and previous-item, requests to the other end of the menu. */
+ MENU_DEF_CONST(O_NONCYCLIC);
+}
+
+
+/*
+ * ITEM wrapper
+ */
+static VALUE wrap_item(ITEM *item)
+{
+ if (item == 0) return Qnil;
+ {
+ VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
+ VALUE item_address = INT2NUM((long)(item));
+ VALUE rb_item = rb_hash_aref(items_hash, item_address);
+
+ if (rb_item == Qnil)
+ {
+ rb_item = Data_Wrap_Struct(cITEM, 0, 0, item);
+ rb_iv_set(rb_item, "@destroyed", Qfalse);
+ rb_hash_aset(items_hash, item_address, rb_item);
+ }
+ return rb_item;
+ }
+}
+static ITEM *get_item(VALUE rb_item)
+{
+ ITEM *item;
+
+ if (rb_item == Qnil) return 0;
+ if (rb_iv_get(rb_item, "@destroyed") == Qtrue)
+ {
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed item");
+ return 0;
+ }
+ Data_Get_Struct(rb_item, ITEM, item);
+ return item;
+}
+
+
+/*
+ * MENU wrapper
+ */
+static VALUE wrap_menu(MENU *menu)
+{
+ if (menu == 0) return Qnil;
+ {
+ VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
+ VALUE menu_address = INT2NUM((long)(menu));
+ VALUE rb_menu = rb_hash_aref(menus_hash, menu_address);
+
+ if (rb_menu == Qnil)
+ {
+ rb_menu = Data_Wrap_Struct(cMENU, 0, 0, menu);
+ rb_iv_set(rb_menu, "@destroyed", Qfalse);
+ rb_hash_aset(menus_hash, menu_address, rb_menu);
+ }
+ return rb_menu;
+ }
+}
+static MENU *get_menu(VALUE rb_menu)
+{
+ MENU *menu;
+
+ if (rb_menu == Qnil) return 0;
+ if (rb_iv_get(rb_menu, "@destroyed") == Qtrue)
+ {
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed menu");
+ return 0;
+ }
+ Data_Get_Struct(rb_menu, MENU, menu);
+ return menu;
+}
+
+
+/*
+ * Proc objects are registered using hashes (one for each type of hook)
+ * The key in the hash is the address of the ncurses "object" and the value is
+ * the Proc object.
+ */
+#define ITEM_INIT_HOOK 0
+#define ITEM_TERM_HOOK 1
+#define MENU_INIT_HOOK 2
+#define MENU_TERM_HOOK 3
+#define PROC_HASHES_COUNT 4
+static VALUE get_proc_hash(int hook)
+{
+ VALUE arr = rb_iv_get(mMenu, "@proc_hashes");
+ VALUE hash = rb_ary_entry(arr, (long)hook);
+
+ if (hash == Qnil)
+ rb_raise(rb_eRuntimeError, "Invalid proc hash.");
+ return hash;
+}
+
+/*
+ * Returns an existing Ruby Proc for a given owning "object" and hook type.
+ * Qnil will be returned if no Proc was associated with the owner
+ */
+static VALUE get_proc(void *owner, int hook)
+{
+ if (owner == 0) return Qnil;
+ {
+ VALUE owner_address = INT2NUM((long)(owner));
+ VALUE proc_hash = get_proc_hash(hook);
+ VALUE proc = rb_hash_aref(proc_hash, owner_address);
+
+ return proc;
+ }
+}
+
+/*
+ * Registers the Proc object with a given owner "object" and hook type.
+ * If proc is Qnil, the hook is unregistered instead.
+ */
+static void reg_proc(void *owner, int hook, VALUE proc)
+{
+ if (owner == NULL) return;
+ {
+ VALUE proc_hash = get_proc_hash(hook);
+ VALUE owner_address = INT2NUM((long)(owner));
+
+ if (proc == Qnil)
+ rb_hash_delete(proc_hash, owner_address);
+ else
+ rb_hash_aset(proc_hash, owner_address, proc);
+ }
+}
+
+
+/*
+ * Menu creation/destruction functions - menu_new(3X) man page
+ */
+static VALUE rbncurs_m_new_menu(VALUE dummy, VALUE rb_item_array)
+{
+ long n = rbncurs_array_length(rb_item_array);
+ /* Will ncurses free this array? If not, must do it after calling free_menu(). */
+ ITEM **items = ALLOC_N(ITEM*, (n+1));
+ long i;
+
+ for (i=0; i<n; i++)
+ items[i] = get_item(rb_ary_entry(rb_item_array, i));
+ items[n] = NULL;
+ return wrap_menu(new_menu(items));
+}
+
+static VALUE rbncurs_c_free_menu(VALUE rb_menu)
+{
+ VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
+ MENU *menu = get_menu(rb_menu);
+ VALUE menu_address = INT2NUM((long)(menu));
+
+ rb_funcall(menus_hash, rb_intern("delete"), 1, menu_address);
+ rb_iv_set(rb_menu, "@destroyed", Qtrue);
+ return INT2NUM(free_menu(menu));
+}
+static VALUE rbncurs_m_free_menu(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_free_menu(rb_menu); }
+
+
+/*
+ * Menu post/unpost functions - menu_post(3X) man page
+ */
+static VALUE rbncurs_c_post_menu(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(post_menu(menu));
+}
+static VALUE rbncurs_m_post_menu(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_post_menu(rb_menu); }
+
+static VALUE rbncurs_c_unpost_menu(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(unpost_menu(menu));
+}
+static VALUE rbncurs_m_unpost_menu(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_unpost_menu(rb_menu); }
+
+
+/*
+ * Menu driver - menu_driver(3X) man page
+ */
+static VALUE rbncurs_c_menu_driver(VALUE rb_menu, VALUE c)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(menu_driver(menu, NUM2INT(c)));
+}
+static VALUE rbncurs_m_menu_driver(VALUE dummy, VALUE rb_menu, VALUE c)
+{ return rbncurs_c_menu_driver(rb_menu, c); }
+
+
+/*
+ * Current menu item get/set functions - mitem_current(3X) man page
+ */
+static VALUE rbncurs_c_current_item(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return wrap_item(current_item(menu));
+}
+static VALUE rbncurs_m_current_item(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_current_item(rb_menu); }
+
+static VALUE rbncurs_c_set_current_item(VALUE rb_menu, VALUE rb_item)
+{
+ MENU *menu = get_menu(rb_menu);
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(set_current_item(menu, item));
+}
+static VALUE rbncurs_m_set_current_item(VALUE dummy, VALUE rb_menu, VALUE rb_item)
+{ return rbncurs_c_set_current_item(rb_menu, rb_item); }
+
+static VALUE rbncurs_c_top_row(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(top_row(menu));
+}
+static VALUE rbncurs_m_top_row(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_top_row(rb_menu); }
+
+static VALUE rbncurs_c_set_top_row(VALUE rb_menu, VALUE n)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_top_row(menu, NUM2INT(n)));
+}
+static VALUE rbncurs_m_set_top_row(VALUE dummy, VALUE rb_menu, VALUE rb_item)
+{ return rbncurs_c_set_top_row(rb_menu, rb_item); }
+
+static VALUE rbncurs_c_item_index(VALUE rb_item)
+{
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(item_index(item));
+}
+static VALUE rbncurs_m_item_index(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_item_index(rb_item); }
+
+
+/*
+ * Item creation/destruction functions - mitem_new(3X) man page
+ */
+static VALUE rbncurs_m_new_item(VALUE dummy, VALUE name, VALUE description)
+{ return wrap_item(new_item(STR2CSTR(name), STR2CSTR(description))); }
+
+static VALUE rbncurs_c_free_item(VALUE rb_item)
+{
+ VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
+ ITEM *item = get_item(rb_item);
+ VALUE item_address = INT2NUM((long)(item));
+ rb_funcall(items_hash, rb_intern("delete"), 1, item_address);
+ rb_iv_set(rb_item, "@destroyed", Qtrue);
+ return INT2NUM(free_item(item));
+}
+static VALUE rbncurs_m_free_item(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_free_item(rb_item); }
+
+
+/*
+ * Item-menu connection make/break functions - menu_items(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_items(VALUE rb_menu, VALUE rb_item_array)
+{
+ long n = rbncurs_array_length(rb_item_array);
+ /* If ncurses does not free memory used by the previous array of strings, */
+ /* we will have to do it now. */
+ ITEM **items = ALLOC_N(ITEM*, (n+1));
+ long i;
+ MENU *menu = NULL;
+
+ for (i=0; i<n; i++)
+ items[i] = get_item(rb_ary_entry(rb_item_array, i));
+ items[n] = NULL;
+ menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_items(menu, items));
+}
+static VALUE rbncurs_m_set_menu_items(VALUE dummy, VALUE rb_menu, VALUE rb_item_array)
+{ return rbncurs_c_set_menu_items(rb_menu, rb_item_array); }
+
+static VALUE rbncurs_c_menu_items(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ ITEM **items = menu_items(menu);
+ VALUE arr = Qundef;
+ int i;
+
+ if (items == NULL)
+ rb_raise(rb_eRuntimeError, "Error retrieving menu items");
+ arr = rb_ary_new();
+ i=0;
+ while (items[i] != NULL)
+ rb_ary_push(arr, wrap_item(items[i++]));
+ return arr;
+}
+static VALUE rbncurs_m_menu_items(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_items(rb_menu); }
+
+static VALUE rbncurs_c_item_count(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(item_count(menu));
+}
+static VALUE rbncurs_m_item_count(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_item_count(rb_menu); }
+
+
+/*
+ * Item/menu hook get/set functions - menu_hook(3X) man page
+ */
+static void item_init_hook(MENU *menu)
+{
+ /* Find the Proc object associated with this menu */
+ VALUE proc = get_proc(menu, ITEM_INIT_HOOK);
+
+ if (proc != Qnil)
+ {
+ VALUE rb_menu = wrap_menu(menu);
+ rb_funcall(proc, rb_intern("call"), 1, rb_menu);
+ }
+}
+static VALUE rbncurs_c_set_item_init(VALUE rb_menu, VALUE proc)
+{
+ MENU *menu = NULL;
+
+ if (!rb_obj_is_kind_of(rb_menu, cMENU))
+ rb_raise(rb_eArgError, "arg1 must be a MENU object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ menu = get_menu(rb_menu);
+ reg_proc(menu, ITEM_INIT_HOOK, proc);
+ if (proc != Qnil)
+ return INT2NUM(set_item_init(menu, item_init_hook));
+ else
+ return INT2NUM(set_item_init(menu, NULL));
+}
+static VALUE rbncurs_m_set_item_init(VALUE dummy, VALUE rb_menu, VALUE proc)
+{ return rbncurs_c_set_item_init(rb_menu, proc); }
+
+static VALUE rbncurs_c_item_init(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return get_proc(menu, ITEM_INIT_HOOK);
+}
+static VALUE rbncurs_m_item_init(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_item_init(rb_menu); }
+
+static void item_term_hook(MENU *menu)
+{
+ /* Find the Proc object associated with this menu */
+ VALUE proc = get_proc(menu, ITEM_TERM_HOOK);
+
+ if (proc != Qnil)
+ {
+ VALUE rb_menu = wrap_menu(menu);
+ rb_funcall(proc, rb_intern("call"), 1, rb_menu);
+ }
+}
+static VALUE rbncurs_c_set_item_term(VALUE rb_menu, VALUE proc)
+{
+ MENU *menu = NULL;
+
+ if (!rb_obj_is_kind_of(rb_menu, cMENU))
+ rb_raise(rb_eArgError, "arg1 must be a MENU object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ menu = get_menu(rb_menu);
+ reg_proc(menu, ITEM_TERM_HOOK, proc);
+ if (proc != Qnil)
+ return INT2NUM(set_item_term(menu, item_term_hook));
+ else
+ return INT2NUM(set_item_term(menu, NULL));
+}
+static VALUE rbncurs_m_set_item_term(VALUE dummy, VALUE rb_menu, VALUE proc)
+{ return rbncurs_c_set_item_term(rb_menu, proc); }
+
+static VALUE rbncurs_c_item_term(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return get_proc(menu, ITEM_TERM_HOOK);
+}
+static VALUE rbncurs_m_item_term(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_item_term(rb_menu); }
+
+static void menu_init_hook(MENU *menu)
+{
+ /* Find the Proc object associated with this menu */
+ VALUE proc = get_proc(menu, MENU_INIT_HOOK);
+
+ if (proc != Qnil)
+ {
+ VALUE rb_menu = wrap_menu(menu);
+ rb_funcall(proc, rb_intern("call"), 1, rb_menu);
+ }
+}
+static VALUE rbncurs_c_set_menu_init(VALUE rb_menu, VALUE proc) {
+ MENU *menu = NULL;
+
+ if (!rb_obj_is_kind_of(rb_menu, cMENU))
+ rb_raise(rb_eArgError, "arg1 must be a MENU object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ menu = get_menu(rb_menu);
+ reg_proc(menu, MENU_INIT_HOOK, proc);
+ if (proc != Qnil)
+ return INT2NUM(set_menu_init(menu, menu_init_hook));
+ else
+ return INT2NUM(set_menu_init(menu, NULL));
+}
+static VALUE rbncurs_m_set_menu_init(VALUE dummy, VALUE rb_menu, VALUE proc)
+{ return rbncurs_c_set_menu_init(rb_menu, proc); }
+
+static VALUE rbncurs_c_menu_init(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return get_proc(menu, MENU_INIT_HOOK);
+}
+static VALUE rbncurs_m_menu_init(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_init(rb_menu); }
+
+static void menu_term_hook(MENU *menu)
+{
+ /* Find the Proc object associated with this menu */
+ VALUE proc = get_proc(menu, MENU_TERM_HOOK);
+
+ if (proc != Qnil)
+ {
+ VALUE rb_menu = wrap_menu(menu);
+ rb_funcall(proc, rb_intern("call"), 1, rb_menu);
+ }
+}
+static VALUE rbncurs_c_set_menu_term(VALUE rb_menu, VALUE proc)
+{
+ MENU *menu = NULL;
+
+ if (!rb_obj_is_kind_of(rb_menu, cMENU))
+ rb_raise(rb_eArgError, "arg1 must be a MENU object");
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ menu = get_menu(rb_menu);
+ reg_proc(menu, MENU_TERM_HOOK, proc);
+ if (proc != Qnil)
+ return INT2NUM(set_menu_term(menu, menu_term_hook));
+ else
+ return INT2NUM(set_menu_term(menu, NULL));
+}
+static VALUE rbncurs_m_set_menu_term(VALUE dummy, VALUE rb_menu, VALUE proc)
+{ return rbncurs_c_set_menu_term(rb_menu, proc); }
+
+static VALUE rbncurs_c_menu_term(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return get_proc(menu, MENU_TERM_HOOK);
+}
+static VALUE rbncurs_m_menu_term(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_term(rb_menu); }
+
+
+/*
+ * Item option get/set functions - mitem_opts(3X) man page
+ */
+static VALUE rbncurs_c_set_item_opts(VALUE rb_item, VALUE opts)
+{
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(set_item_opts(item, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_set_item_opts(VALUE dummy, VALUE rb_item, VALUE opts)
+{ return rbncurs_c_set_item_opts(rb_item, opts); }
+
+static VALUE rbncurs_c_item_opts_on(VALUE rb_item, VALUE opts)
+{
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(item_opts_on(item, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_item_opts_on(VALUE dummy, VALUE rb_item, VALUE opts)
+{ return rbncurs_c_item_opts_on(rb_item, opts); }
+
+static VALUE rbncurs_c_item_opts_off(VALUE rb_item, VALUE opts)
+{
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(item_opts_off(item, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_item_opts_off(VALUE dummy, VALUE rb_item, VALUE opts)
+{ return rbncurs_c_item_opts_off(rb_item, opts); }
+
+static VALUE rbncurs_c_item_opts(VALUE rb_item)
+{
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(item_opts(item));
+}
+static VALUE rbncurs_m_item_opts(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_item_opts(rb_item); }
+
+
+/*
+ * Menu option get/set functions - menu_opts(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_opts(VALUE rb_menu, VALUE opts)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_opts(menu, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_set_menu_opts(VALUE dummy, VALUE rb_menu, VALUE opts)
+{ return rbncurs_c_set_menu_opts(rb_menu, opts); }
+
+static VALUE rbncurs_c_menu_opts_on(VALUE rb_menu, VALUE opts)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(menu_opts_on(menu, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_menu_opts_on(VALUE dummy, VALUE rb_menu, VALUE opts)
+{ return rbncurs_c_menu_opts_on(rb_menu, opts); }
+
+static VALUE rbncurs_c_menu_opts_off(VALUE rb_menu, VALUE opts)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(menu_opts_off(menu, NUM2INT(opts)));
+}
+static VALUE rbncurs_m_menu_opts_off(VALUE dummy, VALUE rb_menu, VALUE opts)
+{ return rbncurs_c_menu_opts_off(rb_menu, opts); }
+
+static VALUE rbncurs_c_menu_opts(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(menu_opts(menu));
+}
+static VALUE rbncurs_m_menu_opts(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_opts(rb_menu); }
+
+
+/*
+ * Printable menu request name handling functions - menu_requestname(3X) man page
+ */
+static VALUE rbncurs_c_menu_request_name(VALUE request)
+{
+ return rb_str_new2(menu_request_name(NUM2INT(request)));
+}
+static VALUE rbncurs_m_menu_request_name(VALUE dummy, VALUE request)
+{ return rbncurs_c_menu_request_name(request); }
+
+static VALUE rbncurs_c_menu_request_by_name(VALUE name)
+{
+ return INT2NUM(menu_request_by_name(STR2CSTR(name)));
+}
+static VALUE rbncurs_m_menu_request_by_name(VALUE dummy, VALUE name)
+{ return rbncurs_c_menu_request_by_name(name); }
+
+
+/*
+ * (Sub)window association make/break functions - menu_win(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_win(VALUE rb_menu, VALUE rb_win)
+{
+ MENU *menu = get_menu(rb_menu);
+ WINDOW *win = get_window(rb_win);
+ return INT2NUM(set_menu_win(menu, win));
+}
+static VALUE rbncurs_m_set_menu_win(VALUE dummy, VALUE rb_menu, VALUE rb_win)
+{ return rbncurs_c_set_menu_win(rb_menu, rb_win); }
+
+static VALUE rbncurs_c_menu_win(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return wrap_window(menu_win(menu));
+}
+static VALUE rbncurs_m_menu_win(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_win(rb_menu); }
+
+static VALUE rbncurs_c_set_menu_sub(VALUE rb_menu, VALUE rb_sub)
+{
+ MENU *menu = get_menu(rb_menu);
+ WINDOW *win = get_window(rb_sub);
+ return INT2NUM(set_menu_sub(menu, win));
+}
+static VALUE rbncurs_m_set_menu_sub(VALUE dummy, VALUE rb_menu, VALUE rb_sub)
+{ return rbncurs_c_set_menu_sub(rb_menu, rb_sub); }
+
+static VALUE rbncurs_c_menu_sub(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return wrap_window(menu_sub(menu));
+}
+static VALUE rbncurs_m_menu_sub(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_sub(rb_menu); }
+
+static VALUE rbncurs_c_scale_menu(VALUE rb_menu, VALUE rows, VALUE columns)
+{
+ MENU *menu = get_menu(rb_menu);
+
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
+ rb_obj_is_instance_of(columns, rb_cArray) != Qtrue)
+ {
+ rb_raise(rb_eArgError, "rows and columns arguments must be empty Arrays");
+ return Qnil;
+ }
+ else
+ {
+ int vals[2] = {0,0};
+ int result = scale_menu(menu, &vals[0],&vals[1]);
+
+ rb_ary_push(rows, INT2NUM(vals[0]));
+ rb_ary_push(columns, INT2NUM(vals[1]));
+ return INT2NUM(result);
+ }
+}
+static VALUE rbncurs_m_scale_menu(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE columns)
+{ return rbncurs_c_scale_menu(rb_menu, rows, columns); }
+
+
+/*
+ * Menu cursor positioning functions - menu_cursor(3X) man page
+ */
+static VALUE rbncurs_c_pos_menu_cursor(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(pos_menu_cursor(menu));
+}
+static VALUE rbncurs_m_pos_menu_cursor(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_pos_menu_cursor(rb_menu); }
+
+
+/*
+ * Item name/description retrieval functions - mitem_name(3X) man page
+ */
+static VALUE rbncurs_c_item_name(VALUE rb_item)
+{
+ ITEM *item = get_item(rb_item);
+ return rb_str_new2(item_name(item));
+}
+static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_item_name(rb_item); }
+
+static VALUE rbncurs_c_item_description(VALUE rb_item)
+{
+ ITEM *item = get_item(rb_item);
+ return rb_str_new2(item_description(item));
+}
+static VALUE rbncurs_m_item_description(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_item_description(rb_item); }
+
+
+/*
+ * Item value get/set functions - mitem_value(3X) man page
+ */
+static VALUE rbncurs_c_set_item_value(VALUE rb_item, VALUE value)
+{
+ ITEM *item = get_item(rb_item);
+ return INT2NUM(set_item_value(item, RTEST(value)));
+}
+static VALUE rbncurs_m_set_item_value(VALUE dummy, VALUE rb_item, VALUE value)
+{ return rbncurs_c_set_item_value(rb_item, value); }
+
+static VALUE rbncurs_c_item_value(VALUE rb_item)
+{
+ ITEM *item = get_item(rb_item);
+ return (item_value(item)) ? Qtrue: Qfalse;
+}
+static VALUE rbncurs_m_item_value(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_item_value(rb_item); }
+
+
+/*
+ * Item visibility retrieval function - mitem_visible(3X) man page
+ */
+static VALUE rbncurs_c_item_visible(VALUE rb_item)
+{
+ ITEM *item = get_item(rb_item);
+ return (item_visible(item)) ? Qtrue: Qfalse;
+}
+static VALUE rbncurs_m_item_visible(VALUE dummy, VALUE rb_item)
+{ return rbncurs_c_item_visible(rb_item); }
+
+
+/*
+ * Menu attribute get/set functions - menu_attributes(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_fore(VALUE rb_menu, VALUE attr)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_fore(menu, NUM2ULONG(attr)));
+}
+static VALUE rbncurs_m_set_menu_fore(VALUE dummy, VALUE rb_menu, VALUE attr)
+{ return rbncurs_c_set_menu_fore(rb_menu, attr); }
+
+static VALUE rbncurs_c_menu_fore(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return ULONG2NUM(menu_fore(menu));
+}
+static VALUE rbncurs_m_menu_fore(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_fore(rb_menu); }
+
+static VALUE rbncurs_c_set_menu_back(VALUE rb_menu, VALUE attr)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_back(menu, NUM2ULONG(attr)));
+}
+static VALUE rbncurs_m_set_menu_back(VALUE dummy, VALUE rb_menu, VALUE attr)
+{ return rbncurs_c_set_menu_back(rb_menu, attr); }
+
+static VALUE rbncurs_c_menu_back(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return ULONG2NUM(menu_back(menu));
+}
+static VALUE rbncurs_m_menu_back(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_back(rb_menu); }
+
+static VALUE rbncurs_c_set_menu_grey(VALUE rb_menu, VALUE attr)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_grey(menu, NUM2ULONG(attr)));
+}
+static VALUE rbncurs_m_set_menu_grey(VALUE dummy, VALUE rb_menu, VALUE attr)
+{ return rbncurs_c_set_menu_grey(rb_menu, attr); }
+
+static VALUE rbncurs_c_menu_grey(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return ULONG2NUM(menu_grey(menu));
+}
+static VALUE rbncurs_m_menu_grey(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_grey(rb_menu); }
+
+static VALUE rbncurs_c_set_menu_pad(VALUE rb_menu, VALUE pad)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_pad(menu, NUM2INT(pad)));
+}
+static VALUE rbncurs_m_set_menu_pad(VALUE dummy, VALUE rb_menu, VALUE pad)
+{ return rbncurs_c_set_menu_pad(rb_menu, pad); }
+
+static VALUE rbncurs_c_menu_pad(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(menu_pad(menu));
+}
+static VALUE rbncurs_m_menu_pad(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_pad(rb_menu); }
+
+
+/*
+ * Menu format get/set functions - menu_format(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_format(menu, NUM2INT(rows), NUM2INT(cols)));
+}
+static VALUE rbncurs_m_set_menu_format(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE cols)
+{ return rbncurs_c_set_menu_format(rb_menu, rows, cols); }
+
+static VALUE rbncurs_c_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
+{
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
+ rb_obj_is_instance_of(cols, rb_cArray) != Qtrue)
+ {
+ rb_raise(rb_eArgError, "rows and cols arguments must be empty Arrays");
+ return Qnil;
+ }
+ else
+ {
+ MENU *menu = get_menu(rb_menu);
+ int vals[2] = {0,0};
+
+ menu_format(menu, &vals[0], &vals[1]);
+ rb_ary_push(rows, INT2NUM(vals[0]));
+ rb_ary_push(cols, INT2NUM(vals[1]));
+ return Qnil;
+ }
+}
+static VALUE rbncurs_m_menu_format(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE cols)
+{ return rbncurs_c_menu_format(rb_menu, rows, cols); }
+
+
+/*
+ * Menu mark get/set functions - menu_mark(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_mark(VALUE rb_menu, VALUE value)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_mark(menu, STR2CSTR(value)));
+}
+static VALUE rbncurs_m_set_menu_mark(VALUE dummy, VALUE rb_field, VALUE value)
+{ return rbncurs_c_set_menu_mark(rb_field, value); }
+
+static VALUE rbncurs_c_menu_mark(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return rb_str_new2(menu_mark(menu));
+}
+static VALUE rbncurs_m_menu_mark(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_mark(rb_menu); }
+
+
+/*
+ * Menu pattern get/set functions - menu_pattern(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_pattern(VALUE rb_menu, VALUE pattern)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_pattern(menu, STR2CSTR(pattern)));
+}
+static VALUE rbncurs_m_set_menu_pattern(VALUE dummy, VALUE rb_menu, VALUE pattern)
+{ return rbncurs_c_set_menu_pattern(rb_menu, pattern); }
+
+static VALUE rbncurs_c_menu_pattern(VALUE rb_menu)
+{
+ MENU *menu = get_menu(rb_menu);
+ return rb_str_new2(menu_pattern(menu));
+}
+static VALUE rbncurs_m_menu_pattern(VALUE dummy, VALUE rb_menu)
+{ return rbncurs_c_menu_pattern(rb_menu); }
+
+
+/*
+ * Menu spacing get/set functions - menu_spacing(3X) man page
+ */
+static VALUE rbncurs_c_set_menu_spacing(VALUE rb_menu, VALUE spc_description,
+ VALUE spc_rows, VALUE spc_cols)
+{
+ MENU *menu = get_menu(rb_menu);
+ return INT2NUM(set_menu_spacing(menu, NUM2INT(spc_description),
+ NUM2INT(spc_rows), NUM2INT(spc_cols)));
+}
+static VALUE rbncurs_m_set_menu_spacing(VALUE dummy, VALUE rb_menu, VALUE spc_description,
+ VALUE spc_rows, VALUE spc_cols)
+{ return rbncurs_c_set_menu_spacing(rb_menu, spc_description, spc_rows, spc_cols); }
+
+static VALUE rbncurs_c_menu_spacing(VALUE rb_menu, VALUE spc_description,
+ VALUE spc_rows, VALUE spc_cols)
+{
+ if (rb_obj_is_instance_of(spc_description, rb_cArray) != Qtrue ||
+ rb_obj_is_instance_of(spc_rows, rb_cArray) != Qtrue ||
+ rb_obj_is_instance_of(spc_cols, rb_cArray) != Qtrue)
+ {
+ rb_raise(rb_eArgError, "spc_description, spc_rows, and spc_cols arguments must be empty Arrays");
+ return Qnil;
+ }
+ else
+ {
+ MENU *menu = get_menu(rb_menu);
+ int vals[3] = {0,0,0};
+
+ int result = menu_spacing(menu, &vals[0], &vals[1], &vals[2]);
+ rb_ary_push(spc_description, INT2NUM(vals[0]));
+ rb_ary_push(spc_rows, INT2NUM(vals[1]));
+ rb_ary_push(spc_cols, INT2NUM(vals[2]));
+ return INT2NUM(result);
+ }
+}
+static VALUE rbncurs_m_menu_spacing(VALUE dummy, VALUE rb_menu, VALUE spc_description,
+ VALUE spc_rows, VALUE spc_cols)
+{ return rbncurs_c_menu_spacing(rb_menu, spc_description, spc_rows, spc_cols); }
+
+
+/*
+ * Menu initialization function
+ */
+void init_menu(void)
+{
+ mMenu = rb_define_module_under(mNcurses, "Menu");
+
+ MENU_SNG_FUNC(current_item, 1);
+ MENU_SNG_FUNC(free_item, 1);
+ MENU_SNG_FUNC(free_menu, 1);
+ MENU_SNG_FUNC(item_count, 1);
+ MENU_SNG_FUNC(item_description, 1);
+ MENU_SNG_FUNC(item_index, 1);
+ MENU_SNG_FUNC(item_init, 1);
+ MENU_SNG_FUNC(item_name, 1);
+ MENU_SNG_FUNC(item_opts, 1);
+ MENU_SNG_FUNC(item_opts_off, 2);
+ MENU_SNG_FUNC(item_opts_on, 2);
+ MENU_SNG_FUNC(item_term, 1);
+ /* MENU_SNG_FUNC(item_userptr, 1); */
+ MENU_SNG_FUNC(item_value, 1);
+ MENU_SNG_FUNC(item_visible, 1);
+ MENU_SNG_FUNC(menu_back, 1);
+ MENU_SNG_FUNC(menu_driver, 2);
+ MENU_SNG_FUNC(menu_fore, 1);
+ MENU_SNG_FUNC(menu_format, 3);
+ MENU_SNG_FUNC(menu_grey, 1);
+ MENU_SNG_FUNC(menu_init, 1);
+ MENU_SNG_FUNC(menu_items, 1);
+ MENU_SNG_FUNC(menu_mark, 1);
+ MENU_SNG_FUNC(menu_opts, 1);
+ MENU_SNG_FUNC(menu_opts_off, 2);
+ MENU_SNG_FUNC(menu_opts_on, 2);
+ MENU_SNG_FUNC(menu_pad, 1);
+ MENU_SNG_FUNC(menu_pattern, 1);
+ MENU_SNG_FUNC(menu_request_by_name, 1);
+ MENU_SNG_FUNC(menu_request_name, 1);
+ MENU_SNG_FUNC(menu_sub, 1);
+ MENU_SNG_FUNC(menu_spacing, 4);
+ MENU_SNG_FUNC(menu_term, 1);
+ /* MENU_SNG_FUNC(menu_userptr, 1); */
+ MENU_SNG_FUNC(menu_win, 1);
+ MENU_SNG_FUNC(new_item, 2);
+ MENU_SNG_FUNC(new_menu, 1);
+ MENU_SNG_FUNC(pos_menu_cursor, 1);
+ MENU_SNG_FUNC(post_menu, 1);
+ MENU_SNG_FUNC(scale_menu, 3);
+ MENU_SNG_FUNC(set_current_item, 2);
+ MENU_SNG_FUNC(set_item_init, 2);
+ MENU_SNG_FUNC(set_item_opts, 2);
+ MENU_SNG_FUNC(set_item_term, 2);
+ /* MENU_SNG_FUNC(set_item_userptr, 2); */
+ MENU_SNG_FUNC(set_item_value, 2);
+ MENU_SNG_FUNC(set_menu_back, 2);
+ MENU_SNG_FUNC(set_menu_fore, 2);
+ MENU_SNG_FUNC(set_menu_format, 3);
+ MENU_SNG_FUNC(set_menu_grey, 2);
+ MENU_SNG_FUNC(set_menu_init, 2);
+ MENU_SNG_FUNC(set_menu_items, 2);
+ MENU_SNG_FUNC(set_menu_mark, 2);
+ MENU_SNG_FUNC(set_menu_opts, 2);
+ MENU_SNG_FUNC(set_menu_pad, 2);
+ MENU_SNG_FUNC(set_menu_pattern, 2);
+ MENU_SNG_FUNC(set_menu_sub, 2);
+ MENU_SNG_FUNC(set_menu_spacing, 4);
+ MENU_SNG_FUNC(set_menu_term, 2);
+ /* MENU_SNG_FUNC(set_menu_userptr, 2); */
+ MENU_SNG_FUNC(set_menu_win, 2);
+ MENU_SNG_FUNC(set_top_row, 2);
+ MENU_SNG_FUNC(top_row, 1);
+ MENU_SNG_FUNC(unpost_menu, 1);
+
+ init_menu_err_codes();
+ init_menu_req_constants();
+ init_menu_opts_constants();
+ init_item_opts_constants();
+
+ /* Hashes to store registered blocks (Proc) */
+ {
+ VALUE hashes = rb_iv_set(mMenu, "@proc_hashes", rb_ary_new());
+ int i;
+
+ for (i = 0; i < PROC_HASHES_COUNT; i++)
+ rb_ary_push(hashes, rb_hash_new());
+ }
+
+ /* Menus */
+ rb_iv_set(mMenu, "@menus_hash", rb_hash_new());
+ cMENU = rb_define_class_under(mMenu, "MENU", rb_cObject);
+ rb_define_singleton_method(cMENU, "new", (&rbncurs_m_new_menu), 1);
+
+ RB_CLASS_METH(cMENU, NULL, current_item, 0);
+ RB_CLASS_METH(cMENU, "free", free_menu, 0);
+ RB_CLASS_METH(cMENU, NULL, item_count, 0);
+ RB_CLASS_METH(cMENU, NULL, item_init, 0);
+ RB_CLASS_METH(cMENU, NULL, item_term, 0);
+ RB_CLASS_METH(cMENU, "back", menu_back, 0);
+ RB_CLASS_METH(cMENU, "driver", menu_driver, 1);
+ RB_CLASS_METH(cMENU, "fore", menu_fore, 0);
+ RB_CLASS_METH(cMENU, "format", menu_format, 2);
+ RB_CLASS_METH(cMENU, "grey", menu_grey, 0);
+ RB_CLASS_METH(cMENU, "init", menu_init, 0);
+ RB_CLASS_METH(cMENU, "items", menu_items, 0);
+ RB_CLASS_METH(cMENU, "mark", menu_mark, 0);
+ RB_CLASS_METH(cMENU, "opts", menu_opts, 0);
+ RB_CLASS_METH(cMENU, "opts_off", menu_opts_off, 1);
+ RB_CLASS_METH(cMENU, "opts_on", menu_opts_on, 1);
+ RB_CLASS_METH(cMENU, "pad", menu_pad, 0);
+ RB_CLASS_METH(cMENU, "pattern", menu_pattern, 0);
+ RB_CLASS_METH(cMENU, "sub", menu_sub, 0);
+ RB_CLASS_METH(cMENU, "spacing", menu_spacing, 3);
+ RB_CLASS_METH(cMENU, "term", menu_term, 0);
+ /* RB_CLASS_METH(cMENU, "userptr", menu_userptr, 0); */
+ RB_CLASS_METH(cMENU, "win", menu_win, 0);
+ RB_CLASS_METH(cMENU, "pos_cursor", pos_menu_cursor, 0);
+ RB_CLASS_METH(cMENU, "post", post_menu, 0);
+ RB_CLASS_METH(cMENU, "scale", scale_menu, 2);
+ RB_CLASS_METH(cMENU, "current_item=", set_current_item, 1);
+ RB_CLASS_METH(cMENU, "item_init=", set_item_init, 1);
+ RB_CLASS_METH(cMENU, "item_term=", set_item_term, 1);
+ RB_CLASS_METH(cMENU, "back=", set_menu_back, 1);
+ RB_CLASS_METH(cMENU, "fore=", set_menu_fore, 1);
+ RB_CLASS_METH(cMENU, "set_format", set_menu_format, 2);
+ RB_CLASS_METH(cMENU, "grey=", set_menu_grey, 1);
+ RB_CLASS_METH(cMENU, "init=", set_menu_init, 1);
+ RB_CLASS_METH(cMENU, "items=", set_menu_items, 1);
+ RB_CLASS_METH(cMENU, "mark=", set_menu_mark, 1);
+ RB_CLASS_METH(cMENU, "opts=", set_menu_opts, 1);
+ RB_CLASS_METH(cMENU, "pad=", set_menu_pad, 1);
+ RB_CLASS_METH(cMENU, "pattern=", set_menu_pattern, 1);
+ RB_CLASS_METH(cMENU, "sub=", set_menu_sub, 1);
+ RB_CLASS_METH(cMENU, "set_spacing", set_menu_spacing, 3);
+ RB_CLASS_METH(cMENU, "term=", set_menu_term, 1);
+ /* RB_CLASS_METH(cMENU, "userptr=", set_menu_userptr, 1); */
+ RB_CLASS_METH(cMENU, "win=", set_menu_win, 1);
+ RB_CLASS_METH(cMENU, "top_row=", set_top_row, 1);
+ RB_CLASS_METH(cMENU, NULL, top_row, 0);
+ RB_CLASS_METH(cMENU, "unpost", unpost_menu, 0);
+
+ /* Items */
+ rb_iv_set(mMenu, "@items_hash", rb_hash_new());
+ cITEM = rb_define_class_under(mMenu, "ITEM", rb_cObject);
+ rb_define_singleton_method(cITEM, "new", (&rbncurs_m_new_item), 2);
+
+ RB_CLASS_METH(cITEM, "free", free_item, 0);
+ RB_CLASS_METH(cITEM, "description", item_description, 0);
+ RB_CLASS_METH(cITEM, "index", item_index, 0);
+ RB_CLASS_METH(cITEM, "name", item_name, 0);
+ RB_CLASS_METH(cITEM, "opts", item_opts, 0);
+ RB_CLASS_METH(cITEM, "opts_off", item_opts_off, 1);
+ RB_CLASS_METH(cITEM, "opts_on", item_opts_on, 1);
+ /* RB_CLASS_METH(cITEM, "userptr", item_userptr, 0); */
+ RB_CLASS_METH(cITEM, "value", item_value, 0);
+ RB_CLASS_METH(cITEM, "visible?", item_visible, 0);
+ RB_CLASS_METH(cITEM, "opts=", set_item_opts, 1);
+ /* RB_CLASS_METH(cITEM, "userptr=", set_item_userptr, 1); */
+ RB_CLASS_METH(cITEM, "value=", set_item_value, 1);
+}
+
+#endif
diff --git a/menu_wrap.h b/menu_wrap.h
@@ -0,0 +1,49 @@
+/*
+ * This is a curses menu wrapper as part of ncurses-ruby.
+ * It borrows heavily from form_wrap.h.
+ * Contributed by Earle Clubb <eclubb@valcom.com>
+ * Valcom Inc. <http://www.valcom.com>
+ * Copyright 2007
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#if !defined(MENU_HH) && defined(HAVE_MENU_H)
+#define MENU_HH
+
+#include <menu.h>
+#include <ruby.h>
+
+extern VALUE mMenu;
+extern VALUE cITEM;
+extern VALUE cMENU;
+
+#define MENU_DEF_CONST(name) \
+ rb_define_const(mMenu, #name, INT2NUM(name));
+
+#define MENU_SNG_FUNC(name, nargs) \
+ rb_define_singleton_method(mMenu, #name, &rbncurs_m_ ## name, nargs)
+
+#define RB_CLASS_METH(class, alt_name, name, nargs) \
+ rb_define_method(class, #name, (&rbncurs_c_ ## name), nargs); \
+ if (alt_name != NULL) \
+ rb_define_method(class, alt_name, (&rbncurs_c_ ## name), nargs); \
+
+//void init_menu_req_constants(void);
+//void init_menu_opts_constants(void);
+void init_menu(void);
+
+#endif
diff --git a/ncurses_wrap.c b/ncurses_wrap.c
@@ -0,0 +1,2768 @@
+/*
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
+ * (C) 2002, 2003, 2004 Tobias Peters <t-peters@berlios.de>
+ * (C) 2004 Simon Kaczor <skaczor@cox.net>
+ * (C) 2005 2006 2009 Tobias Herzke
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: ncurses_wrap.c,v 1.18 2009/07/31 10:49:24 t-peters Exp $
+ *
+ * This file was adapted from the original ncurses header file which
+ * has the following copyright statements:
+ */
+
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ NOT IMPLEMENTED:
+ - terminfo, termcap-functions
+ - rippoffline
+ - v*printw functions (but normal printw functions are supported!)
+*/
+
+#include "ncurses_wrap.h"
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+VALUE mNcurses; /* module Ncurses */
+VALUE cWINDOW; /* class Ncurses::WINDOW */
+VALUE cSCREEN; /* class Ncurses::SCREEN */
+VALUE eNcurses; /* Ncurses::Exception thrown by this extension */
+
+static void Init_ncurses_full(void);
+
+static
+void
+init_constants_1(void)
+{
+#ifdef CURSES
+ rb_define_const(mNcurses, "CURSES", INT2NUM((int)(CURSES)));
+#endif
+#ifdef CURSES_H
+ rb_define_const(mNcurses, "CURSES_H", INT2NUM((int)(CURSES_H)));
+#endif
+#ifdef NCURSES_VERSION_MAJOR
+ rb_define_const(mNcurses, "NCURSES_VERSION_MAJOR",
+ INT2NUM((int)(NCURSES_VERSION_MAJOR)));
+#endif
+#ifdef NCURSES_VERSION_MINOR
+ rb_define_const(mNcurses, "NCURSES_VERSION_MINOR",
+ INT2NUM((int)(NCURSES_VERSION_MINOR)));
+#endif
+#ifdef NCURSES_VERSION_PATCH
+ rb_define_const(mNcurses, "NCURSES_VERSION_PATCH",
+ INT2NUM((int)(NCURSES_VERSION_PATCH)));
+#endif
+#ifdef NCURSES_VERSION
+ rb_define_const(mNcurses, "NCURSES_VERSION",
+ rb_str_new2(NCURSES_VERSION));
+#endif
+
+ /* attributes */
+#ifdef WA_ATTRIBUTES
+ rb_define_const(mNcurses, "WA_ATTRIBUTES", INT2NUM(WA_ATTRIBUTES));
+ rb_define_const(mNcurses, "WA_NORMAL", INT2NUM(WA_NORMAL));
+ rb_define_const(mNcurses, "WA_STANDOUT", INT2NUM(WA_STANDOUT));
+ rb_define_const(mNcurses, "WA_UNDERLINE", INT2NUM(WA_UNDERLINE));
+ rb_define_const(mNcurses, "WA_REVERSE", INT2NUM(WA_REVERSE));
+ rb_define_const(mNcurses, "WA_BLINK", INT2NUM(WA_BLINK));
+ rb_define_const(mNcurses, "WA_DIM", INT2NUM(WA_DIM));
+ rb_define_const(mNcurses, "WA_BOLD", INT2NUM(WA_BOLD));
+ rb_define_const(mNcurses, "WA_ALTCHARSET", INT2NUM(WA_ALTCHARSET));
+ rb_define_const(mNcurses, "WA_INVIS", INT2NUM(WA_INVIS));
+ rb_define_const(mNcurses, "WA_PROTECT", INT2NUM(WA_PROTECT));
+ rb_define_const(mNcurses, "WA_HORIZONTAL", INT2NUM(WA_HORIZONTAL));
+ rb_define_const(mNcurses, "WA_LEFT", INT2NUM(WA_LEFT));
+ rb_define_const(mNcurses, "WA_LOW", INT2NUM(WA_LOW));
+ rb_define_const(mNcurses, "WA_RIGHT", INT2NUM(WA_RIGHT));
+ rb_define_const(mNcurses, "WA_TOP", INT2NUM(WA_TOP));
+ rb_define_const(mNcurses, "WA_VERTICAL", INT2NUM(WA_VERTICAL));
+#endif
+
+ /* locale flags */
+#ifdef HAVE_LOCALE_H
+ rb_define_const(mNcurses, "LC_ALL", INT2NUM(LC_ALL));
+ rb_define_const(mNcurses, "LC_COLLATE", INT2NUM(LC_COLLATE));
+ rb_define_const(mNcurses, "LC_CTYPE", INT2NUM(LC_CTYPE));
+ rb_define_const(mNcurses, "LC_MESSAGES", INT2NUM(LC_MESSAGES));
+ rb_define_const(mNcurses, "LC_MONETARY", INT2NUM(LC_MONETARY));
+ rb_define_const(mNcurses, "LC_NUMERIC", INT2NUM(LC_NUMERIC));
+ rb_define_const(mNcurses, "LC_TIME", INT2NUM(LC_TIME));
+#endif
+}
+
+static VALUE rbncurs_COLORS()
+{return INT2NUM(COLORS);}
+static VALUE rbncurs_COLOR_PAIRS()
+{return INT2NUM(COLOR_PAIRS);}
+
+static
+void
+init_globals_1(void)
+{
+ /* colors */
+ NCFUNC(COLORS, 0);
+ NCFUNC(COLOR_PAIRS, 0);
+}
+static
+void
+init_constants_2(void)
+{
+ rb_define_const(mNcurses, "COLOR_BLACK", INT2NUM(COLOR_BLACK));
+ rb_define_const(mNcurses, "COLOR_RED", INT2NUM(COLOR_RED));
+ rb_define_const(mNcurses, "COLOR_GREEN", INT2NUM(COLOR_GREEN));
+ rb_define_const(mNcurses, "COLOR_YELLOW", INT2NUM(COLOR_YELLOW));
+ rb_define_const(mNcurses, "COLOR_BLUE", INT2NUM(COLOR_BLUE));
+ rb_define_const(mNcurses, "COLOR_MAGENTA", INT2NUM(COLOR_MAGENTA));
+ rb_define_const(mNcurses, "COLOR_CYAN", INT2NUM(COLOR_CYAN));
+ rb_define_const(mNcurses, "COLOR_WHITE", INT2NUM(COLOR_WHITE));
+
+ rb_define_const(mNcurses, "ERR", INT2NUM(ERR));
+ rb_define_const(mNcurses, "OK", INT2NUM(OK));
+
+ /* values for the _flags member */
+#ifdef _SUBWIN
+ rb_define_const(mNcurses, "SUBWIN", INT2NUM(_SUBWIN));
+#endif
+#ifdef _ENDLINE
+ rb_define_const(mNcurses, "ENDLINE", INT2NUM(_ENDLINE));
+#endif
+#ifdef _FULLWIN
+ rb_define_const(mNcurses, "FULLWIN", INT2NUM(_FULLWIN));
+#endif
+#ifdef _SCROLLWIN
+ rb_define_const(mNcurses, "SCROLLWIN", INT2NUM(_SCROLLWIN));
+#endif
+#ifdef _ISPAD
+ rb_define_const(mNcurses, "ISPAD", INT2NUM(_ISPAD));
+#endif
+#ifdef _HASMOVED
+ rb_define_const(mNcurses, "HASMOVED", INT2NUM(_HASMOVED));
+#endif
+#ifdef _WRAPPED
+ rb_define_const(mNcurses, "WRAPPED", INT2NUM(_WRAPPED));
+#endif
+
+#ifdef _NOCHANGE
+ /*
+ * this value is used in the firstchar and lastchar fields to mark
+ * unchanged lines
+ */
+ rb_define_const(mNcurses, "NOCHANGE", INT2NUM(_NOCHANGE));
+#endif
+#ifdef _NEWINDEX
+ /*
+ * this value is used in the oldindex field to mark lines created by
+ * insertions and scrolls.
+ */
+ rb_define_const(mNcurses, "NEWINDEX", INT2NUM(_NEWINDEX));
+#endif
+#ifdef CCHARW_MAX
+ rb_define_const(mNcurses, "CCHARW_MAX", INT2NUM(CCHARW_MAX));
+#endif
+}
+
+/// Portable (1.8,1.9) determination of array length (calling #length)
+long rbncurs_array_length(VALUE array)
+{
+ return NUM2LONG(rb_funcall(array, rb_intern("length"), 0));
+}
+
+VALUE wrap_window(WINDOW* window)
+{
+ if (window == 0) return Qnil;
+ {
+ VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash");
+ VALUE window_adress = INT2NUM((long)(window));
+ VALUE rb_window = rb_hash_aref(windows_hash, window_adress);
+ if (rb_window == Qnil) {
+ rb_window = Data_Wrap_Struct(cWINDOW, 0, 0, window);
+ rb_iv_set(rb_window, "@destroyed", Qfalse);
+ rb_hash_aset(windows_hash, window_adress, rb_window);
+ }
+ return rb_window;
+ }
+}
+WINDOW* get_window(VALUE rb_window)
+{
+ WINDOW* window;
+ if (rb_window == Qnil) return 0;
+ if (rb_iv_get(rb_window, "@destroyed") == Qtrue) {
+ rb_raise(eNcurses, "Attempt to access a destroyed window");
+ return 0;
+ }
+ Data_Get_Struct(rb_window, WINDOW, window);
+ return window;
+}
+static VALUE rbncurs_delwin(VALUE dummy, VALUE arg1) {
+ VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash");
+ WINDOW* window = get_window(arg1);
+ VALUE window_adress = INT2NUM((long)(window));
+ rb_funcall(windows_hash, rb_intern("delete"), 1, window_adress);
+ rb_iv_set(arg1, "@destroyed", Qtrue);
+ return INT2NUM(delwin(window));
+}
+
+static VALUE wrap_screen(SCREEN* screen)
+{
+ if (screen == 0) return Qnil;
+ {
+ VALUE screens_hash = rb_iv_get(mNcurses, "@screens_hash");
+ VALUE screen_adress = INT2NUM((long)(screen));
+ VALUE rb_screen = rb_hash_aref(screens_hash, screen_adress);
+ if (rb_screen == Qnil) {
+ rb_screen = Data_Wrap_Struct(cSCREEN, 0, 0, screen);
+ rb_iv_set(rb_screen, "@destroyed", Qfalse);
+ rb_hash_aset(screens_hash, screen_adress, rb_screen);
+ }
+ return rb_screen;
+ }
+}
+static SCREEN* get_screen(VALUE rb_screen)
+{
+ SCREEN* screen;
+ if (rb_screen == Qnil) return 0;
+ if (rb_iv_get(rb_screen, "@destroyed") == Qtrue) {
+ rb_raise(eNcurses, "Attempt to access a destroyed screen");
+ return 0;
+ }
+ Data_Get_Struct(rb_screen, SCREEN, screen);
+ return screen;
+}
+#ifdef HAVE_DELSCREEN
+static VALUE rbncurs_delscreen(VALUE dummy, VALUE arg1) {
+ VALUE screens_hash = rb_iv_get(mNcurses, "@screens_hash");
+ SCREEN* screen = get_screen(arg1);
+ VALUE screen_adress = INT2NUM((long)(screen));
+ rb_funcall(screens_hash, rb_intern("delete"), 1, screen_adress);
+ rb_iv_set(arg1, "@destroyed", Qtrue);
+ delscreen(screen);
+ return Qnil;
+}
+#endif
+static VALUE rbncurs_winchnstr(VALUE dummy, VALUE rb_win, VALUE rb_str, VALUE rb_n)
+{
+ if (rb_obj_is_instance_of(rb_str, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError, "2nd argument must be an empty Array");
+ return Qnil;
+ }
+
+ {
+ WINDOW * window = get_window(rb_win);
+ int n = NUM2INT(rb_n);
+ chtype * str = ALLOC_N(chtype, n + 1);
+ int return_value;
+ return_value = winchnstr(window, str, n);
+ if (return_value != ERR) {
+ int i;
+ for (i = 0; i < return_value; ++i) {
+ rb_ary_push(rb_str, INT2NUM(str[i]));
+ }
+ }
+ xfree(str);
+ return INT2NUM(return_value);
+ }
+}
+static VALUE rbncurs_wgetnstr(VALUE dummy, VALUE rb_win, VALUE rb_chstr, VALUE rb_n)
+{
+ WINDOW * window = get_window(rb_win);
+ int n = NUM2INT(rb_n);
+ char * str = ALLOC_N(char, n + 1);
+ int return_value;
+ return_value = wgetnstr(window, str, n);
+ if (return_value != ERR) {
+ rb_str_cat2(rb_chstr, str);
+ }
+ xfree(str);
+ return INT2NUM(return_value);
+}
+static VALUE rbncurs_winnstr(VALUE dummy, VALUE rb_win, VALUE rb_chstr, VALUE rb_n)
+{
+ WINDOW * window = get_window(rb_win);
+ int n = NUM2INT(rb_n);
+ char* str = ALLOC_N(char, n + 1);
+ int return_value;
+ return_value = winnstr(window, str, n);
+ if (return_value != ERR) {
+ rb_str_cat(rb_chstr, str, return_value);
+ }
+ xfree(str);
+ return INT2NUM(return_value);
+}
+
+#ifdef HAVE_PANEL_H
+#include "panel_wrap.h" /* needs access to mNcurses, wrap_window, get_window */
+#endif
+
+#ifdef HAVE_FORM_H
+#include "form_wrap.h" /* needs init_form */
+#endif
+
+#ifdef HAVE_MENU_H
+#include "menu_wrap.h" /* needs init_menu */
+#endif
+
+static
+void
+init_functions_0(void)
+{
+#ifdef HAVE_DELSCREEN
+ NCFUNC(delscreen, 1);
+#endif
+ NCFUNC(delwin, 1);
+ NCFUNC(winchnstr, 3);
+ NCFUNC(winnstr, 3);
+ NCFUNC(wgetnstr, 3);
+}
+
+static VALUE get_stdscr()
+{
+ VALUE rb_stdscr = rb_iv_get(mNcurses, "@stdscr");
+ if (rb_stdscr == Qnil) {
+ rb_stdscr = wrap_window(stdscr);
+ rb_iv_set(mNcurses, "@stdscr", rb_stdscr);
+ }
+ return rb_stdscr;
+}
+static VALUE get_curscr()
+{
+ VALUE rb_curscr = rb_iv_get(mNcurses, "@curscr");
+ if (rb_curscr == Qnil) {
+ rb_curscr = wrap_window(curscr);
+ rb_iv_set(mNcurses, "@curscr", rb_curscr);
+ }
+ return rb_curscr;
+}
+#ifdef HAVE_NEWSCR
+static VALUE get_newscr()
+{
+ VALUE rb_newscr = rb_iv_get(mNcurses, "@newscr");
+ if (rb_newscr == Qnil) {
+ rb_newscr = wrap_window(newscr);
+ rb_iv_set(mNcurses, "@newscr", rb_newscr);
+ }
+ return rb_newscr;
+}
+#endif
+static VALUE get_LINES() {return INT2NUM(LINES);}
+static VALUE get_COLS() {return INT2NUM(COLS);}
+#ifdef HAVE_TABSIZE
+static VALUE get_TABSIZE() {return INT2NUM(TABSIZE);}
+#endif
+#ifdef HAVE_ESCDELAY
+/* This global was an undocumented feature under AIX curses. */
+/* ESC expire time in milliseconds */
+static VALUE get_ESCDELAY(){return INT2NUM(ESCDELAY);}
+static VALUE set_ESCDELAY(VALUE dummy, VALUE new_delay)
+{
+ ESCDELAY=NUM2INT(new_delay);
+ return INT2NUM(ESCDELAY);
+}
+#endif
+
+/* This global is wrapper-specific. It denotes the interval after which the
+ terminal is periodically checked for having resized or not. */
+/* time in milliseconds */
+static VALUE get_RESIZEDELAY(){return rb_iv_get(mNcurses, "@resize_delay");}
+static VALUE set_RESIZEDELAY(VALUE dummy, VALUE rb_new_delay)
+{
+ int c_new_delay = NUM2INT(rb_new_delay);
+ if (c_new_delay <= 0)
+ rb_raise(rb_eArgError, "delay must be > 0");
+ rb_new_delay = INT2NUM(c_new_delay);
+ rb_iv_set(mNcurses, "@resize_delay", rb_new_delay);
+ return rb_new_delay ;
+}
+
+static
+void
+init_globals_2(void)
+{
+ rb_iv_set(mNcurses, "@stdscr", Qnil);
+ rb_iv_set(mNcurses, "@curscr", Qnil);
+ rb_iv_set(mNcurses, "@newscr", Qnil);
+
+ rb_define_module_function(mNcurses, "stdscr",
+ (&get_stdscr), 0);
+ rb_define_module_function(mNcurses, "curscr",
+ (&get_curscr), 0);
+#ifdef HAVE_NEWSCR
+ rb_define_module_function(mNcurses, "newscr",
+ (&get_newscr), 0);
+#endif
+ rb_define_module_function(mNcurses, "LINES",
+ (&get_LINES), 0);
+ rb_define_module_function(mNcurses, "COLS",
+ (&get_COLS), 0);
+#ifdef HAVE_TABSIZE
+ rb_define_module_function(mNcurses, "TABSIZE",
+ (&get_TABSIZE),0);
+#endif
+#ifdef HAVE_ESCDELAY
+ rb_define_module_function(mNcurses, "ESCDELAY",
+ (&get_ESCDELAY),0);
+ rb_define_module_function(mNcurses, "ESCDELAY=",
+ (&set_ESCDELAY),1);
+#endif
+ /* The maximum delay before screen resize is detected, in milliseconds */
+ rb_iv_set(mNcurses, "@resize_delay", INT2FIX(333));
+ rb_define_module_function(mNcurses, "RESIZEDELAY",
+ (&get_RESIZEDELAY),0);
+ rb_define_module_function(mNcurses, "RESIZEDELAY=",
+ (&set_RESIZEDELAY),1);
+}
+#ifdef HAVE_KEYBOUND
+static VALUE rbncurs_keybound(VALUE dummy, VALUE keycode, VALUE count)
+{
+ char * str = keybound(NUM2INT(keycode), NUM2INT(count));
+ VALUE rb_str = Qnil;
+ if (str) {
+ rb_str = rb_str_new2(str);
+ free(str);
+ }
+ return rb_str;
+}
+#endif
+#ifdef HAVE_CURSES_VERSION
+static VALUE rbncurs_curses_version(){return rb_str_new2(curses_version());}
+#endif
+#ifdef HAVE_DEFINE_KEY
+static VALUE rbncurs_define_key(VALUE dummy, VALUE definition, VALUE keycode)
+{
+ return INT2NUM(define_key((definition != Qnil)
+ ? STR2CSTR(definition)
+ : (char*)(NULL),
+ NUM2INT(keycode)));
+}
+#endif
+#ifdef HAVE_KEYOK
+static VALUE rbncurs_keyok(VALUE dummy, VALUE keycode, VALUE enable)
+{
+ return INT2NUM(keyok(NUM2INT(keycode), RTEST(enable)));
+}
+#endif
+#ifdef HAVE_RESIZETERM
+static VALUE rbncurs_resizeterm(VALUE dummy, VALUE lines, VALUE columns)
+{
+ return INT2NUM(resizeterm(NUM2INT(lines), NUM2INT(columns)));
+}
+#endif
+#ifdef HAVE_USE_DEFAULT_COLORS
+static VALUE rbncurs_use_default_colors()
+{
+ return INT2NUM(use_default_colors());
+}
+#endif
+#ifdef HAVE_USE_EXTENDED_NAMES
+static VALUE rbncurs_use_extended_names(VALUE dummy, VALUE boolean)
+{return INT2NUM(use_extended_names(RTEST(boolean)));}
+#endif
+#ifdef HAVE_WRESIZE
+static VALUE rbncurs_wresize(VALUE dummy, VALUE win, VALUE lines, VALUE columns)
+{
+ return INT2NUM(wresize(get_window(win), NUM2INT(lines), NUM2INT(columns)));
+}
+#endif
+static
+void
+init_functions_1(void)
+{
+#ifdef HAVE_KEYBOUND
+ NCFUNC(keybound, 2);
+#endif
+#ifdef HAVE_CURSES_VERSION
+ NCFUNC(curses_version, 0);
+#endif
+#ifdef HAVE_DEFINE_KEY
+ NCFUNC(define_key, 2);
+#endif
+#ifdef HAVE_KEYOK
+ NCFUNC(keyok, 2);
+#endif
+#ifdef HAVE_RESIZETERM
+ NCFUNC(resizeterm, 2);
+#endif
+#ifdef HAVE_USE_DEFAULT_COLORS
+ NCFUNC(use_default_colors, 0);
+#endif
+#ifdef HAVE_USE_EXTENDED_NAMES
+ NCFUNC(use_extended_names, 1);
+#endif
+#ifdef HAVE_WRESIZE
+ NCFUNC(wresize, 3);
+#endif
+}
+/* FIXME: what's this? */
+/* extern char ttytype[]; */ /* needed for backward compatibility */
+
+
+/* copy a chstr from ruby to c */
+static chtype * RB2CHSTR(VALUE array)
+{
+ if (rb_obj_is_instance_of(array, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "chtype string argument must be an empty Array");
+ return NULL;
+ }
+ {
+ size_t string_length =
+ NUM2ULONG(rb_funcall(array, rb_intern("size"), 0));
+ size_t vector_length =
+ string_length + 1; /* for terminating 0 */
+ chtype * chstr = ALLOC_N(chtype, vector_length);
+ unsigned long i;
+ for (i = 0; i < string_length; ++i) {
+ chstr[i] = NUM2ULONG(rb_ary_entry(array, i));
+ }
+ chstr[string_length] = 0;
+ return chstr;
+ }
+}
+
+static VALUE rbncurs_addch(VALUE dummy, VALUE arg1) {
+ return INT2NUM(addch(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_addchnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
+ chtype * chstr = RB2CHSTR(arg1);
+ VALUE return_value = INT2NUM(addchnstr(chstr, NUM2INT(arg2)));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_addchstr(VALUE dummy, VALUE arg1) {
+ chtype * chstr = RB2CHSTR(arg1);
+ VALUE return_value = INT2NUM(addchstr(chstr));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_addnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(addnstr(STR2CSTR(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_addstr(VALUE dummy, VALUE arg1) {
+ return INT2NUM(addstr(STR2CSTR(arg1)));
+}
+static VALUE rbncurs_attroff(VALUE dummy, VALUE arg1) {
+ return INT2NUM(attroff(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_attron(VALUE dummy, VALUE arg1) {
+ return INT2NUM(attron(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_attrset(VALUE dummy, VALUE arg1) {
+ return INT2NUM(attrset(NUM2ULONG(arg1)));
+}
+#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR > 4
+#ifdef HAVE_ATTR_OFF
+static VALUE rbncurs_attr_off(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(attr_off(NUM2ULONG(arg1), ((void)(arg2),NULL)));
+}
+#endif
+#ifdef HAVE_ATTR_ON
+static VALUE rbncurs_attr_on(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(attr_on(NUM2ULONG(arg1), ((void)(arg2),NULL)));
+}
+#endif
+#ifdef HAVE_ATTR_SET
+static VALUE rbncurs_attr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(attr_set(NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
+}
+#endif
+#if defined(HAVE_SLK_ATTR_OFF) || defined(slk_attr_off)
+static VALUE rbncurs_slk_attr_off(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(slk_attr_off(NUM2ULONG(arg1), ((void)(arg2),NULL)));
+}
+#endif
+#if defined(HAVE_SLK_ATTR_ON) || defined(slk_attr_on)
+static VALUE rbncurs_slk_attr_on(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(slk_attr_on(NUM2ULONG(arg1), ((void)(arg2),NULL)));
+}
+#endif
+#ifdef HAVE_SLK_ATTR_SET
+static VALUE rbncurs_slk_attr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(slk_attr_set(NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
+}
+#endif
+#ifdef HAVE_WATTR_ON
+static VALUE rbncurs_wattr_on(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wattr_on(get_window(arg1), NUM2ULONG(arg2), ((void)(arg3),NULL)));
+}
+#endif
+#ifdef HAVE_WATTR_OFF
+static VALUE rbncurs_wattr_off(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wattr_off(get_window(arg1), NUM2ULONG(arg2), ((void)(arg3),NULL)));
+}
+#endif
+#ifdef HAVE_WATTR_SET
+static VALUE rbncurs_wattr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(wattr_set(get_window(arg1), NUM2ULONG(arg2), NUM2INT(arg3), ((void)(arg4),NULL)));
+}
+#endif
+#if defined(HAVE_VID_ATTR) || defined(vid_attr)
+static VALUE rbncurs_vid_attr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(vid_attr(NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
+}
+#endif
+#ifdef HAVE_ATTR_GET
+static VALUE rbncurs_attr_get(VALUE dummy, VALUE rb_attrs, VALUE rb_pair,
+ VALUE dummy2)
+{
+ if ((rb_obj_is_instance_of(rb_attrs, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_pair, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "attrs and pair arguments must be empty Arrays");
+ return Qnil;
+ }
+ {
+ attr_t attrs = 0;
+ short pair = 0;
+ int return_value = attr_get(&attrs, &pair, 0);
+ rb_ary_push(rb_attrs, INT2NUM(attrs));
+ rb_ary_push(rb_pair, INT2NUM(pair));
+ return INT2NUM(return_value);
+ }
+}
+static VALUE rbncurs_wattr_get(VALUE dummy,VALUE win, VALUE rb_attrs, VALUE rb_pair,
+ VALUE dummy2)
+{
+ if ((rb_obj_is_instance_of(rb_attrs, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_pair, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "attrs and pair arguments must be empty Arrays");
+ return Qnil;
+ }
+ {
+ attr_t attrs = 0;
+ short pair = 0;
+ int return_value = wattr_get(get_window(win), &attrs, &pair, 0);
+ rb_ary_push(rb_attrs, INT2NUM(attrs));
+ rb_ary_push(rb_pair, INT2NUM(pair));
+ return INT2NUM(return_value);
+ }
+}
+#endif /* HAVE_ATTR_GET */
+#endif
+
+static VALUE rbncurs_baudrate(VALUE dummy) {
+ return INT2NUM(baudrate());
+}
+static VALUE rbncurs_beep(VALUE dummy) {
+ return INT2NUM(beep());
+}
+static VALUE rbncurs_bkgd(VALUE dummy, VALUE arg1) {
+ return INT2NUM(bkgd(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_bkgdset(VALUE dummy, VALUE arg1) {
+ return ((bkgdset(NUM2ULONG(arg1))),Qnil);
+}
+static VALUE rbncurs_border(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8) {
+ return INT2NUM(border(NUM2ULONG(arg1), NUM2ULONG(arg2), NUM2ULONG(arg3), NUM2ULONG(arg4), NUM2ULONG(arg5), NUM2ULONG(arg6), NUM2ULONG(arg7), NUM2ULONG(arg8)));
+}
+static VALUE rbncurs_box(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(box(get_window(arg1), NUM2ULONG(arg2), NUM2ULONG(arg3)));
+}
+static VALUE rbncurs_can_change_color(VALUE dummy) {
+ return (can_change_color()) ? Qtrue : Qfalse;
+}
+
+static int rbncurshelper_halfdelay_cbreak(int tenths, int break_chars)
+{
+ int status = break_chars ? cbreak() : nocbreak();
+ if (status != ERR) {
+ rb_iv_set(mNcurses, "@halfdelay", INT2NUM(tenths));
+ rb_iv_set(mNcurses, "@cbreak", break_chars ? Qtrue : Qfalse);
+ }
+ return status;
+}
+static void rbncurshelper_halfdelay_cbreak_restore()
+{
+ if (RTEST(rb_iv_get(mNcurses, "@cbreak")))
+ cbreak();
+ else
+ nocbreak();
+}
+static VALUE rbncurs_cbreak(VALUE dummy) {
+ return INT2NUM(rbncurshelper_halfdelay_cbreak(0, 1));
+}
+#ifdef HAVE_CHGAT
+static VALUE rbncurs_chgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(chgat(NUM2INT(arg1), NUM2ULONG(arg2), NUM2INT(arg3),
+ ((void)(arg4),NULL)));
+}
+#endif
+static VALUE rbncurs_clear(VALUE dummy) {
+ return INT2NUM(clear());
+}
+static VALUE rbncurs_clearok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(clearok(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_clrtobot(VALUE dummy) {
+ return INT2NUM(clrtobot());
+}
+static VALUE rbncurs_clrtoeol(VALUE dummy) {
+ return INT2NUM(clrtoeol());
+}
+#ifdef HAVE_COLOR_SET
+static VALUE rbncurs_color_set(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(color_set(NUM2INT(arg1), ((void)(arg2),NULL)));
+}
+#endif
+static VALUE rbncurs_COLOR_PAIR(VALUE dummy, VALUE arg1) {
+ return INT2NUM(COLOR_PAIR(NUM2INT(arg1)));
+}
+static VALUE rbncurs_copywin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8, VALUE arg9) {
+ return INT2NUM(copywin(get_window(arg1), get_window(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7), NUM2INT(arg8), NUM2INT(arg9)));
+}
+static VALUE rbncurs_curs_set(VALUE dummy, VALUE arg1) {
+ return INT2NUM(curs_set(NUM2INT(arg1)));
+}
+static VALUE rbncurs_def_prog_mode(VALUE dummy) {
+ return INT2NUM(def_prog_mode());
+}
+static VALUE rbncurs_def_shell_mode(VALUE dummy) {
+ return INT2NUM(def_shell_mode());
+}
+static VALUE rbncurs_delay_output(VALUE dummy, VALUE arg1) {
+ return INT2NUM(delay_output(NUM2INT(arg1)));
+}
+static VALUE rbncurs_delch(VALUE dummy) {
+ return INT2NUM(delch());
+}
+static VALUE rbncurs_deleteln(VALUE dummy) {
+ return INT2NUM(deleteln());
+}
+static VALUE rbncurs_derwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return wrap_window(derwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5)));
+}
+static VALUE rbncurs_doupdate(VALUE dummy) {
+ return INT2NUM(doupdate());
+}
+static VALUE rbncurs_dupwin(VALUE dummy, VALUE arg1) {
+ return wrap_window(dupwin(get_window(arg1)));
+}
+static VALUE rbncurs_echo(VALUE dummy) {
+ return INT2NUM(echo());
+}
+static VALUE rbncurs_echochar(VALUE dummy, VALUE arg1) {
+ return INT2NUM(echochar(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_endwin(VALUE dummy) {
+ return INT2NUM(endwin());
+}
+static VALUE rbncurs_erasechar(VALUE dummy) {
+ return INT2NUM(erasechar());
+}
+#ifdef HAVE_FILTER
+static VALUE rbncurs_filter(VALUE dummy) {
+ return ((filter()),Qnil);
+}
+#endif
+static VALUE rbncurs_flash(VALUE dummy) {
+ return INT2NUM(flash());
+}
+static VALUE rbncurs_flushinp(VALUE dummy) {
+ return INT2NUM(flushinp());
+}
+static VALUE rbncurs_getbkgd(VALUE dummy, VALUE arg1) {
+ return INT2NUM(getbkgd(get_window(arg1)));
+}
+
+static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) {
+ /* nonblocking wgetch only implemented for Ncurses */
+ int halfdelay = NUM2INT(rb_iv_get(mNcurses, "@halfdelay"));
+ int infd = NUM2INT(rb_iv_get(mNcurses, "@infd"));
+ double screen_delay = halfdelay * 0.1;
+#ifdef NCURSES_VERSION
+ int windelay = c_win->_delay;
+#else
+ int windelay = 0;
+#endif
+ double window_delay = (windelay >= 0) ? 0.001 * windelay : (1e200*1e200);
+ /* FIXME: ^ Infinity ^*/
+ double delay = (screen_delay > 0) ? screen_delay : window_delay;
+ int result;
+ struct timeval tv;
+ struct timezone tz = {0,0};
+ double starttime, nowtime, finishtime;
+ double resize_delay = NUM2INT(get_RESIZEDELAY()) / 1000.0;
+ fd_set in_fds;
+ gettimeofday(&tv, &tz);
+ starttime = tv.tv_sec + tv.tv_usec * 1e-6;
+ finishtime = starttime + delay;
+#ifdef NCURSES_VERSION
+ c_win->_delay = 0;
+#endif
+ while (doupdate() /* detects resize */, (result = wgetch(c_win)) == ERR) {
+ gettimeofday(&tv, &tz);
+ nowtime = tv.tv_sec + tv.tv_usec * 1e-6;
+ delay = finishtime - nowtime;
+ if (delay <= 0) break;
+
+ /* Check for terminal size change every resize_delay seconds */
+ if (resize_delay > delay) resize_delay = delay;
+ tv.tv_sec = (time_t)resize_delay;
+ tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 );
+
+ /* sleep on infd until input is available or tv reaches timeout */
+ FD_ZERO(&in_fds);
+ FD_SET(infd, &in_fds);
+ rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
+ }
+#ifdef NCURSES_VERSION
+ c_win->_delay = windelay;
+#endif
+ return result;
+}
+static VALUE rbncurs_getch(VALUE dummy) {
+ return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr));
+}
+static VALUE rbncurs_halfdelay(VALUE dummy, VALUE arg1) {
+ return INT2NUM(rbncurshelper_halfdelay_cbreak(NUM2INT(arg1), 1));
+}
+static VALUE rbncurs_has_colors(VALUE dummy) {
+ return (has_colors()) ? Qtrue : Qfalse;
+}
+static VALUE rbncurs_has_ic(VALUE dummy) {
+ return (has_ic()) ? Qtrue : Qfalse;
+}
+static VALUE rbncurs_has_il(VALUE dummy) {
+ return (has_il()) ? Qtrue : Qfalse;
+}
+static VALUE rbncurs_hline(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(hline(NUM2ULONG(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_idcok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return ((idcok(get_window(arg1), RTEST(arg2))),Qnil);
+}
+static VALUE rbncurs_idlok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(idlok(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_immedok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return ((immedok(get_window(arg1), RTEST(arg2))),Qnil);
+}
+static VALUE rbncurs_inch(VALUE dummy) {
+ return INT2NUM(inch());
+}
+static VALUE rbncurs_initscr(VALUE dummy) {
+ VALUE v = wrap_window(initscr());
+ if (!RTEST(v))
+ return v;
+
+ Init_ncurses_full();
+
+ /* Some constants defined by the initscr call. */
+
+ /* line graphics */
+
+ /* VT100 symbols begin here */
+
+ rb_define_const(mNcurses, "ACS_ULCORNER", INT2NUM(ACS_ULCORNER));
+ rb_define_const(mNcurses, "ACS_LLCORNER", INT2NUM(ACS_LLCORNER));
+ rb_define_const(mNcurses, "ACS_URCORNER", INT2NUM(ACS_URCORNER));
+ rb_define_const(mNcurses, "ACS_LRCORNER", INT2NUM(ACS_LRCORNER));
+ rb_define_const(mNcurses, "ACS_LTEE", INT2NUM(ACS_LTEE));
+ rb_define_const(mNcurses, "ACS_RTEE", INT2NUM(ACS_RTEE));
+ rb_define_const(mNcurses, "ACS_BTEE", INT2NUM(ACS_BTEE));
+ rb_define_const(mNcurses, "ACS_TTEE", INT2NUM(ACS_TTEE));
+ rb_define_const(mNcurses, "ACS_HLINE", INT2NUM(ACS_HLINE));
+ rb_define_const(mNcurses, "ACS_VLINE", INT2NUM(ACS_VLINE));
+ rb_define_const(mNcurses, "ACS_PLUS", INT2NUM(ACS_PLUS));
+ rb_define_const(mNcurses, "ACS_S1", INT2NUM(ACS_S1));
+ rb_define_const(mNcurses, "ACS_S9", INT2NUM(ACS_S9));
+ rb_define_const(mNcurses, "ACS_DIAMOND", INT2NUM(ACS_DIAMOND));
+ rb_define_const(mNcurses, "ACS_CKBOARD", INT2NUM(ACS_CKBOARD));
+ rb_define_const(mNcurses, "ACS_DEGREE", INT2NUM(ACS_DEGREE));
+ rb_define_const(mNcurses, "ACS_PLMINUS", INT2NUM(ACS_PLMINUS));
+ rb_define_const(mNcurses, "ACS_BULLET", INT2NUM(ACS_BULLET));
+ /* Teletype 5410v1 symbols begin here */
+ rb_define_const(mNcurses, "ACS_LARROW", INT2NUM(ACS_LARROW));
+ rb_define_const(mNcurses, "ACS_RARROW", INT2NUM(ACS_RARROW));
+ rb_define_const(mNcurses, "ACS_DARROW", INT2NUM(ACS_DARROW));
+ rb_define_const(mNcurses, "ACS_UARROW", INT2NUM(ACS_UARROW));
+ rb_define_const(mNcurses, "ACS_BOARD", INT2NUM(ACS_BOARD));
+ rb_define_const(mNcurses, "ACS_LANTERN", INT2NUM(ACS_LANTERN));
+ rb_define_const(mNcurses, "ACS_BLOCK", INT2NUM(ACS_BLOCK));
+ /*
+ * These aren't documented, but a lot of System Vs have them anyway
+ * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings).
+ * The ACS_names may not match AT&T's, our source didn't know them.
+ */
+#ifdef ACS_S3
+ rb_define_const(mNcurses, "ACS_S3", INT2NUM(ACS_S3));
+#endif
+#ifdef ACS_S7
+ rb_define_const(mNcurses, "ACS_S7", INT2NUM(ACS_S7));
+#endif
+#ifdef ACS_LEQUAL
+ rb_define_const(mNcurses, "ACS_LEQUAL", INT2NUM(ACS_LEQUAL));
+#endif
+#ifdef ACS_LEQUAL
+ rb_define_const(mNcurses, "ACS_GEQUAL", INT2NUM(ACS_GEQUAL));
+#endif
+#ifdef ACS_PI
+ rb_define_const(mNcurses, "ACS_PI", INT2NUM(ACS_PI));
+#endif
+#ifdef ACS_NEQUAL
+ rb_define_const(mNcurses, "ACS_NEQUAL", INT2NUM(ACS_NEQUAL));
+#endif
+#ifdef ACS_STERLING
+ rb_define_const(mNcurses, "ACS_STERLING", INT2NUM(ACS_STERLING));
+#endif
+ /*
+ * Line drawing ACS names are of the form ACS_trbl, where t is the top, r
+ * is the right, b is the bottom, and l is the left. t, r, b, and l might
+ * be B (blank), S (single), D (double), or T (thick). The subset defined
+ * here only uses B and S.
+ */
+#ifdef ACS_BSSB
+ rb_define_const(mNcurses, "ACS_BSSB", INT2NUM(ACS_BSSB));
+#endif
+#ifdef ACS_SSBB
+ rb_define_const(mNcurses, "ACS_SSBB", INT2NUM(ACS_SSBB));
+#endif
+#ifdef ACS_BBSS
+ rb_define_const(mNcurses, "ACS_BBSS", INT2NUM(ACS_BBSS));
+#endif
+#ifdef ACS_SBBS
+ rb_define_const(mNcurses, "ACS_SBBS", INT2NUM(ACS_SBBS));
+#endif
+#ifdef ACS_SBSS
+ rb_define_const(mNcurses, "ACS_SBSS", INT2NUM(ACS_SBSS));
+#endif
+#ifdef ACS_SSSB
+ rb_define_const(mNcurses, "ACS_SSSB", INT2NUM(ACS_SSSB));
+#endif
+#ifdef ACS_SSBS
+ rb_define_const(mNcurses, "ACS_SSBS", INT2NUM(ACS_SSBS));
+#endif
+#ifdef ACS_BSSS
+ rb_define_const(mNcurses, "ACS_BSSS", INT2NUM(ACS_BSSS));
+#endif
+#ifdef ACS_BSBS
+ rb_define_const(mNcurses, "ACS_BSBS", INT2NUM(ACS_BSBS));
+#endif
+#ifdef ACS_SBSB
+ rb_define_const(mNcurses, "ACS_SBSB", INT2NUM(ACS_SBSB));
+#endif
+#ifdef ACS_SSSS
+ rb_define_const(mNcurses, "ACS_SSSS", INT2NUM(ACS_SSSS));
+#endif
+ rbncurshelper_halfdelay_cbreak_restore();
+ rb_iv_set(mNcurses, "@infd", INT2FIX(0));
+ rb_iv_set(mNcurses, "@halfdelay", INT2FIX(0));
+ rb_iv_set(mNcurses, "@cbreak", Qfalse);
+ return v;
+}
+static VALUE rbncurs_init_color(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(init_color(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
+}
+static VALUE rbncurs_init_pair(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(init_pair(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_insch(VALUE dummy, VALUE arg1) {
+ return INT2NUM(insch(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_insdelln(VALUE dummy, VALUE arg1) {
+ return INT2NUM(insdelln(NUM2INT(arg1)));
+}
+static VALUE rbncurs_insertln(VALUE dummy) {
+ return INT2NUM(insertln());
+}
+static VALUE rbncurs_insnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(insnstr(STR2CSTR(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_insstr(VALUE dummy, VALUE arg1) {
+ return INT2NUM(insstr(STR2CSTR(arg1)));
+}
+#ifdef HAVE_INTRFLUSH
+static VALUE rbncurs_intrflush(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(intrflush(get_window(arg1), RTEST(arg2)));
+}
+#endif
+static VALUE rbncurs_isendwin(VALUE dummy) {
+ return (isendwin()) ? Qtrue : Qfalse;
+}
+static VALUE rbncurs_is_linetouched(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return (is_linetouched(get_window(arg1), NUM2INT(arg2))) ? Qtrue : Qfalse;
+}
+static VALUE rbncurs_is_wintouched(VALUE dummy, VALUE arg1) {
+ return (is_wintouched(get_window(arg1))) ? Qtrue : Qfalse;
+}
+static VALUE rbncurs_keyname(VALUE dummy, VALUE arg1) {
+ return rb_str_new2(keyname(NUM2INT(arg1)));
+}
+static VALUE rbncurs_keypad(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(keypad(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_killchar(VALUE dummy) {
+ return INT2NUM(killchar());
+}
+static VALUE rbncurs_leaveok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(leaveok(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_longname(VALUE dummy) {
+ return rb_str_new2(longname());
+}
+static VALUE rbncurs_meta(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(meta(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_move(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(move(NUM2INT(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_mvaddch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvaddch(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3)));
+}
+static VALUE rbncurs_mvaddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
+ VALUE arg4) {
+ chtype * chstr = RB2CHSTR(arg3);
+ VALUE return_value = INT2NUM(mvaddchnstr(NUM2INT(arg1), NUM2INT(arg2),
+ chstr, NUM2INT(arg4)));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_mvaddchstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ chtype * chstr = RB2CHSTR(arg3);
+ VALUE return_value = INT2NUM(mvaddchstr(NUM2INT(arg1), NUM2INT(arg2),
+ chstr));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_mvaddnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvaddnstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3), NUM2INT(arg4)));
+}
+static VALUE rbncurs_mvaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvaddstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3)));
+}
+#ifdef HAVE_MVCHGAT
+static VALUE rbncurs_mvchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6) {
+ return INT2NUM(mvchgat(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4), NUM2INT(arg5), ((void)(arg6),NULL)));
+}
+#endif
+static VALUE rbncurs_mvcur(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvcur(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
+}
+static VALUE rbncurs_mvdelch(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(mvdelch(NUM2INT(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_mvderwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvderwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_mvgetch(VALUE dummy, VALUE arg1, VALUE arg2) {
+ if (wmove(stdscr, NUM2INT(arg1), NUM2INT(arg2)) == ERR)
+ return INT2NUM(ERR);
+ return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr));
+}
+#ifdef HAVE_MVHLINE
+static VALUE rbncurs_mvhline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvhline(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3), NUM2INT(arg4)));
+}
+#endif
+static VALUE rbncurs_mvinch(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(mvinch(NUM2INT(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_mvinsch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvinsch(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3)));
+}
+static VALUE rbncurs_mvinsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvinsnstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3), NUM2INT(arg4)));
+}
+static VALUE rbncurs_mvinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvinsstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3)));
+}
+#ifdef HAVE_MVVLINE
+static VALUE rbncurs_mvvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvvline(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3), NUM2INT(arg4)));
+}
+#endif
+static VALUE rbncurs_mvwaddch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvwaddch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4)));
+}
+static VALUE rbncurs_mvwaddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
+ VALUE arg4, VALUE arg5) {
+ chtype * chstr = RB2CHSTR(arg4);
+ VALUE return_value = INT2NUM(mvwaddchnstr(get_window(arg1), NUM2INT(arg2),
+ NUM2INT(arg3), chstr,
+ NUM2INT(arg5)));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_mvwaddchstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
+ VALUE arg4) {
+ chtype * chstr = RB2CHSTR(arg4);
+ VALUE return_value = INT2NUM(mvwaddchstr(get_window(arg1), NUM2INT(arg2),
+ NUM2INT(arg3), chstr));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_mvwaddnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return INT2NUM(mvwaddnstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4), NUM2INT(arg5)));
+}
+static VALUE rbncurs_mvwaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvwaddstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4)));
+}
+#ifdef HAVE_MVWCHGAT
+static VALUE rbncurs_mvwchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) {
+ return INT2NUM(mvwchgat(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2ULONG(arg5), NUM2INT(arg6), ((void)(arg7),NULL)));
+}
+#endif
+static VALUE rbncurs_mvwdelch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvwdelch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_mvwgetch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ WINDOW * c_win = get_window(arg1);
+ if (wmove(c_win, NUM2INT(arg1), NUM2INT(arg2)) == ERR)
+ return INT2NUM(ERR);
+ return INT2NUM(rbncurshelper_nonblocking_wgetch(c_win));
+}
+#ifdef HAVE_MVWHLINE
+static VALUE rbncurs_mvwhline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return INT2NUM(mvwhline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4), NUM2INT(arg5)));
+}
+#endif
+static VALUE rbncurs_mvwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_mvwinch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(mvwinch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_mvwinsch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvwinsch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4)));
+}
+static VALUE rbncurs_mvwinsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return INT2NUM(mvwinsnstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4), NUM2INT(arg5)));
+}
+static VALUE rbncurs_mvwinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(mvwinsstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4)));
+}
+#ifdef HAVE_MVWVLINE
+static VALUE rbncurs_mvwvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return INT2NUM(mvwvline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4), NUM2INT(arg5)));
+}
+#endif
+static VALUE rbncurs_napms(VALUE dummy, VALUE arg1) {
+ return INT2NUM(napms(NUM2INT(arg1)));
+}
+static VALUE rbncurs_newpad(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return wrap_window(newpad(NUM2INT(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_newwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return wrap_window(newwin(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
+}
+static VALUE rbncurs_nl(VALUE dummy) {
+ return INT2NUM(nl());
+}
+static VALUE rbncurs_nocbreak(VALUE dummy) {
+ return INT2NUM(rbncurshelper_halfdelay_cbreak(0, 0));
+}
+static VALUE rbncurs_nodelay(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(nodelay(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_noecho(VALUE dummy) {
+ return INT2NUM(noecho());
+}
+static VALUE rbncurs_nonl(VALUE dummy) {
+ return INT2NUM(nonl());
+}
+#ifdef HAVE_NOQIFLUSH
+static VALUE rbncurs_noqiflush(VALUE dummy) {
+ return ((noqiflush()),Qnil);
+}
+#endif
+static VALUE rbncurs_noraw(VALUE dummy) {
+ return INT2NUM(noraw());
+}
+static VALUE rbncurs_notimeout(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(notimeout(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_overlay(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(overlay(get_window(arg1), get_window(arg2)));
+}
+static VALUE rbncurs_overwrite(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(overwrite(get_window(arg1), get_window(arg2)));
+}
+static VALUE rbncurs_PAIR_NUMBER(VALUE dummy, VALUE arg1) {
+ return INT2NUM(PAIR_NUMBER(NUM2INT(arg1)));
+}
+#ifndef __PDCURSES__ /* pdcurses "pechochar" macro won't compile*/
+static VALUE rbncurs_pechochar(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(pechochar(get_window(arg1), NUM2ULONG(arg2)));
+}
+#endif
+static VALUE rbncurs_pnoutrefresh(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) {
+ return INT2NUM(pnoutrefresh(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7)));
+}
+static VALUE rbncurs_prefresh(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) {
+ return INT2NUM(prefresh(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7)));
+}
+#ifdef HAVE_PUTP
+static VALUE rbncurs_putp(VALUE dummy, VALUE arg1) {
+ return INT2NUM(putp(STR2CSTR(arg1)));
+}
+#endif
+#ifdef HAVE_QIFLUSH
+static VALUE rbncurs_qiflush(VALUE dummy) {
+ return ((qiflush()),Qnil);
+}
+#endif
+static VALUE rbncurs_raw(VALUE dummy) {
+ return INT2NUM(raw());
+}
+#ifndef __PDCURSES__ /* __PDCURSES__ redrawwin macro is buggy */
+static VALUE rbncurs_redrawwin(VALUE dummy, VALUE arg1) {
+ return INT2NUM(redrawwin(get_window(arg1)));
+}
+#endif
+static VALUE rbncurs_refresh(VALUE dummy) {
+ return INT2NUM(refresh());
+}
+static VALUE rbncurs_resetty(VALUE dummy) {
+ return INT2NUM(resetty());
+}
+static VALUE rbncurs_reset_prog_mode(VALUE dummy) {
+ return INT2NUM(reset_prog_mode());
+}
+static VALUE rbncurs_reset_shell_mode(VALUE dummy) {
+ return INT2NUM(reset_shell_mode());
+}
+static VALUE rbncurs_savetty(VALUE dummy) {
+ return INT2NUM(savetty());
+}
+#ifdef HAVE_SCR_DUMP
+static VALUE rbncurs_scr_dump(VALUE dummy, VALUE arg1) {
+ return INT2NUM(scr_dump(STR2CSTR(arg1)));
+}
+#endif
+#ifdef HAVE_SCR_INIT
+static VALUE rbncurs_scr_init(VALUE dummy, VALUE arg1) {
+ return INT2NUM(scr_init(STR2CSTR(arg1)));
+}
+#endif
+static VALUE rbncurs_scrl(VALUE dummy, VALUE arg1) {
+ return INT2NUM(scrl(NUM2INT(arg1)));
+}
+static VALUE rbncurs_scroll(VALUE dummy, VALUE arg1) {
+ return INT2NUM(scroll(get_window(arg1)));
+}
+static VALUE rbncurs_scrollok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(scrollok(get_window(arg1), RTEST(arg2)));
+}
+#ifdef HAVE_SCR_RESTORE
+static VALUE rbncurs_scr_restore(VALUE dummy, VALUE arg1) {
+ return INT2NUM(scr_restore(STR2CSTR(arg1)));
+}
+#endif
+#ifdef HAVE_SCR_SET
+static VALUE rbncurs_scr_set(VALUE dummy, VALUE arg1) {
+ return INT2NUM(scr_set(STR2CSTR(arg1)));
+}
+#endif
+static VALUE rbncurs_setscrreg(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(setscrreg(NUM2INT(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_set_term(VALUE dummy, VALUE rb_new_screen) {
+ VALUE rb_old_screen = wrap_screen(set_term(get_screen(rb_new_screen)));
+ rb_iv_set(rb_old_screen, "@infd", rb_iv_get(mNcurses, "@infd"));
+ rb_iv_set(rb_old_screen, "@halfdelay", rb_iv_get(mNcurses, "@halfdelay"));
+ rb_iv_set(rb_old_screen, "@cbreak", rb_iv_get(mNcurses, "@cbreak"));
+ rb_iv_set(mNcurses, "@infd", rb_iv_get(rb_new_screen, "@infd"));
+ rb_iv_set(mNcurses, "@halfdelay", rb_iv_get(rb_new_screen, "@halfdelay"));
+ rb_iv_set(mNcurses, "@cbreak", rb_iv_get(rb_new_screen, "@cbreak"));
+
+ rbncurshelper_halfdelay_cbreak_restore();
+ return rb_old_screen;
+}
+static VALUE rbncurs_slk_attroff(VALUE dummy, VALUE arg1) {
+ return INT2NUM(slk_attroff(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_slk_attron(VALUE dummy, VALUE arg1) {
+ return INT2NUM(slk_attron(NUM2ULONG(arg1)));
+}
+static VALUE rbncurs_slk_attrset(VALUE dummy, VALUE arg1) {
+ return INT2NUM(slk_attrset(NUM2ULONG(arg1)));
+}
+#ifdef HAVE_SLK_ATTR
+static VALUE rbncurs_slk_attr(VALUE dummy) {
+ return INT2NUM(slk_attr());
+}
+#endif
+
+static VALUE rbncurs_slk_clear(VALUE dummy) {
+ return INT2NUM(slk_clear());
+}
+#ifdef HAVE_SLK_COLOR
+static VALUE rbncurs_slk_color(VALUE dummy, VALUE arg1) {
+ return INT2NUM(slk_color(NUM2INT(arg1)));
+}
+#endif
+static VALUE rbncurs_slk_init(VALUE dummy, VALUE arg1) {
+ return INT2NUM(slk_init(NUM2INT(arg1)));
+}
+static VALUE rbncurs_slk_label(VALUE dummy, VALUE arg1) {
+ return rb_str_new2(slk_label(NUM2INT(arg1)));
+}
+static VALUE rbncurs_slk_noutrefresh(VALUE dummy) {
+ return INT2NUM(slk_noutrefresh());
+}
+static VALUE rbncurs_slk_refresh(VALUE dummy) {
+ return INT2NUM(slk_refresh());
+}
+static VALUE rbncurs_slk_restore(VALUE dummy) {
+ return INT2NUM(slk_restore());
+}
+static VALUE rbncurs_slk_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(slk_set(NUM2INT(arg1), STR2CSTR(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_slk_touch(VALUE dummy) {
+ return INT2NUM(slk_touch());
+}
+static VALUE rbncurs_standout(VALUE dummy) {
+ return INT2NUM(standout());
+}
+static VALUE rbncurs_standend(VALUE dummy) {
+ return INT2NUM(standend());
+}
+static VALUE rbncurs_start_color(VALUE dummy) {
+ return INT2NUM(start_color());
+}
+static VALUE rbncurs_subpad(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return wrap_window(subpad(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5)));
+}
+static VALUE rbncurs_subwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return wrap_window(subwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5)));
+}
+static VALUE rbncurs_syncok(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(syncok(get_window(arg1), RTEST(arg2)));
+}
+static VALUE rbncurs_termattrs(VALUE dummy) {
+ return INT2NUM(termattrs());
+}
+static VALUE rbncurs_termname(VALUE dummy) {
+ return rb_str_new2(termname());
+}
+#ifdef HAVE_TIGETFLAG
+static VALUE rbncurs_tigetflag(VALUE dummy, VALUE arg1) {
+ return INT2NUM(tigetflag(STR2CSTR(arg1)));
+}
+#endif
+#ifdef HAVE_TIGETNUM
+static VALUE rbncurs_tigetnum(VALUE dummy, VALUE arg1) {
+ return INT2NUM(tigetnum(STR2CSTR(arg1)));
+}
+#endif
+#ifdef HAVE_TIGETSTR
+static VALUE rbncurs_tigetstr(VALUE dummy, VALUE arg1) {
+ return rb_str_new2(tigetstr(STR2CSTR(arg1)));
+}
+#endif
+static VALUE rbncurs_timeout(VALUE dummy, VALUE arg1) {
+ return ((timeout(NUM2INT(arg1))),Qnil);
+}
+static VALUE rbncurs_typeahead(VALUE dummy, VALUE arg1) {
+ return INT2NUM(typeahead(NUM2INT(arg1)));
+}
+static VALUE rbncurs_ungetch(VALUE dummy, VALUE arg1) {
+ return INT2NUM(ungetch(NUM2INT(arg1)));
+}
+static VALUE rbncurs_untouchwin(VALUE dummy, VALUE arg1) {
+ return INT2NUM(untouchwin(get_window(arg1)));
+}
+#ifdef HAVE_USE_ENV
+static VALUE rbncurs_use_env(VALUE dummy, VALUE arg1) {
+ return ((use_env(RTEST(arg1))),Qnil);
+}
+#endif
+#ifdef HAVE_VIDATTR
+static VALUE rbncurs_vidattr(VALUE dummy, VALUE arg1) {
+ return INT2NUM(vidattr(NUM2ULONG(arg1)));
+}
+#endif
+static VALUE rbncurs_vline(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(vline(NUM2ULONG(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_waddch(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(waddch(get_window(arg1), NUM2ULONG(arg2)));
+}
+static VALUE rbncurs_waddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ chtype * chstr = RB2CHSTR(arg2);
+ VALUE return_value = INT2NUM(waddchnstr(get_window(arg1), chstr,
+ NUM2INT(arg3)));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_waddchstr(VALUE dummy, VALUE arg1, VALUE arg2) {
+ chtype * chstr = RB2CHSTR(arg2);
+ VALUE return_value = INT2NUM(waddchstr(get_window(arg1), chstr));
+ xfree(chstr);
+ return return_value;
+}
+static VALUE rbncurs_waddnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(waddnstr(get_window(arg1), STR2CSTR(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_waddstr(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(waddstr(get_window(arg1), STR2CSTR(arg2)));
+}
+static VALUE rbncurs_wattron(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(wattron(get_window(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_wattroff(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(wattroff(get_window(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_wattrset(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(wattrset(get_window(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_wbkgd(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(wbkgd(get_window(arg1), NUM2ULONG(arg2)));
+}
+static VALUE rbncurs_wbkgdset(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return ((wbkgdset(get_window(arg1), NUM2ULONG(arg2))),Qnil);
+}
+static VALUE rbncurs_wborder(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8, VALUE arg9) {
+ return INT2NUM(wborder(get_window(arg1), NUM2ULONG(arg2), NUM2ULONG(arg3), NUM2ULONG(arg4), NUM2ULONG(arg5), NUM2ULONG(arg6), NUM2ULONG(arg7), NUM2ULONG(arg8), NUM2ULONG(arg9)));
+}
+#ifdef HAVE_WCHGAT
+static VALUE rbncurs_wchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
+ return INT2NUM(wchgat(get_window(arg1), NUM2INT(arg2), NUM2ULONG(arg3), NUM2INT(arg4), ((void)(arg5),NULL)));
+}
+#endif
+static VALUE rbncurs_wclear(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wclear(get_window(arg1)));
+}
+static VALUE rbncurs_wclrtobot(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wclrtobot(get_window(arg1)));
+}
+static VALUE rbncurs_wclrtoeol(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wclrtoeol(get_window(arg1)));
+}
+#ifdef HAVE_WCOLOR_SET
+static VALUE rbncurs_wcolor_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wcolor_set(get_window(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
+}
+#endif
+static VALUE rbncurs_wcursyncup(VALUE dummy, VALUE arg1) {
+ return ((wcursyncup(get_window(arg1))),Qnil);
+}
+static VALUE rbncurs_wdelch(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wdelch(get_window(arg1)));
+}
+static VALUE rbncurs_wdeleteln(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wdeleteln(get_window(arg1)));
+}
+static VALUE rbncurs_wechochar(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(wechochar(get_window(arg1), NUM2ULONG(arg2)));
+}
+static VALUE rbncurs_werase(VALUE dummy, VALUE arg1) {
+ return INT2NUM(werase(get_window(arg1)));
+}
+static VALUE rbncurs_wgetch(VALUE dummy, VALUE arg1) {
+ return INT2NUM(rbncurshelper_nonblocking_wgetch(get_window(arg1)));
+}
+static VALUE rbncurs_whline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(whline(get_window(arg1), NUM2ULONG(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_winch(VALUE dummy, VALUE arg1) {
+ return INT2NUM(winch(get_window(arg1)));
+}
+static VALUE rbncurs_winsch(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(winsch(get_window(arg1), NUM2ULONG(arg2)));
+}
+static VALUE rbncurs_winsdelln(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(winsdelln(get_window(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_winsertln(VALUE dummy, VALUE arg1) {
+ return INT2NUM(winsertln(get_window(arg1)));
+}
+static VALUE rbncurs_winsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(winsnstr(get_window(arg1), STR2CSTR(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_winsstr(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(winsstr(get_window(arg1), STR2CSTR(arg2)));
+}
+static VALUE rbncurs_wmove(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wmove(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_wnoutrefresh(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wnoutrefresh(get_window(arg1)));
+}
+static VALUE rbncurs_wredrawln(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wredrawln(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_wrefresh(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wrefresh(get_window(arg1)));
+}
+static VALUE rbncurs_wscrl(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return INT2NUM(wscrl(get_window(arg1), NUM2INT(arg2)));
+}
+static VALUE rbncurs_wsetscrreg(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wsetscrreg(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_wstandout(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wstandout(get_window(arg1)));
+}
+static VALUE rbncurs_wstandend(VALUE dummy, VALUE arg1) {
+ return INT2NUM(wstandend(get_window(arg1)));
+}
+static VALUE rbncurs_wsyncdown(VALUE dummy, VALUE arg1) {
+ return ((wsyncdown(get_window(arg1))),Qnil);
+}
+static VALUE rbncurs_wsyncup(VALUE dummy, VALUE arg1) {
+ return ((wsyncup(get_window(arg1))),Qnil);
+}
+static VALUE rbncurs_wtimeout(VALUE dummy, VALUE arg1, VALUE arg2) {
+ return ((wtimeout(get_window(arg1), NUM2INT(arg2))),Qnil);
+}
+static VALUE rbncurs_wtouchln(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
+ return INT2NUM(wtouchln(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
+}
+static VALUE rbncurs_wvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
+ return INT2NUM(wvline(get_window(arg1), NUM2ULONG(arg2), NUM2INT(arg3)));
+}
+static VALUE rbncurs_color_content(VALUE dummy, VALUE color, VALUE r, VALUE g, VALUE b) {
+ if (rb_obj_is_instance_of(r, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(g, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(b, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "r,g and b (2nd to 4th argument) must be an empty Arrays");
+ return Qnil;
+ }
+ {
+ short cv[3] = {0,0,0};
+ int return_value = color_content(NUM2INT(color), &cv[0], &cv[1],
+ &cv[2]);
+ rb_ary_push(r, INT2NUM(cv[0])); rb_ary_push(g, INT2NUM(cv[1]));
+ rb_ary_push(b, INT2NUM(cv[2])); return INT2NUM(return_value);
+ }
+}
+static VALUE rbncurs_pair_content(VALUE dummy, VALUE pair, VALUE fg, VALUE bg) {
+ if (rb_obj_is_instance_of(fg, rb_cArray) != Qtrue
+ || rb_obj_is_instance_of(bg, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "fg and bg (2nd and 3rd argument) must be an empty Arrays");
+ return Qnil;
+ }
+ {
+ short cn[2] = {0,0};
+ int return_value = pair_content(NUM2INT(pair), &cn[0], &cn[1]);
+ rb_ary_push(fg, INT2NUM(cn[0])); rb_ary_push(bg, INT2NUM(cn[1]));
+ return INT2NUM(return_value);
+ }
+}
+#ifdef HAVE_GETWIN
+static VALUE rbncurs_getwin(VALUE dummy, VALUE io)
+{
+ int fd = dup(NUM2INT(rb_funcall(io, rb_intern("to_i"), 0)));
+ FILE * f = fdopen(fd, "r");
+ WINDOW * win = getwin(f);
+ fclose(f);
+ close(fd);
+ {
+ VALUE return_value = Qnil;
+ if (win) return_value = wrap_window(win);
+ return return_value;
+ }
+}
+#endif
+#ifdef HAVE_PUTWIN
+static VALUE rbncurs_putwin(VALUE dummy, VALUE rb_win, VALUE io)
+{
+ int fd = dup(NUM2INT(rb_funcall(io, rb_intern("to_i"), 0)));
+ FILE * f = fdopen(fd, "w");
+ WINDOW * win = get_window(rb_win);
+ int return_value = putwin(win, f);
+ fclose(f);
+ close(fd);
+ return INT2NUM(return_value);
+}
+#endif
+static VALUE rbncurs_unctrl(VALUE dummy, VALUE ch)
+{ return rb_str_new2(unctrl(NUM2ULONG(ch))); }
+static VALUE rbncurs_newterm(VALUE dummy, VALUE rb_type, VALUE rb_outfd, VALUE rb_infd)
+{
+ char * type = (rb_type == Qnil) ? (char*)0 : STR2CSTR(rb_type);
+ int outfd = NUM2INT(rb_funcall(rb_outfd, rb_intern("to_i"), 0));
+ int infd = NUM2INT(rb_funcall(rb_infd, rb_intern("to_i"), 0));
+ VALUE rb_screen =
+ wrap_screen(newterm(type, fdopen(outfd, "w"), fdopen(infd, "r")));
+ if (RTEST(rb_screen)) {
+ Init_ncurses_full();
+ rbncurshelper_halfdelay_cbreak_restore();
+ }
+ rb_iv_set(mNcurses, "@infd", INT2NUM(infd));
+ rb_iv_set(rb_screen, "@infd", INT2NUM(infd));
+ rb_iv_set(mNcurses, "@halfdelay", INT2FIX(0));
+ rb_iv_set(rb_screen, "@halfdelay", INT2FIX(0));
+ rb_iv_set(mNcurses, "@cbreak", Qfalse);
+ rb_iv_set(rb_screen, "@cbreak", Qfalse);
+ return rb_screen;
+}
+
+
+static void init_functions_2(void) {
+ NCFUNC(addch, 1);
+ NCFUNC(addchnstr, 2);
+ NCFUNC(addchstr, 1);
+ NCFUNC(addnstr, 2);
+ NCFUNC(addstr, 1);
+ NCFUNC(attroff, 1);
+ NCFUNC(attron, 1);
+ NCFUNC(attrset, 1);
+#if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR > 4
+#ifdef HAVE_ATTR_OFF
+ NCFUNC(attr_off, 2);
+#endif
+#ifdef HAVE_ATTR_ON
+ NCFUNC(attr_on, 2);
+#endif
+#ifdef HAVE_ATTR_SET
+ NCFUNC(attr_set, 3);
+#endif
+#if defined(HAVE_SLK_ATTR_OFF) || defined(slk_attr_off)
+ NCFUNC(slk_attr_off, 2);
+#endif
+#if defined(HAVE_SLK_ATTR_ON) || defined(slk_attr_on)
+ NCFUNC(slk_attr_on, 2);
+#endif
+#ifdef HAVE_SLK_ATTR_SET
+ NCFUNC(slk_attr_set, 3);
+#endif
+#ifdef HAVE_WATTR_ON
+ NCFUNC(wattr_on, 3);
+#endif
+#ifdef HAVE_WATTR_OFF
+ NCFUNC(wattr_off, 3);
+#endif
+#ifdef HAVE_WATTR_SET
+ NCFUNC(wattr_set, 4);
+#endif
+#if defined (HAVE_VID_ATTR) || defined(vid_attr)
+ NCFUNC(vid_attr, 3);
+#endif
+#ifdef HAVE_ATTR_GET
+ NCFUNC(attr_get, 3);
+ NCFUNC(wattr_get, 4);
+#endif /* HAVE_ATTR_GET */
+#endif
+ NCFUNC(baudrate, 0);
+ NCFUNC(beep, 0);
+ NCFUNC(bkgd, 1);
+ NCFUNC(bkgdset, 1);
+ NCFUNC(border, 8);
+ NCFUNC(box, 3);
+ rb_define_module_function(mNcurses, "can_change_color?",
+ (&rbncurs_can_change_color),
+ 0);
+ NCFUNC(cbreak, 0);
+#ifdef HAVE_CHGAT
+ NCFUNC(chgat, 4);
+#endif
+ NCFUNC(clear, 0);
+ NCFUNC(clearok, 2);
+ NCFUNC(clrtobot, 0);
+ NCFUNC(clrtoeol, 0);
+#ifdef HAVE_COLOR_SET
+ NCFUNC(color_set, 2);
+#endif
+ NCFUNC(COLOR_PAIR, 1);
+ NCFUNC(copywin, 9);
+ NCFUNC(curs_set, 1);
+ NCFUNC(def_prog_mode, 0);
+ NCFUNC(def_shell_mode, 0);
+ NCFUNC(delay_output, 1);
+ NCFUNC(delch, 0);
+ NCFUNC(deleteln, 0);
+ NCFUNC(derwin, 5);
+ NCFUNC(doupdate, 0);
+ NCFUNC(dupwin, 1);
+ NCFUNC(echo, 0);
+ NCFUNC(echochar, 1);
+ NCFUNC(endwin, 0);
+ NCFUNC(erasechar, 0);
+ NCFUNC(flash, 0);
+ NCFUNC(flushinp, 0);
+ NCFUNC(getbkgd, 1);
+ NCFUNC(getch, 0);
+ NCFUNC(halfdelay, 1);
+ rb_define_module_function(mNcurses, "has_colors?",
+ (&rbncurs_has_colors),
+ 0);
+ rb_define_module_function(mNcurses, "has_ic?",
+ (&rbncurs_has_ic),
+ 0);
+ rb_define_module_function(mNcurses, "has_il?",
+ (&rbncurs_has_il),
+ 0);
+ NCFUNC(hline, 2);
+ NCFUNC(idcok, 2);
+ NCFUNC(idlok, 2);
+ NCFUNC(immedok, 2);
+ NCFUNC(inch, 0);
+ NCFUNC(init_color, 4);
+ NCFUNC(init_pair, 3);
+ NCFUNC(insch, 1);
+ NCFUNC(insdelln, 1);
+ NCFUNC(insertln, 0);
+ NCFUNC(insnstr, 2);
+ NCFUNC(insstr, 1);
+#ifdef HAVE_INTRFLUSH
+ NCFUNC(intrflush, 2);
+#endif
+ rb_define_module_function(mNcurses, "isendwin?",
+ (&rbncurs_isendwin),
+ 0);
+ rb_define_module_function(mNcurses, "is_linetouched?",
+ (&rbncurs_is_linetouched),
+ 2);
+ rb_define_module_function(mNcurses, "is_wintouched?",
+ (&rbncurs_is_wintouched),
+ 1);
+ NCFUNC(keyname, 1);
+ NCFUNC(keypad, 2);
+ NCFUNC(killchar, 0);
+ NCFUNC(leaveok, 2);
+ NCFUNC(longname, 0);
+ NCFUNC(meta, 2);
+ NCFUNC(move, 2);
+ NCFUNC(mvaddch, 3);
+ NCFUNC(mvaddchnstr, 4);
+ NCFUNC(mvaddchstr, 3);
+ NCFUNC(mvaddnstr, 4);
+ NCFUNC(mvaddstr, 3);
+#ifdef HAVE_MVCHGAT
+ NCFUNC(mvchgat, 6);
+#endif
+ NCFUNC(mvcur, 4);
+ NCFUNC(mvdelch, 2);
+ NCFUNC(mvderwin, 3);
+ NCFUNC(mvgetch, 2);
+#ifdef HAVE_MVHLINE
+ NCFUNC(mvhline, 4);
+#endif
+ NCFUNC(mvinch, 2);
+ NCFUNC(mvinsch, 3);
+ NCFUNC(mvinsnstr, 4);
+ NCFUNC(mvinsstr, 3);
+#ifdef HAVE_MVVLINE
+ NCFUNC(mvvline, 4);
+#endif
+ NCFUNC(mvwaddch, 4);
+ NCFUNC(mvwaddchnstr, 5);
+ NCFUNC(mvwaddchstr, 4);
+ NCFUNC(mvwaddnstr, 5);
+ NCFUNC(mvwaddstr, 4);
+#ifdef HAVE_MVWCHGAT
+ NCFUNC(mvwchgat, 7);
+#endif
+ NCFUNC(mvwdelch, 3);
+ NCFUNC(mvwgetch, 3);
+#ifdef HAVE_MVWHLINE
+ NCFUNC(mvwhline, 5);
+#endif
+ NCFUNC(mvwin, 3);
+ NCFUNC(mvwinch, 3);
+ NCFUNC(mvwinsch, 4);
+ NCFUNC(mvwinsnstr, 5);
+ NCFUNC(mvwinsstr, 4);
+#ifdef HAVE_MVWVLINE
+ NCFUNC(mvwvline, 5);
+#endif
+ NCFUNC(napms, 1);
+ NCFUNC(newpad, 2);
+ NCFUNC(newwin, 4);
+ NCFUNC(nl, 0);
+ NCFUNC(nocbreak, 0);
+ NCFUNC(nodelay, 2);
+ NCFUNC(noecho, 0);
+ NCFUNC(nonl, 0);
+#ifdef HAVE_NOQIFLUSH
+ NCFUNC(noqiflush, 0);
+#endif
+ NCFUNC(noraw, 0);
+ NCFUNC(notimeout, 2);
+ NCFUNC(overlay, 2);
+ NCFUNC(overwrite, 2);
+ NCFUNC(PAIR_NUMBER, 1);
+#ifndef __PDCURSES__ /* pdcurses' pechochar macro does not work */
+ NCFUNC(pechochar, 2);
+#endif
+ NCFUNC(pnoutrefresh, 7);
+ NCFUNC(prefresh, 7);
+#ifdef HAVE_PUTP
+ NCFUNC(putp, 1);
+#endif
+#ifdef HAVE_QIFLUSH
+ NCFUNC(qiflush, 0);
+#endif
+ NCFUNC(raw, 0);
+#ifndef __PDCURSES__ /* pdcurses redrawwin macro has a bug */
+ NCFUNC(redrawwin, 1);
+#endif
+ NCFUNC(refresh, 0);
+ NCFUNC(resetty, 0);
+ NCFUNC(reset_prog_mode, 0);
+ NCFUNC(reset_shell_mode, 0);
+ NCFUNC(savetty, 0);
+#ifdef HAVE_SCR_DUMP
+ NCFUNC(scr_dump, 1);
+#endif
+#ifdef HAVE_SCR_INIT
+ NCFUNC(scr_init, 1);
+#endif
+ NCFUNC(scrl, 1);
+ NCFUNC(scroll, 1);
+ NCFUNC(scrollok, 2);
+#ifdef HAVE_SCR_RESTORE
+ NCFUNC(scr_restore, 1);
+#endif
+#ifdef HAVE_SCR_SET
+ NCFUNC(scr_set, 1);
+#endif
+ NCFUNC(setscrreg, 2);
+ NCFUNC(set_term, 1);
+ NCFUNC(slk_attroff, 1);
+ NCFUNC(slk_attron, 1);
+ NCFUNC(slk_attrset, 1);
+#ifdef HAVE_SLK_ATTR
+ NCFUNC(slk_attr, 0);
+#endif
+ NCFUNC(slk_clear, 0);
+#ifdef HAVE_SLK_COLOR
+ NCFUNC(slk_color, 1);
+#endif
+ NCFUNC(slk_label, 1);
+ NCFUNC(slk_noutrefresh, 0);
+ NCFUNC(slk_refresh, 0);
+ NCFUNC(slk_restore, 0);
+ NCFUNC(slk_set, 3);
+ NCFUNC(slk_touch, 0);
+ NCFUNC(standout, 0);
+ NCFUNC(standend, 0);
+ NCFUNC(start_color, 0);
+ NCFUNC(subpad, 5);
+ NCFUNC(subwin, 5);
+ NCFUNC(syncok, 2);
+ NCFUNC(termattrs, 0);
+ NCFUNC(termname, 0);
+#ifdef HAVE_TIGETFLAG
+ NCFUNC(tigetflag, 1);
+#endif
+#ifdef HAVE_TIGETNUM
+ NCFUNC(tigetnum, 1);
+#endif
+#ifdef HAVE_TIGETSTR
+ NCFUNC(tigetstr, 1);
+#endif
+ NCFUNC(timeout, 1);
+ NCFUNC(typeahead, 1);
+ NCFUNC(ungetch, 1);
+ NCFUNC(untouchwin, 1);
+#ifdef HAVE_VIDATTR
+ NCFUNC(vidattr, 1);
+#endif
+ NCFUNC(vline, 2);
+ NCFUNC(waddch, 2);
+ NCFUNC(waddchnstr, 3);
+ NCFUNC(waddchstr, 2);
+ NCFUNC(waddnstr, 3);
+ NCFUNC(waddstr, 2);
+ NCFUNC(wattron, 2);
+ NCFUNC(wattroff, 2);
+ NCFUNC(wattrset, 2);
+ NCFUNC(wbkgd, 2);
+ NCFUNC(wbkgdset, 2);
+ NCFUNC(wborder, 9);
+#ifdef HAVE_WCHGAT
+ NCFUNC(wchgat, 5);
+#endif
+ NCFUNC(wclear, 1);
+ NCFUNC(wclrtobot, 1);
+ NCFUNC(wclrtoeol, 1);
+#ifdef HAVE_WCOLOR_SET
+ NCFUNC(wcolor_set, 3);
+#endif
+ NCFUNC(wcursyncup, 1);
+ NCFUNC(wdelch, 1);
+ NCFUNC(wdeleteln, 1);
+ NCFUNC(wechochar, 2);
+ NCFUNC(werase, 1);
+ NCFUNC(wgetch, 1);
+ NCFUNC(whline, 3);
+ NCFUNC(winch, 1);
+ NCFUNC(winsch, 2);
+ NCFUNC(winsdelln, 2);
+ NCFUNC(winsertln, 1);
+ NCFUNC(winsnstr, 3);
+ NCFUNC(winsstr, 2);
+ NCFUNC(wmove, 3);
+ NCFUNC(wnoutrefresh, 1);
+ NCFUNC(wredrawln, 3);
+ NCFUNC(wrefresh, 1);
+ NCFUNC(wscrl, 2);
+ NCFUNC(wsetscrreg, 3);
+ NCFUNC(wstandout, 1);
+ NCFUNC(wstandend, 1);
+ NCFUNC(wsyncdown, 1);
+ NCFUNC(wsyncup, 1);
+ NCFUNC(wtimeout, 2);
+ NCFUNC(wtouchln, 4);
+ NCFUNC(wvline, 3);
+ NCFUNC(color_content, 4);
+ NCFUNC(pair_content, 3);
+ NCFUNC(pair_content, 3);
+#ifdef HAVE_GETWIN
+ NCFUNC(getwin, 1);
+#endif
+#ifdef HAVE_PUTWIN
+ NCFUNC(putwin, 2);
+#endif
+ NCFUNC(unctrl, 1);
+}
+
+
+static void init_constants_3(void) {
+ /* #define NCURSES_BITS(mask,shift) ((mask) << ((shift) + 8)) */
+
+ /* attributes */
+
+ rb_define_const(mNcurses, "A_NORMAL", INT2NUM(A_NORMAL));
+ rb_define_const(mNcurses, "A_ATTRIBUTES", INT2NUM(A_ATTRIBUTES));
+ rb_define_const(mNcurses, "A_CHARTEXT", INT2NUM(A_CHARTEXT));
+ rb_define_const(mNcurses, "A_COLOR", INT2NUM(A_COLOR));
+ rb_define_const(mNcurses, "A_STANDOUT", INT2NUM(A_STANDOUT));
+ rb_define_const(mNcurses, "A_UNDERLINE", INT2NUM(A_UNDERLINE));
+ rb_define_const(mNcurses, "A_REVERSE", INT2NUM(A_REVERSE));
+ rb_define_const(mNcurses, "A_BLINK", INT2NUM(A_BLINK));
+ rb_define_const(mNcurses, "A_DIM", INT2NUM(A_DIM));
+ rb_define_const(mNcurses, "A_BOLD", INT2NUM(A_BOLD));
+ rb_define_const(mNcurses, "A_ALTCHARSET", INT2NUM(A_ALTCHARSET));
+ rb_define_const(mNcurses, "A_INVIS", INT2NUM(A_INVIS));
+
+ /* Tradeoff on 32-bit machines ('protect' vs widec). The others (e.g., left
+ * highlight are not implemented in any terminal descriptions, anyway.
+ */
+ rb_define_const(mNcurses, "A_PROTECT", INT2NUM(A_PROTECT));
+#ifdef A_HORIZONTAL
+ rb_define_const(mNcurses, "A_HORIZONTAL", INT2NUM(A_HORIZONTAL));
+#endif
+#ifdef A_LEFT
+ rb_define_const(mNcurses, "A_LEFT", INT2NUM(A_LEFT));
+#endif
+#ifdef A_LOW
+ rb_define_const(mNcurses, "A_LOW", INT2NUM(A_LOW));
+#endif
+#ifdef A_RIGHT
+ rb_define_const(mNcurses, "A_RIGHT", INT2NUM(A_RIGHT));
+#endif
+#ifdef A_TOP
+ rb_define_const(mNcurses, "A_TOP", INT2NUM(A_TOP));
+#endif
+#ifdef A_VERTICAL
+ rb_define_const(mNcurses, "A_VERTICAL", INT2NUM(A_VERTICAL));
+#endif
+
+ /* Pseudo-character tokens outside ASCII range. The curses wgetch()
+ * function will return any given one of these only if the corresponding
+ * k- capability is defined in your terminal's terminfo entry. */
+#ifdef KEY_CODE_YES
+ rb_define_const(mNcurses, "KEY_CODE_YES", INT2NUM(KEY_CODE_YES));
+#endif
+ rb_define_const(mNcurses, "KEY_MIN", INT2NUM(KEY_MIN));
+ rb_define_const(mNcurses, "KEY_BREAK", INT2NUM(KEY_BREAK));
+ rb_define_const(mNcurses, "KEY_DOWN", INT2NUM(KEY_DOWN));
+ rb_define_const(mNcurses, "KEY_UP", INT2NUM(KEY_UP));
+ rb_define_const(mNcurses, "KEY_LEFT", INT2NUM(KEY_LEFT));
+ rb_define_const(mNcurses, "KEY_RIGHT", INT2NUM(KEY_RIGHT));
+ rb_define_const(mNcurses, "KEY_HOME", INT2NUM(KEY_HOME));
+ rb_define_const(mNcurses, "KEY_BACKSPACE", INT2NUM(KEY_BACKSPACE));
+ rb_define_const(mNcurses, "KEY_F0", INT2NUM(KEY_F(0)));
+ rb_define_const(mNcurses, "KEY_F1", INT2NUM(KEY_F(1)));
+ rb_define_const(mNcurses, "KEY_F2", INT2NUM(KEY_F(2)));
+ rb_define_const(mNcurses, "KEY_F3", INT2NUM(KEY_F(3)));
+ rb_define_const(mNcurses, "KEY_F4", INT2NUM(KEY_F(4)));
+ rb_define_const(mNcurses, "KEY_F5", INT2NUM(KEY_F(5)));
+ rb_define_const(mNcurses, "KEY_F6", INT2NUM(KEY_F(6)));
+ rb_define_const(mNcurses, "KEY_F7", INT2NUM(KEY_F(7)));
+ rb_define_const(mNcurses, "KEY_F8", INT2NUM(KEY_F(8)));
+ rb_define_const(mNcurses, "KEY_F9", INT2NUM(KEY_F(9)));
+ rb_define_const(mNcurses, "KEY_F10", INT2NUM(KEY_F(10)));
+ rb_define_const(mNcurses, "KEY_F11", INT2NUM(KEY_F(11)));
+ rb_define_const(mNcurses, "KEY_F12", INT2NUM(KEY_F(12)));
+ rb_define_const(mNcurses, "KEY_F13", INT2NUM(KEY_F(13)));
+ rb_define_const(mNcurses, "KEY_F14", INT2NUM(KEY_F(14)));
+ rb_define_const(mNcurses, "KEY_F15", INT2NUM(KEY_F(15)));
+ rb_define_const(mNcurses, "KEY_F16", INT2NUM(KEY_F(16)));
+ rb_define_const(mNcurses, "KEY_F17", INT2NUM(KEY_F(17)));
+ rb_define_const(mNcurses, "KEY_F18", INT2NUM(KEY_F(18)));
+ rb_define_const(mNcurses, "KEY_F19", INT2NUM(KEY_F(19)));
+ rb_define_const(mNcurses, "KEY_F20", INT2NUM(KEY_F(20)));
+ rb_define_const(mNcurses, "KEY_F21", INT2NUM(KEY_F(21)));
+ rb_define_const(mNcurses, "KEY_F22", INT2NUM(KEY_F(22)));
+ rb_define_const(mNcurses, "KEY_F23", INT2NUM(KEY_F(23)));
+ rb_define_const(mNcurses, "KEY_F24", INT2NUM(KEY_F(24)));
+ rb_define_const(mNcurses, "KEY_F25", INT2NUM(KEY_F(25)));
+ rb_define_const(mNcurses, "KEY_F26", INT2NUM(KEY_F(26)));
+ rb_define_const(mNcurses, "KEY_F27", INT2NUM(KEY_F(27)));
+ rb_define_const(mNcurses, "KEY_F28", INT2NUM(KEY_F(28)));
+ rb_define_const(mNcurses, "KEY_F29", INT2NUM(KEY_F(29)));
+ rb_define_const(mNcurses, "KEY_F30", INT2NUM(KEY_F(30)));
+ rb_define_const(mNcurses, "KEY_DL", INT2NUM(KEY_DL));
+ rb_define_const(mNcurses, "KEY_IL", INT2NUM(KEY_IL));
+ rb_define_const(mNcurses, "KEY_DC", INT2NUM(KEY_DC));
+ rb_define_const(mNcurses, "KEY_IC", INT2NUM(KEY_IC));
+ rb_define_const(mNcurses, "KEY_EIC", INT2NUM(KEY_EIC));
+ rb_define_const(mNcurses, "KEY_CLEAR", INT2NUM(KEY_CLEAR));
+ rb_define_const(mNcurses, "KEY_EOS", INT2NUM(KEY_EOS));
+ rb_define_const(mNcurses, "KEY_EOL", INT2NUM(KEY_EOL));
+ rb_define_const(mNcurses, "KEY_SF", INT2NUM(KEY_SF));
+ rb_define_const(mNcurses, "KEY_SR", INT2NUM(KEY_SR));
+ rb_define_const(mNcurses, "KEY_NPAGE", INT2NUM(KEY_NPAGE));
+ rb_define_const(mNcurses, "KEY_PPAGE", INT2NUM(KEY_PPAGE));
+ rb_define_const(mNcurses, "KEY_STAB", INT2NUM(KEY_STAB));
+ rb_define_const(mNcurses, "KEY_CTAB", INT2NUM(KEY_CTAB));
+ rb_define_const(mNcurses, "KEY_CATAB", INT2NUM(KEY_CATAB));
+ rb_define_const(mNcurses, "KEY_ENTER", INT2NUM(KEY_ENTER));
+ rb_define_const(mNcurses, "KEY_SRESET", INT2NUM(KEY_SRESET));
+ rb_define_const(mNcurses, "KEY_RESET", INT2NUM(KEY_RESET));
+ rb_define_const(mNcurses, "KEY_PRINT", INT2NUM(KEY_PRINT));
+ rb_define_const(mNcurses, "KEY_LL", INT2NUM(KEY_LL));
+
+ /* The keypad is arranged like this: */
+ /* a1 up a3 */
+ /* left b2 right */
+ /* c1 down c3 */
+
+ rb_define_const(mNcurses, "KEY_A1", INT2NUM(KEY_A1));
+ rb_define_const(mNcurses, "KEY_A3", INT2NUM(KEY_A3));
+ rb_define_const(mNcurses, "KEY_B2", INT2NUM(KEY_B2));
+ rb_define_const(mNcurses, "KEY_C1", INT2NUM(KEY_C1));
+ rb_define_const(mNcurses, "KEY_C3", INT2NUM(KEY_C3));
+ rb_define_const(mNcurses, "KEY_BTAB", INT2NUM(KEY_BTAB));
+ rb_define_const(mNcurses, "KEY_BEG", INT2NUM(KEY_BEG));
+ rb_define_const(mNcurses, "KEY_CANCEL", INT2NUM(KEY_CANCEL));
+ rb_define_const(mNcurses, "KEY_CLOSE", INT2NUM(KEY_CLOSE));
+ rb_define_const(mNcurses, "KEY_COMMAND", INT2NUM(KEY_COMMAND));
+ rb_define_const(mNcurses, "KEY_COPY", INT2NUM(KEY_COPY));
+ rb_define_const(mNcurses, "KEY_CREATE", INT2NUM(KEY_CREATE));
+ rb_define_const(mNcurses, "KEY_END", INT2NUM(KEY_END));
+ rb_define_const(mNcurses, "KEY_EXIT", INT2NUM(KEY_EXIT));
+ rb_define_const(mNcurses, "KEY_FIND", INT2NUM(KEY_FIND));
+ rb_define_const(mNcurses, "KEY_HELP", INT2NUM(KEY_HELP));
+ rb_define_const(mNcurses, "KEY_MARK", INT2NUM(KEY_MARK));
+ rb_define_const(mNcurses, "KEY_MESSAGE", INT2NUM(KEY_MESSAGE));
+ rb_define_const(mNcurses, "KEY_MOVE", INT2NUM(KEY_MOVE));
+ rb_define_const(mNcurses, "KEY_NEXT", INT2NUM(KEY_NEXT));
+ rb_define_const(mNcurses, "KEY_OPEN", INT2NUM(KEY_OPEN));
+ rb_define_const(mNcurses, "KEY_OPTIONS", INT2NUM(KEY_OPTIONS));
+ rb_define_const(mNcurses, "KEY_PREVIOUS", INT2NUM(KEY_PREVIOUS));
+ rb_define_const(mNcurses, "KEY_REDO", INT2NUM(KEY_REDO));
+ rb_define_const(mNcurses, "KEY_REFERENCE", INT2NUM(KEY_REFERENCE));
+ rb_define_const(mNcurses, "KEY_REFRESH", INT2NUM(KEY_REFRESH));
+ rb_define_const(mNcurses, "KEY_REPLACE", INT2NUM(KEY_REPLACE));
+ rb_define_const(mNcurses, "KEY_RESTART", INT2NUM(KEY_RESTART));
+ rb_define_const(mNcurses, "KEY_RESUME", INT2NUM(KEY_RESUME));
+ rb_define_const(mNcurses, "KEY_SAVE", INT2NUM(KEY_SAVE));
+ rb_define_const(mNcurses, "KEY_SBEG", INT2NUM(KEY_SBEG));
+ rb_define_const(mNcurses, "KEY_SCANCEL", INT2NUM(KEY_SCANCEL));
+ rb_define_const(mNcurses, "KEY_SCOMMAND", INT2NUM(KEY_SCOMMAND));
+ rb_define_const(mNcurses, "KEY_SCOPY", INT2NUM(KEY_SCOPY));
+ rb_define_const(mNcurses, "KEY_SCREATE", INT2NUM(KEY_SCREATE));
+ rb_define_const(mNcurses, "KEY_SDC", INT2NUM(KEY_SDC));
+ rb_define_const(mNcurses, "KEY_SDL", INT2NUM(KEY_SDL));
+ rb_define_const(mNcurses, "KEY_SELECT", INT2NUM(KEY_SELECT));
+ rb_define_const(mNcurses, "KEY_SEND", INT2NUM(KEY_SEND));
+ rb_define_const(mNcurses, "KEY_SEOL", INT2NUM(KEY_SEOL));
+ rb_define_const(mNcurses, "KEY_SEXIT", INT2NUM(KEY_SEXIT));
+ rb_define_const(mNcurses, "KEY_SFIND", INT2NUM(KEY_SFIND));
+ rb_define_const(mNcurses, "KEY_SHELP", INT2NUM(KEY_SHELP));
+ rb_define_const(mNcurses, "KEY_SHOME", INT2NUM(KEY_SHOME));
+ rb_define_const(mNcurses, "KEY_SIC", INT2NUM(KEY_SIC));
+ rb_define_const(mNcurses, "KEY_SLEFT", INT2NUM(KEY_SLEFT));
+ rb_define_const(mNcurses, "KEY_SMESSAGE", INT2NUM(KEY_SMESSAGE));
+ rb_define_const(mNcurses, "KEY_SMOVE", INT2NUM(KEY_SMOVE));
+ rb_define_const(mNcurses, "KEY_SNEXT", INT2NUM(KEY_SNEXT));
+ rb_define_const(mNcurses, "KEY_SOPTIONS", INT2NUM(KEY_SOPTIONS));
+ rb_define_const(mNcurses, "KEY_SPREVIOUS", INT2NUM(KEY_SPREVIOUS));
+ rb_define_const(mNcurses, "KEY_SPRINT", INT2NUM(KEY_SPRINT));
+ rb_define_const(mNcurses, "KEY_SREDO", INT2NUM(KEY_SREDO));
+ rb_define_const(mNcurses, "KEY_SREPLACE", INT2NUM(KEY_SREPLACE));
+ rb_define_const(mNcurses, "KEY_SRIGHT", INT2NUM(KEY_SRIGHT));
+ rb_define_const(mNcurses, "KEY_SRSUME", INT2NUM(KEY_SRSUME));
+ rb_define_const(mNcurses, "KEY_SSAVE", INT2NUM(KEY_SSAVE));
+ rb_define_const(mNcurses, "KEY_SSUSPEND", INT2NUM(KEY_SSUSPEND));
+ rb_define_const(mNcurses, "KEY_SUNDO", INT2NUM(KEY_SUNDO));
+ rb_define_const(mNcurses, "KEY_SUSPEND", INT2NUM(KEY_SUSPEND));
+ rb_define_const(mNcurses, "KEY_UNDO", INT2NUM(KEY_UNDO));
+ rb_define_const(mNcurses, "KEY_MOUSE", INT2NUM(KEY_MOUSE));
+ rb_define_const(mNcurses, "KEY_RESIZE", INT2NUM(KEY_RESIZE));
+ rb_define_const(mNcurses, "KEY_MAX", INT2NUM(KEY_MAX));
+
+ /* mouse interface */
+ /* #define NCURSES_MOUSE_VERSION 1 */
+
+ /* event masks */
+ rb_define_const(mNcurses, "BUTTON1_RELEASED", INT2NUM(BUTTON1_RELEASED));
+ rb_define_const(mNcurses, "BUTTON1_PRESSED", INT2NUM(BUTTON1_PRESSED));
+ rb_define_const(mNcurses, "BUTTON1_CLICKED", INT2NUM(BUTTON1_CLICKED));
+ rb_define_const(mNcurses, "BUTTON1_DOUBLE_CLICKED", INT2NUM(BUTTON1_DOUBLE_CLICKED));
+ rb_define_const(mNcurses, "BUTTON1_TRIPLE_CLICKED", INT2NUM(BUTTON1_TRIPLE_CLICKED));
+#ifdef BUTTON1_RESERVED_EVENT
+ rb_define_const(mNcurses, "BUTTON1_RESERVED_EVENT", INT2NUM(BUTTON1_RESERVED_EVENT));
+#endif
+ rb_define_const(mNcurses, "BUTTON2_RELEASED", INT2NUM(BUTTON2_RELEASED));
+ rb_define_const(mNcurses, "BUTTON2_PRESSED", INT2NUM(BUTTON2_PRESSED));
+ rb_define_const(mNcurses, "BUTTON2_CLICKED", INT2NUM(BUTTON2_CLICKED));
+ rb_define_const(mNcurses, "BUTTON2_DOUBLE_CLICKED", INT2NUM(BUTTON2_DOUBLE_CLICKED));
+ rb_define_const(mNcurses, "BUTTON2_TRIPLE_CLICKED", INT2NUM(BUTTON2_TRIPLE_CLICKED));
+#ifdef BUTTON2_RESERVED_EVENT
+ rb_define_const(mNcurses, "BUTTON2_RESERVED_EVENT", INT2NUM(BUTTON2_RESERVED_EVENT));
+#endif
+ rb_define_const(mNcurses, "BUTTON3_RELEASED", INT2NUM(BUTTON3_RELEASED));
+ rb_define_const(mNcurses, "BUTTON3_PRESSED", INT2NUM(BUTTON3_PRESSED));
+ rb_define_const(mNcurses, "BUTTON3_CLICKED", INT2NUM(BUTTON3_CLICKED));
+ rb_define_const(mNcurses, "BUTTON3_DOUBLE_CLICKED", INT2NUM(BUTTON3_DOUBLE_CLICKED));
+ rb_define_const(mNcurses, "BUTTON3_TRIPLE_CLICKED", INT2NUM(BUTTON3_TRIPLE_CLICKED));
+#ifdef BUTTON3_RESERVED_EVENT
+ rb_define_const(mNcurses, "BUTTON3_RESERVED_EVENT", INT2NUM(BUTTON3_RESERVED_EVENT));
+#endif
+#ifdef BUTTON4_RELEASED
+ rb_define_const(mNcurses, "BUTTON4_RELEASED", INT2NUM(BUTTON4_RELEASED));
+#endif
+#ifdef BUTTON4_PRESSED
+ rb_define_const(mNcurses, "BUTTON4_PRESSED", INT2NUM(BUTTON4_PRESSED));
+#endif
+#ifdef BUTTON4_CLICKED
+ rb_define_const(mNcurses, "BUTTON4_CLICKED", INT2NUM(BUTTON4_CLICKED));
+#endif
+#ifdef BUTTON4_DOUBLE_CLICKED
+ rb_define_const(mNcurses, "BUTTON4_DOUBLE_CLICKED", INT2NUM(BUTTON4_DOUBLE_CLICKED));
+#endif
+#ifdef BUTTON4_TRIPLE_CLICKED
+ rb_define_const(mNcurses, "BUTTON4_TRIPLE_CLICKED", INT2NUM(BUTTON4_TRIPLE_CLICKED));
+#endif
+#ifdef BUTTON4_RESERVED_EVENT
+ rb_define_const(mNcurses, "BUTTON4_RESERVED_EVENT", INT2NUM(BUTTON4_RESERVED_EVENT));
+#endif
+#ifdef BUTTON_CTRL
+ rb_define_const(mNcurses, "BUTTON_CTRL", INT2NUM(BUTTON_CTRL));
+#endif
+#ifdef BUTTON_CONTROL
+ rb_define_const(mNcurses, "BUTTON_CTRL", INT2NUM(BUTTON_CONTROL));
+#endif
+ rb_define_const(mNcurses, "BUTTON_SHIFT", INT2NUM(BUTTON_SHIFT));
+ rb_define_const(mNcurses, "BUTTON_ALT", INT2NUM(BUTTON_ALT));
+ rb_define_const(mNcurses, "ALL_MOUSE_EVENTS", INT2NUM(ALL_MOUSE_EVENTS));
+ rb_define_const(mNcurses, "REPORT_MOUSE_POSITION", INT2NUM(REPORT_MOUSE_POSITION));
+}
+
+/* typedef struct */
+/* { */
+/* short id; */ /* ID to distinguish multiple devices */
+/* int x, y, z; */ /* event coordinates (character-cell) */
+/* mmask_t bstate; *//* button state bits */
+/* } */
+/* MEVENT; */
+#ifdef HAVE_UNGETMOUSE
+static VALUE rbncurs_getmouse(VALUE dummy, VALUE rb_m)
+{
+ MEVENT m;
+ int return_value = getmouse(&m);
+ if (return_value != ERR) {
+ rb_iv_set(rb_m, "@id", INT2NUM(m.id));
+ rb_iv_set(rb_m, "@x", INT2NUM(m.x));
+ rb_iv_set(rb_m, "@y", INT2NUM(m.y));
+ rb_iv_set(rb_m, "@z", INT2NUM(m.z));
+ rb_iv_set(rb_m, "@bstate", INT2NUM(m.bstate));
+ }
+ return INT2NUM(return_value);
+}
+static VALUE rbncurs_ungetmouse(VALUE dummy, VALUE rb_m)
+{
+ MEVENT m;
+ m.id = NUM2INT(rb_iv_get(rb_m, "@id"));
+ m.x = NUM2INT(rb_iv_get(rb_m, "@x"));
+ m.y = NUM2INT(rb_iv_get(rb_m, "@y"));
+ m.z = NUM2INT(rb_iv_get(rb_m, "@z"));
+ m.bstate = NUM2ULONG(rb_iv_get(rb_m, "@bstate"));
+ return INT2NUM(ungetmouse(&m));
+}
+#endif
+#ifdef HAVE_MOUSEMASK
+static VALUE rbncurs_mousemask(VALUE dummy, VALUE rb_newmask, VALUE rb_oldmask)
+{
+ if (rb_obj_is_instance_of(rb_oldmask, rb_cArray) != Qtrue) {
+ rb_raise(rb_eArgError,
+ "oldmask (2nd argument) must be an empty Array");
+ return Qnil;
+ }
+ {
+ mmask_t oldmask, return_value;
+ return_value = mousemask(NUM2ULONG(rb_newmask), &oldmask);
+ rb_ary_push(rb_oldmask, INT2NUM(oldmask));
+ return INT2NUM(return_value);
+ }
+}
+#endif
+#ifdef HAVE_WENCLOSE
+static VALUE rbncurs_wenclose(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
+{
+ return wenclose(get_window(rb_win), NUM2INT(rb_y), NUM2INT(rb_y))
+ ? Qtrue : Qfalse;
+}
+#endif
+#ifdef HAVE_MOUSEINTERVAL
+static VALUE rbncurs_mouseinterval(VALUE dummy, VALUE rb_interval)
+{ return INT2NUM(mouseinterval(NUM2INT(rb_interval))); }
+#endif
+#ifdef HAVE_WMOUSE_TRAFO
+static VALUE rbncurs_wmouse_trafo(VALUE dummy, VALUE rb_win, VALUE rb_pY, VALUE rb_pX,
+ VALUE rb_to_screen)
+{
+ if ((rb_obj_is_instance_of(rb_pY, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_pY, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "pY and pX arguments must be Arrays, containing exactly one "
+ "Integer");
+ return Qnil;
+ }
+ {
+ int X = NUM2INT(rb_ary_pop(rb_pX));
+ int Y = NUM2INT(rb_ary_pop(rb_pY));
+ bool return_value =
+ wmouse_trafo(get_window(rb_win), &Y, &X, RTEST(rb_to_screen));
+ rb_ary_push(rb_pY, INT2NUM(Y)); rb_ary_push(rb_pX, INT2NUM(X));
+ return return_value ? Qtrue : Qfalse;
+ }
+}
+#endif
+#ifdef HAVE_MCPRINT
+static VALUE rbncurs_mcprint(VALUE dummy, VALUE data, VALUE len)
+{
+ return INT2NUM(mcprint(STR2CSTR(data), NUM2INT(len)));
+}
+#endif
+#ifdef HAVE_HAS_KEY
+static VALUE rbncurs_has_key(VALUE dummy, VALUE ch)
+{return INT2NUM(has_key(NUM2INT(ch)));}
+#endif
+static VALUE rbncurs_getyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
+{
+ if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "y and x arguments must be empty Arrays");
+ return Qnil;
+ }
+ {
+ int y,x;
+ getyx(get_window(rb_win), y,x);
+ rb_ary_push(rb_y, INT2NUM(y));
+ rb_ary_push(rb_x, INT2NUM(x));
+ return Qnil;
+ }
+}
+#if defined(HAVE_GETATTRS) || defined(getattrs)
+static VALUE rbncurs_getattrs(VALUE dummy, VALUE rb_win)
+{return INT2NUM(getattrs(get_window(rb_win)));}
+#endif
+static VALUE rbncurs_getbegyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
+{
+ int y,x;
+ if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "y and x arguments must be empty Arrays");
+ return Qnil;
+ }
+ getbegyx(get_window(rb_win), y,x);
+ rb_ary_push(rb_y, INT2NUM(y));
+ rb_ary_push(rb_x, INT2NUM(x));
+ return Qnil;
+}
+static VALUE rbncurs_getmaxyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
+{
+ int y,x;
+ if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "y and x arguments must be empty Arrays");
+ return Qnil;
+ }
+ getmaxyx(get_window(rb_win), y,x);
+ rb_ary_push(rb_y, INT2NUM(y));
+ rb_ary_push(rb_x, INT2NUM(x));
+ return Qnil;
+}
+static VALUE rbncurs_getparyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
+{
+ int y,x;
+ if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "y and x arguments must be empty Arrays");
+ return Qnil;
+ }
+ getparyx(get_window(rb_win), y,x);
+ rb_ary_push(rb_y, INT2NUM(y));
+ rb_ary_push(rb_x, INT2NUM(x));
+ return Qnil;
+}
+static VALUE rbncurs_getsyx(VALUE dummy, VALUE rb_y, VALUE rb_x)
+{
+ int y,x;
+ if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
+ || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
+ rb_raise(rb_eArgError,
+ "y and x arguments must be empty Arrays");
+ return Qnil;
+ }
+#ifdef getsyx
+ getsyx(y,x);
+#else
+ getsyx(&y,&x);
+#endif
+ rb_ary_push(rb_y, INT2NUM(y));
+ rb_ary_push(rb_x, INT2NUM(x));
+ return Qnil;
+}
+static VALUE rbncurs_setsyx(VALUE dummy, VALUE rb_y, VALUE rb_x)
+{
+ int y = NUM2INT(rb_y), x = NUM2INT(rb_x);
+ setsyx(y,x);
+ return Qnil;
+}
+
+static VALUE rbncurs_wprintw(int argc, VALUE * argv, VALUE dummy)
+{
+ if (argc < 2) {
+ rb_raise(rb_eArgError, "function needs at least 2 arguments: a WINDOW"
+ " and a String");
+ return Qnil;
+ }
+ wprintw(get_window(argv[0]), "%s",
+ STR2CSTR(rb_funcall3(rb_mKernel, rb_intern("sprintf"), argc-1,
+ argv + 1)));
+ return Qnil;
+}
+
+/* Debugging : use with libncurses_g.a */
+#ifdef HAVE__TRACEF
+static VALUE rbncurs_tracef(int argc, VALUE * argv, VALUE dummy)
+{
+ (void) dummy;
+ if (argc < 1) {
+ rb_raise(rb_eArgError, "function needs at least 1 argument");
+ return Qnil;
+ }
+ _tracef("%s",
+ STR2CSTR(funcall3(rb_mKernel, rb_intern("sprintf"), argc, argv)));
+ return Qnil;
+}
+#endif /* HAVE__TRACEF */
+#ifdef HAVE__TRACEDUMP
+static VALUE rbncurs_tracedump(VALUE dummy, VALUE rb_label, VALUE rb_win)
+{
+ _tracedump(STR2CSTR(rb_label), get_window(rb_win));
+}
+#endif /* HAVE__TRACEDUMP */
+#ifdef HAVE__TRACEATTR
+static VALUE rbncurs_traceattr(VALUE dummy, VALUE attr)
+{ return rb_str_new2(_traceattr(NUM2ULONG(attr))); }
+#endif /* HAVE__TRACEATTR */
+#ifdef HAVE__TRACEATTR2
+static VALUE rbncurs_traceattr2(VALUE dummy, VALUE buffer, VALUE ch)
+{ return rb_str_new2(_traceattr2(NUM2INT(buffer),NUM2ULONG(ch))); }
+#endif /* HAVE__TRACEATTR2 */
+#ifdef HAVE__TRACEBITS
+static VALUE rbncurs_tracebits(VALUE dummy)
+{ return rb_str_new2(_tracebits()); }
+#endif /* HAVE__TRACEBITS */
+#ifdef HAVE__TRACECHAR
+static VALUE rbncurs_tracechar(VALUE dummy, VALUE ch)
+{ return rb_str_new2(_tracechar(NUM2ULONG(ch))); }
+#endif /* HAVE__TRACECHAR */
+#ifdef HAVE__TRACECHTYPE
+static VALUE rbncurs_tracechtype(VALUE dummy, VALUE ch)
+{ return rb_str_new2(_tracechtype(NUM2ULONG(ch))); }
+#endif /* HAVE__TRACECHTYPE */
+#ifdef HAVE__TRACECHTYPE2
+static VALUE rbncurs_tracechtype2(VALUE dummy, VALUE buffer, VALUE ch)
+{ return rb_str_new2(_tracechtype2(NUM2INT(buffer),NUM2ULONG(ch))); }
+#endif /* HAVE__TRACECHTYPE2 */
+#ifdef HAVE__TRACEMOUSE
+static VALUE rbncurs_tracemouse(VALUE dummy, VALUE rb_m)
+{
+ MEVENT m;
+ m.id = NUM2INT(rb_iv_get(rb_m, "@id"));
+ m.x = NUM2INT(rb_iv_get(rb_m, "@x"));
+ m.y = NUM2INT(rb_iv_get(rb_m, "@y"));
+ m.z = NUM2INT(rb_iv_get(rb_m, "@z"));
+ m.bstate = NUM2ULONG(rb_iv_get(rb_m, "@bstate"));
+ return rb_str_new2(_tracemouse(&m));
+}
+#endif /* HAVE__TRACEMOUSE */
+#ifdef HAVE_TRACE
+static VALUE rbncurs_trace(VALUE dummy, VALUE param)
+{ trace(NUM2ULONG(param)); return Qnil; }
+#endif /* HAVE_TRACE */
+#ifdef HAVE__NC_TRACEBITS
+static VALUE rbncurs_nc_tracebits()
+{ return rb_str_new2((char*)_nc_tracebits()); }
+#endif /* HAVE__NC_TRACEBITS */
+
+#ifdef HAVE_ASSUME_DEFAULT_COLORS
+static VALUE rbncurs_assume_default_colors(VALUE dummy, VALUE fg, VALUE bg)
+{ return INT2NUM(assume_default_colors(NUM2INT(fg),NUM2INT(bg))); }
+#endif /* HAVE_ASSUME_DEFAULT_COLORS */
+
+static void init_functions_3(void)
+{
+#ifdef HAVE_UNGETMOUSE
+ NCFUNC(getmouse, 1);
+ NCFUNC(ungetmouse, 1);
+#endif
+#ifdef HAVE_MOUSEMASK
+ NCFUNC(mousemask, 2);
+#endif
+#ifdef HAVE_WENCLOSE
+ rb_define_module_function(mNcurses, "wenclose?",
+ (&rbncurs_wenclose),
+ 1);
+#endif
+#ifdef HAVE_MOUSEINTERVAL
+ NCFUNC(mouseinterval, 1);
+#endif
+#ifdef HAVE_WMOUSE_TRAFO
+ NCFUNC(wmouse_trafo, 4);
+#endif
+#ifdef HAVE_MCPRINT
+ NCFUNC(mcprint, 2);
+#endif
+#ifdef HAVE_HAS_KEY
+ rb_define_module_function(mNcurses, "has_key?",
+ (&rbncurs_has_key),
+ 2);
+#endif
+ NCFUNC(getyx, 3);
+ NCFUNC(getbegyx, 3);
+ NCFUNC(getmaxyx, 3);
+ NCFUNC(getparyx, 3);
+ NCFUNC(getsyx, 2);
+ NCFUNC(setsyx, 2);
+#if defined(HAVE_GETATTRS) || defined(getattrs)
+ NCFUNC(getattrs, 1);
+#endif
+#ifdef HAVE__TRACEF
+ rb_define_module_function(mNcurses, "_tracef",
+ (&rbncurs_tracef), -1);
+#endif /* HAVE__TRACEF */
+#ifdef HAVE__TRACEDUMP
+ rb_define_module_function(mNcurses, "_tracedump",
+ (&rbncurs_tracedump),
+ 2);
+#endif /* HAVE__TRACEDUMP */
+#ifdef HAVE__TRACEATTR
+ rb_define_module_function(mNcurses, "_traceattr",
+ (&rbncurs_traceattr),
+ 1);
+#endif /* HAVE__TRACEATTR */
+#ifdef HAVE__TRACEATTR2
+ rb_define_module_function(mNcurses, "_traceattr2",
+ (&rbncurs_traceattr2),
+ 2);
+#endif /* HAVE__TRACEATTR2 */
+#ifdef HAVE__TRACEBITS
+ rb_define_module_function(mNcurses, "_tracebits",
+ (&rbncurs_tracebits),
+ 0);
+#endif /* HAVE__TRACEBITS */
+#ifdef HAVE__TRACECHAR
+ rb_define_module_function(mNcurses, "_tracechar",
+ (&rbncurs_tracechar),
+ 1);
+#endif /* HAVE__TRACECHAR */
+#ifdef HAVE__TRACECHTYPE
+ rb_define_module_function(mNcurses, "_tracechtype",
+ (&rbncurs_tracechtype),
+ 1);
+#endif /* HAVE__TRACECHTYPE */
+#ifdef HAVE__TRACECHTYPE2
+ rb_define_module_function(mNcurses, "_tracechtype2",
+ (&rbncurs_tracechtype2), 2);
+#endif /* HAVE__TRACECHTYPE2 */
+#ifdef HAVE__TRACEMOUSE
+ rb_define_module_function(mNcurses, "_tracechmouse",
+ (&rbncurs_tracemouse),
+ 1);
+#endif /* HAVE__TRACEMOUSE */
+#ifdef HAVE_TRACE
+ NCFUNC(trace, 1);
+#endif /* HAVE_TRACE */
+#ifdef HAVE__NC_TRACEBITS
+ rb_define_module_function(mNcurses, "_nc_tracebits", &rbncurs_nc_tracebits, 0);
+#endif /* HAVE__NC_TRACEBITS */
+#ifdef HAVE_ASSUME_DEFAULT_COLORS
+ NCFUNC(assume_default_colors, 2);
+#endif /* HAVE_ASSUME_DEFAULT_COLORS */
+ NCFUNC(wprintw, -1);
+}
+
+static void init_constants_4(void)
+{
+ /* trace masks */
+#ifdef TRACE_DISABLE
+ rb_define_const(mNcurses, "TRACE_DISABLE", INT2NUM(TRACE_DISABLE));
+#endif
+#ifdef TRACE_TIMES
+ rb_define_const(mNcurses, "TRACE_TIMES", INT2NUM(TRACE_TIMES));
+#endif
+#ifdef TRACE_TPUTS
+ rb_define_const(mNcurses, "TRACE_TPUTS", INT2NUM(TRACE_TPUTS));
+#endif
+#ifdef TRACE_UPDATE
+ rb_define_const(mNcurses, "TRACE_UPDATE", INT2NUM(TRACE_UPDATE));
+#endif
+#ifdef TRACE_MOVE
+ rb_define_const(mNcurses, "TRACE_MOVE", INT2NUM(TRACE_MOVE));
+#endif
+#ifdef TRACE_CHARPUT
+ rb_define_const(mNcurses, "TRACE_CHARPUT", INT2NUM(TRACE_CHARPUT));
+#endif
+#ifdef TRACE_ORDINARY
+ rb_define_const(mNcurses, "TRACE_ORDINARY", INT2NUM(TRACE_ORDINARY));
+#endif
+#ifdef TRACE_CALLS
+ rb_define_const(mNcurses, "TRACE_CALLS", INT2NUM(TRACE_CALLS));
+#endif
+#ifdef TRACE_VIRTPUT
+ rb_define_const(mNcurses, "TRACE_VIRTPUT", INT2NUM(TRACE_VIRTPUT));
+#endif
+#ifdef TRACE_IEVENT
+ rb_define_const(mNcurses, "TRACE_IEVENT", INT2NUM(TRACE_IEVENT));
+#endif
+#ifdef TRACE_BITS
+ rb_define_const(mNcurses, "TRACE_BITS", INT2NUM(TRACE_BITS));
+#endif
+#ifdef TRACE_ICALLS
+ rb_define_const(mNcurses, "TRACE_ICALLS", INT2NUM(TRACE_ICALLS));
+#endif
+#ifdef TRACE_CCALLS
+ rb_define_const(mNcurses, "TRACE_CCALLS", INT2NUM(TRACE_CCALLS));
+#endif
+#ifdef TRACE_MAXIMUM
+ rb_define_const(mNcurses, "TRACE_MAXIMUM", INT2NUM(TRACE_MAXIMUM));
+#endif
+}
+
+/* Wrap ACS_* constants (additionally) as methods of SCREEN: */
+#define rb_ACS(ACS) \
+VALUE rb_## ACS (VALUE rb_screen) \
+{ \
+ VALUE current_screen = \
+ rbncurs_set_term(mNcurses, rb_screen); \
+ VALUE rb_ACS_CONST = INT2NUM(ACS); \
+ rbncurs_set_term(mNcurses, current_screen); \
+ return rb_ACS_CONST; \
+}
+#define wrap_ACS(ACS) \
+rb_define_method(cSCREEN, #ACS, \
+ (&rb_ ## ACS), \
+ 0)
+rb_ACS(ACS_ULCORNER)
+ rb_ACS(ACS_LLCORNER)
+ rb_ACS(ACS_URCORNER)
+ rb_ACS(ACS_LRCORNER)
+ rb_ACS(ACS_LTEE)
+ rb_ACS(ACS_RTEE)
+ rb_ACS(ACS_BTEE)
+ rb_ACS(ACS_TTEE)
+ rb_ACS(ACS_HLINE)
+ rb_ACS(ACS_VLINE)
+ rb_ACS(ACS_PLUS)
+ rb_ACS(ACS_S1)
+ rb_ACS(ACS_S9)
+ rb_ACS(ACS_DIAMOND)
+ rb_ACS(ACS_CKBOARD)
+ rb_ACS(ACS_DEGREE)
+ rb_ACS(ACS_PLMINUS)
+ rb_ACS(ACS_BULLET)
+ rb_ACS(ACS_LARROW)
+ rb_ACS(ACS_RARROW)
+ rb_ACS(ACS_DARROW)
+ rb_ACS(ACS_UARROW)
+ rb_ACS(ACS_BOARD)
+ rb_ACS(ACS_LANTERN)
+ rb_ACS(ACS_BLOCK)
+#ifdef ACS_S3
+ rb_ACS(ACS_S3)
+#endif
+#ifdef ACS_S7
+ rb_ACS(ACS_S7)
+#endif
+#ifdef ACS_LEQUAL
+ rb_ACS(ACS_LEQUAL)
+#endif
+#ifdef ACS_GEQUAL
+ rb_ACS(ACS_GEQUAL)
+#endif
+#ifdef ACS_PI
+ rb_ACS(ACS_PI)
+#endif
+#ifdef ACS_NEQUAL
+ rb_ACS(ACS_NEQUAL)
+#endif
+#ifdef ACS_STERLING
+ rb_ACS(ACS_STERLING)
+#endif
+
+void init_SCREEN_methods(void)
+{
+ wrap_ACS(ACS_ULCORNER);
+ wrap_ACS(ACS_LLCORNER);
+ wrap_ACS(ACS_URCORNER);
+ wrap_ACS(ACS_LRCORNER);
+ wrap_ACS(ACS_LTEE);
+ wrap_ACS(ACS_RTEE);
+ wrap_ACS(ACS_BTEE);
+ wrap_ACS(ACS_TTEE);
+ wrap_ACS(ACS_HLINE);
+ wrap_ACS(ACS_VLINE);
+ wrap_ACS(ACS_PLUS);
+ wrap_ACS(ACS_S1);
+ wrap_ACS(ACS_S9);
+ wrap_ACS(ACS_DIAMOND);
+ wrap_ACS(ACS_CKBOARD);
+ wrap_ACS(ACS_DEGREE);
+ wrap_ACS(ACS_PLMINUS);
+ wrap_ACS(ACS_BULLET);
+ wrap_ACS(ACS_LARROW);
+ wrap_ACS(ACS_RARROW);
+ wrap_ACS(ACS_DARROW);
+ wrap_ACS(ACS_UARROW);
+ wrap_ACS(ACS_BOARD);
+ wrap_ACS(ACS_LANTERN);
+ wrap_ACS(ACS_BLOCK);
+#ifdef ACS_S3
+ wrap_ACS(ACS_S3);
+#endif
+#ifdef ACS_S7
+ wrap_ACS(ACS_S7);
+#endif
+#ifdef ACS_LEQUAL
+ wrap_ACS(ACS_LEQUAL);
+#endif
+#ifdef ACS_GEQUAL
+ wrap_ACS(ACS_GEQUAL);
+#endif
+#ifdef ACS_PI
+ wrap_ACS(ACS_PI);
+#endif
+#ifdef ACS_NEQUAL
+ wrap_ACS(ACS_NEQUAL);
+#endif
+#ifdef ACS_STERLING
+ wrap_ACS(ACS_STERLING);
+#endif
+}
+
+#ifdef HAVE_LOCALE_H
+static VALUE rbncurs_setlocale(VALUE dummy, VALUE category, VALUE locale)
+{ return rb_str_new2(setlocale(NUM2INT(category), STR2CSTR(locale)));}
+#endif
+
+static void init_safe_functions(void)
+{
+ NCFUNC(initscr, 0);
+ NCFUNC(newterm, 3);
+ NCFUNC(slk_init, 1);
+#ifdef HAVE_FILTER
+ NCFUNC(filter, 0);
+#endif
+#ifdef HAVE_USE_ENV
+ NCFUNC(use_env, 1);
+#endif
+#ifdef HAVE_LOCALE_H
+ NCFUNC(setlocale, 2);
+#endif
+}
+void Init_ncurses_bin(void)
+{
+ mNcurses = rb_define_module("Ncurses");
+ eNcurses = rb_define_class_under(mNcurses, "Exception", rb_eRuntimeError);
+ rb_iv_set(mNcurses, "@windows_hash", rb_hash_new());
+ rb_iv_set(mNcurses, "@screens_hash", rb_hash_new());
+
+ /* keep track of "halfdelay" settings in the wrapper */
+ rb_iv_set(mNcurses, "@halfdelay", INT2FIX(0));
+ rb_iv_set(mNcurses, "@cbreak", Qfalse);
+
+ /* filedescriptor that transports input from terminal to application */
+ rb_iv_set(mNcurses, "@infd", Qnil);
+
+ cWINDOW = rb_define_class_under(mNcurses, "WINDOW", rb_cObject);
+ cSCREEN = rb_define_class_under(mNcurses, "SCREEN", rb_cObject);
+ init_constants_1();
+ init_constants_2();
+ init_constants_3();
+ init_constants_4();
+ init_safe_functions();
+}
+static void Init_ncurses_full(void)
+{
+ init_globals_1();
+ init_globals_2();
+ init_functions_0();
+ init_functions_1();
+ init_functions_2();
+ init_functions_3();
+
+ init_SCREEN_methods();
+#ifdef HAVE_PANEL_H
+ init_panel();
+#endif
+#ifdef HAVE_FORM_H
+ init_form();
+#endif
+#ifdef HAVE_MENU_H
+ init_menu();
+#endif
+}
diff --git a/ncurses_wrap.h b/ncurses_wrap.h
@@ -0,0 +1,101 @@
+/*
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
+ * (C) 2002, 2003 Tobias Peters <t-peters@berlios.de>
+ * (C) 2004 Simon Kaczor <skaczor@cox.net>
+ * (C) 2009 Tobias Herzke
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: ncurses_wrap.h,v 1.3 2009/05/03 20:37:26 t-peters Exp $
+ *
+ * This file was adapted from the original ncurses header file which
+ * has the following copyright statements:
+ */
+
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ NOT IMPLEMENTED:
+ - terminfo, termcap-functions
+ - rippoffline
+ - v*printw functions (but normal printw functions are supported!)
+*/
+
+#if defined(HAVE_GETWIN) || defined(HAVE_PUTWIN)
+# ifdef HAVE_UNISTD_H
+# include <unistd.h>
+# else
+int dup(int);
+int close(int);
+# endif
+#endif
+
+#ifdef HAVE_NCURSES_H
+# include <ncurses.h>
+#else
+# ifdef HAVE_NCURSES_CURSES_H
+# include <ncurses/curses.h>
+# else
+# include <curses.h>
+# endif
+#endif
+
+#include <ruby.h>
+
+extern VALUE mNcurses; /* module Ncurses */
+extern VALUE cWINDOW; /* class Ncurses::WINDOW */
+extern VALUE cSCREEN; /* class Ncurses::SCREEN */
+extern VALUE eNcurses; /* Ncurses::Exception thrown by this extension */
+
+#define NCFUNC(name, nargs) \
+ rb_define_singleton_method(mNcurses, \
+ #name, \
+ &rbncurs_ ## name, \
+ nargs)
+
+WINDOW* get_window(VALUE rb_window);
+VALUE wrap_window(WINDOW* window);
+long rbncurs_array_length(VALUE rb_array);
diff --git a/panel_wrap.c b/panel_wrap.c
@@ -0,0 +1,256 @@
+/*
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
+ * (C) 2002 Tobias Peters <t-peters@berlios.de>
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: panel_wrap.c,v 1.2 2004/07/31 08:35:13 t-peters Exp $ */
+
+#ifdef HAVE_PANEL_H
+
+#include "panel_wrap.h"
+#include "ncurses_wrap.h"
+
+VALUE mPanel;
+VALUE cPANEL;
+
+static VALUE wrap_panel(PANEL* panel)
+{
+ if (panel == 0) return Qnil;
+ {
+ VALUE panels_hash = rb_iv_get(mPanel, "@panels_hash");
+ VALUE panel_adress = INT2NUM((long)(panel));
+ VALUE rb_panel = rb_hash_aref(panels_hash, panel_adress);
+ if (rb_panel == Qnil) {
+ rb_panel = Data_Wrap_Struct(cPANEL, 0, 0, panel);
+ rb_iv_set(rb_panel, "@destroyed", Qfalse);
+ rb_hash_aset(panels_hash, panel_adress, rb_panel);
+ }
+ return rb_panel;
+ }
+}
+static PANEL* get_panel(VALUE rb_panel)
+{
+ PANEL* panel;
+ if (rb_panel == Qnil) return 0;
+ if (rb_iv_get(rb_panel, "@destroyed") == Qtrue) {
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed panel");
+ return 0;
+ }
+ Data_Get_Struct(rb_panel, PANEL, panel);
+ return panel;
+}
+static VALUE rbncurs_c_del_panel(VALUE rb_panel) {
+ VALUE panels_hash = rb_iv_get(mPanel, "@panels_hash");
+ PANEL* panel = get_panel(rb_panel);
+ VALUE panel_adress = INT2NUM((long)(panel));
+ rb_funcall(panels_hash, rb_intern("delete"), 1, panel_adress);
+ rb_iv_set(rb_panel, "@destroyed", Qtrue);
+ return INT2NUM(del_panel(panel));
+}
+static VALUE rbncurs_m_del_panel(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_del_panel(rb_panel); }
+
+static VALUE rbncurs_c_panel_window(VALUE rb_panel)
+{ return wrap_window(panel_window(get_panel(rb_panel))); }
+static VALUE rbncurs_m_panel_window(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_panel_window(rb_panel); }
+
+static VALUE rbncurs_m_update_panels(VALUE dummy)
+{ update_panels(); return Qnil; }
+
+static VALUE rbncurs_c_hide_panel(VALUE rb_panel)
+{ return INT2NUM(hide_panel(get_panel(rb_panel))); }
+static VALUE rbncurs_m_hide_panel(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_hide_panel(rb_panel); }
+
+static VALUE rbncurs_c_show_panel(VALUE rb_panel)
+{ return INT2NUM(show_panel(get_panel(rb_panel))); }
+static VALUE rbncurs_m_show_panel(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_show_panel(rb_panel); }
+
+static VALUE rbncurs_c_top_panel(VALUE rb_panel)
+{ return INT2NUM(top_panel(get_panel(rb_panel))); }
+static VALUE rbncurs_m_top_panel(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_top_panel(rb_panel); }
+
+static VALUE rbncurs_c_bottom_panel(VALUE rb_panel)
+{ return INT2NUM(bottom_panel(get_panel(rb_panel))); }
+static VALUE rbncurs_m_bottom_panel(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_bottom_panel(rb_panel); }
+
+static VALUE rbncurs_c_new_panel(VALUE rb_window)
+{ return wrap_panel(new_panel(get_window(rb_window))); }
+static VALUE rbncurs_m_new_panel(VALUE dummy, VALUE rb_window)
+{ return rbncurs_c_new_panel(rb_window); }
+static VALUE rbncurs_c_panel_above(VALUE rb_panel)
+{ return wrap_panel(panel_above(get_panel(rb_panel))); }
+static VALUE rbncurs_m_panel_above(VALUE rb_panel)
+{ return rbncurs_c_panel_above(rb_panel); }
+static VALUE rbncurs_c_panel_below(VALUE rb_panel)
+{ return wrap_panel(panel_below(get_panel(rb_panel))); }
+static VALUE rbncurs_m_panel_below(VALUE rb_panel)
+{ return rbncurs_c_panel_below(rb_panel); }
+static VALUE rbncurs_c_set_panel_userptr(VALUE rb_panel, VALUE userptr)
+{ return INT2NUM(set_panel_userptr(get_panel(rb_panel),
+ (void*)(userptr))); }
+static VALUE rbncurs_m_set_panel_userptr(VALUE dummy, VALUE rb_panel, VALUE userptr)
+{ return rbncurs_c_set_panel_userptr(rb_panel, userptr); }
+static VALUE rbncurs_c_panel_userptr(VALUE rb_panel)
+{ return (VALUE)(panel_userptr(get_panel(rb_panel))); }
+static VALUE rbncurs_m_panel_userptr(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_panel_userptr(rb_panel); }
+static VALUE rbncurs_c_move_panel(VALUE rb_panel, VALUE starty, VALUE startx)
+{ return INT2NUM(move_panel(get_panel(rb_panel), NUM2INT(starty),
+ NUM2INT(startx))); }
+static VALUE rbncurs_m_move_panel(VALUE dummy, VALUE rb_panel, VALUE starty, VALUE startx)
+{ return rbncurs_c_move_panel(rb_panel, starty, startx); }
+static VALUE rbncurs_c_replace_panel(VALUE rb_panel, VALUE rb_window)
+{ return INT2NUM(replace_panel(get_panel(rb_panel), get_window(rb_window))); }
+static VALUE rbncurs_m_replace_panel(VALUE dummy, VALUE rb_panel, VALUE rb_window)
+{ return rbncurs_c_replace_panel(rb_panel, rb_window); }
+static VALUE rbncurs_c_panel_hidden(VALUE rb_panel)
+{ return panel_hidden(get_panel(rb_panel)) ? Qtrue : Qfalse; }
+static VALUE rbncurs_m_panel_hidden(VALUE dummy, VALUE rb_panel)
+{ return rbncurs_c_panel_hidden(rb_panel); }
+
+
+void init_panel(void)
+{
+ mPanel = rb_define_module_under(mNcurses, "Panel");
+ rb_iv_set(mPanel, "@panels_hash", rb_hash_new());
+ cPANEL = rb_define_class_under(mPanel, "PANEL", rb_cObject);
+ rb_define_singleton_method(mPanel, "del_panel",
+ (&rbncurs_m_del_panel),
+ 1);
+ rb_define_singleton_method(mPanel, "delpanel",
+ (&rbncurs_m_del_panel),
+ 1);
+ rb_define_method(cPANEL, "del",
+ (&rbncurs_c_del_panel), 0);
+ rb_define_method(cPANEL, "delete",
+ (&rbncurs_c_del_panel), 0);
+ rb_define_singleton_method(mPanel, "panel_window",
+ (&rbncurs_m_panel_window),
+ 1);
+ rb_define_method(cPANEL, "panel_window",
+ (&rbncurs_c_panel_window), 0);
+ rb_define_method(cPANEL, "window",
+ (&rbncurs_c_panel_window), 0);
+ rb_define_singleton_method(mPanel, "update_panels",
+ (&rbncurs_m_update_panels),
+ 0);
+ rb_define_singleton_method(mPanel, "update",
+ (&rbncurs_m_update_panels),
+ 0);
+ rb_define_singleton_method(mPanel, "hide_panel",
+ (&rbncurs_m_hide_panel),
+ 1);
+ rb_define_method(cPANEL, "hide_panel",
+ (&rbncurs_c_hide_panel), 0);
+
+ rb_define_method(cPANEL, "hide",
+ (&rbncurs_c_hide_panel), 0);
+ rb_define_singleton_method(mPanel, "show_panel",
+ (&rbncurs_m_show_panel),
+ 1);
+ rb_define_method(cPANEL, "show_panel",
+ (&rbncurs_c_show_panel), 0);
+
+ rb_define_method(cPANEL, "show",
+ (&rbncurs_c_show_panel), 0);
+ rb_define_singleton_method(mPanel, "top_panel",
+ (&rbncurs_m_top_panel), 1);
+ rb_define_method(cPANEL, "top_panel",
+ (&rbncurs_c_top_panel), 0);
+
+ rb_define_method(cPANEL, "top",
+ (&rbncurs_c_top_panel), 0);
+ rb_define_singleton_method(mPanel, "bottom_panel",
+ (&rbncurs_m_bottom_panel),
+ 1);
+ rb_define_method(cPANEL, "bottom_panel",
+ (&rbncurs_c_bottom_panel), 0);
+
+ rb_define_method(cPANEL, "bottom",
+ (&rbncurs_c_bottom_panel), 0);
+ rb_define_singleton_method(mPanel, "new_panel",
+ (&rbncurs_m_new_panel),
+ 1);
+ rb_define_singleton_method(cPANEL, "new",
+ (&rbncurs_m_new_panel),
+ 1);
+ rb_define_method(cWINDOW, "new_panel",
+ (&rbncurs_c_new_panel),
+ 0);
+ rb_define_singleton_method(mPanel, "panel_above",
+ (&rbncurs_m_panel_above),
+ 1);
+ rb_define_method(cPANEL, "panel_above",
+ (&rbncurs_c_panel_above), 0);
+ rb_define_method(cPANEL, "above",
+ (&rbncurs_c_panel_above), 0);
+ rb_define_singleton_method(mPanel, "panel_below",
+ (&rbncurs_m_panel_below),
+ 1);
+ rb_define_method(cPANEL, "panel_below",
+ (&rbncurs_c_panel_below), 0);
+ rb_define_method(cPANEL, "below",
+ (&rbncurs_c_panel_below), 0);
+ rb_define_singleton_method(mPanel, "set_panel_userptr",
+ (&rbncurs_m_set_panel_userptr), 2);
+ rb_define_method(cPANEL, "set_panel_userptr",
+ (&rbncurs_c_set_panel_userptr),
+ 1);
+ rb_define_method(cPANEL, "set_userptr",
+ (&rbncurs_c_set_panel_userptr),
+ 1);
+ rb_define_method(cPANEL, "userptr=",
+ (&rbncurs_c_set_panel_userptr),
+ 1);
+ rb_define_singleton_method(mPanel, "panel_userptr",
+ (&rbncurs_m_panel_userptr),
+ 1);
+ rb_define_method(cPANEL, "panel_userptr",
+ (&rbncurs_c_panel_userptr),
+ 0);
+ rb_define_method(cPANEL, "userptr",
+ (&rbncurs_c_panel_userptr),
+ 0);
+ rb_define_singleton_method(mPanel, "move_panel",
+ (&rbncurs_m_move_panel),
+ 3);
+ rb_define_method(cPANEL, "move_panel",
+ (&rbncurs_c_move_panel), 2);
+ rb_define_method(cPANEL, "move",
+ (&rbncurs_c_move_panel), 2);
+ rb_define_singleton_method(mPanel, "replace_panel",
+ (&rbncurs_m_replace_panel),
+ 2);
+ rb_define_method(cPANEL, "replace_panel",
+ (&rbncurs_c_replace_panel), 1);
+ rb_define_method(cPANEL, "replace",
+ (&rbncurs_c_replace_panel), 1);
+ rb_define_singleton_method(mPanel, "panel_hidden?",
+ (&rbncurs_m_panel_hidden),
+ 1);
+ rb_define_method(cPANEL, "panel_hidden?",
+ (&rbncurs_c_panel_hidden), 0);
+ rb_define_method(cPANEL, "hidden?",
+ (&rbncurs_c_panel_hidden), 0);
+}
+
+#endif
diff --git a/panel_wrap.h b/panel_wrap.h
@@ -0,0 +1,32 @@
+/*
+ * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
+ * (C) 2002 Tobias Peters <t-peters@berlios.de>
+ *
+ * This module is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This module is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this module; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: panel_wrap.h,v 1.5 2004/07/31 08:35:13 t-peters Exp $ */
+
+#if !defined(PANEL_HH) && defined(HAVE_PANEL_H)
+#define PANEL_HH
+#include <panel.h>
+#include <ruby.h>
+
+extern VALUE mPanel;
+extern VALUE cPANEL;
+
+void init_panel(void);
+
+#endif