Ada95 Binding for ncurses
The ncurses Ada95 binding is © 1996 by
Permission is hereby granted to reproduce and distribute this
binding by any means and for any fee, whether alone or as part
of a larger distribution, in source or in binary form, PROVIDED
this notice is included with any such distribution, and is not
removed from any of its header files. Mention of ncurses and the
author of this binding in any applications linked with it is
This binding comes AS IS with no warranty, implied or expressed.
- This document describes Version 00.92.00 of the binding.
- The functionality is modelled to be compatible with the ncurses
package, a clone of the SVr4 curses model.
I did the development on an Intel box running
Linux 1.3.x and 2.0,
ncurses-1.9.9e and the
GNU Ada Translator
gnat-3.05. For any older versions of ncurses and gnat
it will not work.
- You must have the m4 macroprocessor to build this package.
If you don't have this program, you can get the FSF version
- Ada programs are supposed to be readable. One of my
favourite methods to make code readable is to use expressive
names for the identifiers. You can find a list of a mapping
of the cryptic curses names to the Ada names in this table.
- This is not a typical one-2-one interface mapping. It is
close to one-2-one on the functional level. Each (n)curses function
has it's counterpart with a more or less similar formal parameter list
in the binding. It is not one-2-one with respect to the datatypes.
I tried to make records out of the flat chtype and similar structures,
so you don't have to do bit operations to mark an attributed character
as bold. Just make the boolean member bold of the record
true. The binding also hides the structures like WINDOW, PANEL, MENU, FORM
etc. ! It's a pure functional API.
- I try to do as much error checking as possible and feasible
in the binding. I will raise an Ada exception when something
went wrong in the low-level curses. This has the effect that - at least
first time in my life - (n)curses programs have now a very rigid error
checking, but - thanks to Ada - you don't have to code the orgiastic
error checking style of C.
- Support for wide characters is currently not in the binding, as it
is not really in ncurses at this point in time.
- I provide no SCREEN datatype and functions to set a new screen.
If you need this (mostly for debugging I guess), write a small
C routine doing all this and import it into your Ada program.
- I provide no functions to switch on/off curses tracing options.
Same suggestion as above.
- Although Ada95 is an OO Language, this binding doesn't provide
an OO abstraction of the (n)curses functionality. As mentioned above
it's a thin binding for the (n)curses functions. But without any
doubt it would be nice to build on top of this an OO abstraction
of (n)curses functionality.
- If you use the user-pointer mechanism for most of the ncurses
structures in a mixed language environemt, i.e. Ada95 and C routines
operate on the same objects, care must be taken because the Ada
binding itself uses the user pointer mechanism for it's own purposes.
See the corresponding section in implementention
- I currently do not support the link_fieldtype functionality of the
- The *_IO packages are currently output only.
Hierarchy of packages
Behind the abstraction
All the new types like Window, Panel,
Menu, Form etc. are just
opaque representations of the pointers to the corresponding
low level (n)curses structures like
WINDOW *, PANEL *,
MENU * or FORM *.
So you can safely pass them to C routines that expect a pointer
to one of those structures.
Item and Field Arrays
In C you have to pass the item and field arrays to define menus or forms
terminated by a null item or null field. This is not necessary in this
binding. The binding routines will construct from an Ada95 style array
of Item or Field objects internally the properly terminated array of
C structure pointers. See the examples for more details.
Extended ripoffline() usage
The official documentation of (n)curses says, that the line parameter
determines only whether or not exactly one line is
stolen from the top or bottom of the screen. So essentially only the
sign of the parameter is evaluated. ncurses has internally implemented
it in a way, that uses the line parameter also to control the amount of
lines to steal. This mechanism is used in the Rip_Off_Lines
routine of the binding.
User Pointer mechanism
How user defined field types work
Enumeration fields handling
The (n)curses documentation says, that the String arrays to be passed to
an TYPE_ENUM fieldtype must not be automatic variables. This is not true
in this binding, because it is internally arranged to safely copy these
Using other Ada compilers
This should basically not be a problem, but you have to replace a code
sequence in package
that uses a hashing package supplied with the GNAT runtime, which is not part
of the Standard Ada runtimes. This should not be too hard. I intend to remove
this dependency in the future.
Port to other curses implementations
Basically it should not be too hard to make all this run on a regular SVr4
implementation of curses. The problems are probably these:
I'm quite sure I forgot something.
- ncurses has some additional features which are presented in this binding. You
have two choices to deal with this:
Most likely you will follow a mixed approach. Some features are easy to simulate,
others will be hard if not impossible.
- Emulate the feature in this binding
- Raise an exception for non implemented features
- For menu items, the name and descriptions are internally copied by ncurses.
So the binding doesn't care for the lifetime of the strings passed to the
construction routine for items. This assumption is not true in most other implementations
of the menu library. In this case you have to modify the binding routine
New_Item to safestore the strings.