A Hacker's Guide to NCURSES

Contents

Abstract

This document is a hacker's tour of the ncurses library and utilities. It discusses design philosophy, implementation methods, and the conventions used for coding and documentation. It is recommended reading for anyone who is interested in porting, extending or improving the package.

Objective of the Package

The objective of the ncurses package is to provide a free software API for character-cell terminals and terminal emulators with the following characteristics: These objectives are in priority order. So, for example, source compatibility with older version must trump featurefulness -- we cannot add features if it means breaking the portion of the API corresponding to historical curses versions.

Why System V Curses?

We used System V curses as a model, reverse-engineering their API, in order to fulfill the first two objectives.

System V curses implementations can support BSD curses programs with just a recompilation, so by capturing the System V API we also capture BSD's.

More importantly for the future, the XSI Curses standard issued by X/Open is explicitly and closely modeled on System V. So conformance with System V took us most of the way to base-level XSI conformance.

How to Design Extensions

The third objective (standards conformance) requires that it be easy to condition source code using ncurses so that the absence of nonstandard extensions does not break the code.

Accordingly, we have a policy of associating with each nonstandard extension a feature macro, so that ncurses client code can use this macro to condition in or out the code that requires the ncurses extension.

For example, there is a macro NCURSES_MOUSE_VERSION which XSI Curses does not define, but which is defined in the ncurses library header. You can use this to condition the calls to the mouse API calls.

Portability and Configuration

Code written for ncurses may assume an ANSI-standard C compiler and POSIX-compatible OS interface. It may also assume the presence of a System-V-compatible select(2) call.

We encourage (but do not require) developers to make the code friendly to less-capable UNIX environments wherever possible.

We encourage developers to support OS-specific optimizations and methods not available under POSIX/ANSI, provided only that:

We use GNU autoconf(1) as a tool to deal with portability issues. The right way to leverage an OS-specific feature is to modify the autoconf specification files (configure.in and aclocal.m4) to set up a new feature macro, which you then use to condition your code.

Documentation Conventions

There are three kinds of documentation associated with this package. Each has a different preferred format: Our conventions are simple:
  1. Maintain package-internal files in plain text. The expected viewer for them more(1) or an editor window; there's no point in elaborate mark-up.
  2. Mark up manual pages in the man macros. These have to be viewable through traditional man(1) programs.
  3. Write everything else in HTML.
When in doubt, HTMLize a master and use lynx(1) to generate plain ASCII (as we do for the announcement document).

The reason for choosing HTML is that it's (a) well-adapted for on-line browsing through viewers that are everywhere; (b) more easily readable as plain text than most other mark-ups, if youA>

* * 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. * **************************************************************************** --> A Hacker's Guide to Ncurses Internals

A Hacker's Guide to NCURSES

Contents

Abstract

This document is a hacker's tour of the ncurses library and utilities. It discusses design philosophy, implementation methods, and the conventions used for coding and documentation. It is recommended reading for anyone who is interested in porting, extending or improving the package.

Objective of the Package

The objective of the ncurses package is to provide a free software API for character-cell terminals and terminal emulators with the following characteristics: These objectives are in priority order. So, for example, source compatibility with older version must trump featurefulness -- we cannot add features if it means breaking the portion of the API corresponding to historical curses versions.

Why System V Curses?

We used System V curses as a model, reverse-engineering their API, in order to fulfill the first two objectives.

System V curses implementations can support BSD curses programs with just a recompilation, so by capturing the System V API we also capture BSD's.

More importantly for the future, the XSI Curses standard issued by X/Open is explicitly and closely modeled on System V. So conformance with System V took us most of the way to base-level XSI conformance.

How to Design Extensions

The third objective (standards conformance) requires that it be easy to condition source code using ncurses so that the absence of nonstandard extensions does not break the code.

Accordingly, we have a policy of associating with each nonstandard extension a feature macro, so that ncurses client code can use this macro to condition in or out the code that requires the ncurses extension.

For example, there is a macro NCURSES_MOUSE_VERSION which XSI Curses does not define, but which is defined in the ncurses library header. You can use this to condition the calls to the mouse API calls.

Portability and Configuration

Code written for ncurses may assume an ANSI-standard C compiler and POSIX-compatible OS interface. It may also assume the presence of a System-V-compatible select(2) call.

We encourage (but do not require) developers to make the code friendly to less-capable UNIX environments wherever possible.

We encourage developers to support OS-specific optimizations and methods not available under POSIX/ANSI, provided only that:

We use GNU autoconf(1) as a tool to deal with portability issues. The right way to leverage an OS-specific feature is to modify the autoconf specification files (configure.in and aclocal.m4) to set up a new feature macro, which you then use to condition your code.

Documentation Conventions

There are three kinds of documentation associated with this package. Each has a different preferred format: Our conventions are simple:
  1. Maintain package-internal files in plain text. The expected viewer for them more(1) or an editor window; there's no point in elaborate mark-up.
  2. Mark up manual pages in the man macros. These have to be viewable through traditional man(1) programs.
  3. Write everything else in HTML.
When in doubt, HTMLize a master and use lynx(1) to generate plain ASCII (as we do for the announcement document).

The reason for choosing HTML is that it's (a) well-adapted for on-line browsing through viewers that are everywhere; (b) more easily readable as plain text than most other mark-ups, if youA>

* * 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. * **************************************************************************** --> A Hacker's Guide to Ncurses Internals

A Hacker's Guide to NCURSES

Contents

Abstract

This document is a hacker's tour of the ncurses library and utilities. It discusses design philosophy, implementation methods, and the conventions used for coding and documentation. It is recommended reading for anyone who is interested in porting, extending or improving the package.

Objective of the Package

The objective of the ncurses package is to provide a free software API for character-cell terminals and terminal emulators with the following characteristics: These objectives are in priority order. So, for example, source compatibility with older version must trump featurefulness -- we cannot add features if it means breaking the portion of the API corresponding to historical curses versions.

Why System V Curses?

We used System V curses as a model, reverse-engineering their API, in order to fulfill the first two objectives.

System V curses implementations can support BSD curses programs with just a recompilation, so by capturing the System V API we also capture BSD's.

More importantly for the future, the XSI Curses standard issued by X/Open is explicitly and closely modeled on System V. So conformance with System V took us most of the way to base-level XSI conformance.

How to Design Extensions

The third objective (standards conformance) requires that it be easy to condition source code using ncurses so that the absence of nonstandard extensions does not break the code.

Accordingly, we have a policy of associating with each nonstandard extension a feature macro, so that ncurses client code can use this macro to condition in or out the code that requires the ncurses extension.

For example, there is a macro NCURSES_MOUSE_VERSION which XSI Curses does not define, but which is defined in the ncurses library header. You can use this to condition the calls to the mouse API calls.

Portability and Configuration

Code written for ncurses may assume an ANSI-standard C compiler and POSIX-compatible OS interface. It may also assume the presence of a System-V-compatible select(2) call.

We encourage (but do not require) developers to make the code friendly to less-capable UNIX environments wherever possible.

We encourage developers to support OS-specific optimizations and methods not available under POSIX/ANSI, provided only that:

We use GNU autoconf(1) as a tool to deal with portability issues. The right way to leverage an OS-specific feature is to modify the autoconf specification files (configure.in and aclocal.m4) to set up a new feature macro, which you then use to condition your code.

Documentation Conventions

There are three kinds of documentation associated with this package. Each has a different preferred format: Our conventions are simple:
  1. Maintain package-internal files in plain text. The expected viewer for them more(1) or an editor window; there's no point in elaborate mark-up.
  2. Mark up manual pages in the man macros. These have to be viewable through traditional man(1) programs.
  3. Write everything else in HTML.
When in doubt, HTMLize a master and use lynx(1) to generate plain ASCII (as we do for the announcement document).

The reason for choosing HTML is that it's (a) well-adapted for on-line browsing through viewers that are everywhere; (b) more easily readable as plain text than most other mark-ups, if youA>

* * 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. * **************************************************************************** --> A Hacker's Guide to Ncurses Internals

A Hacker's Guide to NCURSES

Contents

Abstract

This document is a hacker's tour of the ncurses library and utilities. It discusses design philosophy, implementation methods, and the conventions used for coding and documentation. It is recommended reading for anyone who is interested in porting, extending or improving the package.

Objective of the Package

The objective of the ncurses package is to provide a free software API for character-cell terminals and terminal emulators with the following characteristics: These objectives are in priority order. So, for example, source compatibility with older version must trump featurefulness -- we cannot add features if it means breaking the portion of the API corresponding to historical curses versions.

Why System V Curses?

We used System V curses as a model, reverse-engineering their API, in order to fulfill the first two objectives.

System V curses implementations can support BSD curses programs with just a recompilation, so by capturing the System V API we also capture BSD's.

More importantly for the future, the XSI Curses standard issued by X/Open is explicitly and closely modeled on System V. So conformance with System V took us most of the way to base-level XSI conformance.

How to Design Extensions

The third objective (standards conformance) requires that it be easy to condition source code using ncurses so that the absence of nonstandard extensions does not break the code.

Accordingly, we have a policy of associating with each nonstandard extension a feature macro, so that ncurses client code can use this macro to condition in or out the code that requires the ncurses extension.

For example, there is a macro NCURSES_MOUSE_VERSION which XSI Curses does not define, but which is defined in the ncurses library header. You can use this to condition the calls to the mouse API calls.

Portability and Configuration

Code written for ncurses may assume an ANSI-standard C compiler and POSIX-compatible OS interface. It may also assume the presence of a System-V-compatible select(2) call.

We encourage (but do not require) developers to make the code friendly to less-capable UNIX environments wherever possible.

We encourage developers to support OS-specific optimizations and methods not available under POSIX/ANSI, provided only that:

We use GNU autoconf(1) as a tool to deal with portability issues. The right way to leverage an OS-specific feature is to modify the autoconf specification files (configure.in and aclocal.m4) to set up a new feature macro, which you then use to condition your code.

Documentation Conventions

There are three kinds of documentation associated with this package. Each has a different preferred format: Our conventions are simple:
  1. Maintain package-internal files in plain text. The expected viewer for them more(1) or an editor window; there's no point in elaborate mark-up.
  2. Mark up manual pages in the man macros. These have to be viewable through traditional man(1) programs.
  3. Write everything else in HTML.
When in doubt, HTMLize a master and use lynx(1) to generate plain ASCII (as we do for the announcement document).

The reason for choosing HTML is that it's (a) well-adapted for on-line browsing through viewers that are everywhere; (b) more easily readable as plain text than most other mark-ups, if youA>

* * 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. * **************************************************************************** --> A Hacker's Guide to Ncurses Internals

A Hacker's Guide to NCURSES

Contents