Ncurses Library On

Posted on  by 

  • How do I write a simple hello world program using the ncurses and compile it on a Linux? GNU ncurses is software API for controlling writing to the console screen under Unix, Linux and other operating systems. You can create text-based user interfaces (TUI) on a Linux or Unix-like system using ncurses library.
  • Ncurses is only a library that helps you manage interactions with the underlying terminal environment. But it doesn't provide a terminal emulator itself. The thing that actually displays stuff on the screen (which in your requirement is listed as 'native resizable win32 windows') is usually called a Terminal Emulator.
  • If you've read this far and want a more in-depth introduction to the features and useage of the library, check out the NCURSES Programming HOWTO and Writing Programs with NCURSES tutorials. As your games become more complex, you'll want to read up on the advanced windowing capabilities of the library - take a look at the functions newwin.

Installing the ncurses library; Controlling LEDs and a buzzer using ncurses; Controlling a rover using a laptop keyboard; Installing and setting up QT5; Controlling LEDs with GUI buttons; Controlling a rover using a laptop with QT5; Summary; Questions. The ncurses (new curses) library is a free software emulation of curses in System V Release 4.0 (SVr4), and more. It uses terminfo format, supports pads and color and multiple highlights and forms characters and function-key mapping, and has all the other SVr4-curses enhancements over BSD curses.

ncurses
Developer(s)GNU Project
Initial release1993; 28 years ago
Stable release
6.2 / 12 February 2020; 17 months ago
Repository
Written inC
Operating systemPOSIX
TypeWidget toolkit
LicenseX11 License[1]
Websiteinvisible-island.net/ncurses/

ncurses (new curses) is a programming library providing an application programming interface (API) that allows the programmer to write text-based user interfaces in a terminal-independent manner. It is a toolkit for developing 'GUI-like' application software that runs under a terminal emulator. It also optimizes screen changes, in order to reduce the latency experienced when using remote shells.

ncurses is a free-software emulation of the System V Release 4.0 (SVr4) curses.

There are bindings for ncurses in a variety of programming languages, including Ada,[2]Python,[3]Gambas,[4]Ruby,[5]PHP,[6]JavaScript,[7] and Perl.[8]

History[edit]

Ncurses Library Online

As the new version, ncurses is a free-software emulation of the System V Release 4.0 (SVr4) curses, which was itself an enhancement over the discontinued 4.4 BSD curses.[9] The XSI Curses standard issued by X/Open is explicitly and closely modeled on System V.

curses[edit]

The first curses library was developed at the University of California at Berkeley, for a BSD operating system, around 1980 to support Rogue, a text-based adventure game. It originally used the termcap library, which was used in other programs, such as the vi editor.[9]

The success of the BSD curses library prompted Bell Labs to release an enhanced curses library in their System V Release 2 Unix systems. This library was more powerful and instead of using termcap, it used terminfo. However, due to AT&T policy regarding source-code distribution, this improved curses library did not have much acceptance in the BSD community.[9]

pcurses[edit]

Around 1982, Pavel Curtis started work on a freeware clone of the Bell Labs curses, named pcurses, which was maintained by various people through 1986.[10]

ncurses[edit]

The pcurses library was further improved when Zeyd Ben-Halim took over the development effort in late 1991.[9][10][11] The new library was released as ncurses in November 1993, with version 1.8.1 as the first major release. Subsequent work, through version 1.8.8 (M1995), was driven by Eric S. Raymond, who added the form and menu libraries written by Juergen Pfeifer.[12] Since 1996, it has been maintained by Thomas E. Dickey.[10]

Most ncurses calls can be easily ported to the old curses. System V curses implementations can support BSD curses programs with just a recompilation.[13] However, a few areas are problematic, such as handling terminal resizing, since no counterpart exists in the old curses.

Terminal database[edit]

Ncurses Library Documentation

Ncurses can use either terminfo (with extensible data) or termcap. Other implementations of curses generally use terminfo; a minority use termcap. Few (mytinfo was an older exception[14]) use both.

License[edit]

Ncurses is a part of the GNU Project. It is one of the few GNU files not distributed under the GNU GPL or LGPL; it is distributed under a permissive free software licence, similar to the MIT License.[15] This is due to the agreement made with the Free Software Foundation at the time the developers assigned their copyright.

When the agreement was made to pass on the rights to the FSF, there was a clause that stated:[15]

The Foundation promises that all distribution of the Package, or of any work 'based on the Package', that takes place under the control of the Foundation or its agents or assignees, shall be on terms that explicitly and perpetually permit anyone possessing a copy of the work to which the terms apply, and possessing accurate notice of these terms, to redistribute copies of the work to anyone on the same terms.

According to the maintainer Thomas E. Dickey, this precludes relicensing to the GPL in any version, since it would place restrictions on the programs that will be able to link to the libraries.[15]

Programs using ncurses[edit]

There are hundreds of programs which use ncurses.[16][17] Some, such as GNU Screen and w3m, use only the termcap interface and perform screen management themselves. Others, such as GNU Midnight Commander and YaST, use the curses programming interface.

See also[edit]

Ncurses Library OnLibrary
  • conio.h – A C header file used in MS-DOS compilers to create text user interfaces
  • SMG$ – The screen-management library available under OpenVMS

References[edit]

  1. ^'NCURSES — Licensing'. Retrieved July 9, 2013.
  2. ^Ada95 Binding for ncurses
  3. ^Curses Programming with Python - Python documentation
  4. ^gb.ncurses - Gambas Wiki
  5. ^ncurses Ruby - RubyGems.org
  6. ^Ncurses functions - PHP Manual
  7. ^nc plugin: ncurses bindings for SpiderApe
  8. ^Curses::UI - A curses based OO user interface framework
  9. ^ abcdEric S. Raymond (September 1995). 'ncurses: Portable Screen-Handling for Linux'. Linux Journal.
  10. ^ abcThomas E. Dickey (December 1996). 'NCURSES - New Curses'.
  11. ^The README file in ncurses 1.8.1 states 'v0.1 July 31, 1992' and 'v1.8.1 November 5, 1993', which agrees with the NEWS (changelog) file
  12. ^NCURSES - Frequently Asked Questions (FAQ): Who wrote NCURSES?
  13. ^A Hacker's Guide to Ncurses Internals
  14. ^Sydney S. Weinstein (April 1993). 'On the Networks'. C/C++ Users Journal. Archived from the original on 2014-08-11. Retrieved 2017-09-15.
  15. ^ abcNCURSES - Frequently Asked Questions (FAQ): Is it GPL'd?
  16. ^'Search results: +ncurses on freshmeat.net'. Archived from the original on February 18, 2012. Retrieved 2013-05-10.
  17. ^'Projects tagged 'ncurses''. ohloh.

External links[edit]

  • Official website
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Ncurses&oldid=1018855132'

Almost all the programmers or every Computer science student in the wild would have practiced C programming, some might have just memorized few programs for the sake of exams. But still, those who really gained the knowledge to write C programs would have missed out all the interesting concepts of C, and Curses is one of them, available on all Linux and Unix variants. You can run Curses with Cygwin for Windows. Now after years of development and with new features added it is called as Ncurses ( New Curses ). Developed in early 1980 to manage application’s display on character-cell terminals.

Programming with NCurses will be lot more interesting because of the formatted output, but it is lot more than that. It aims at providing a library of advanced functions that can be used to develop wonderful applications with “GUI like” interface with C. You can control every input including keyboard and mouse, as well as the output.

Creating menu with Ncurses in C.

Though Ncurses has a special include directive “menu.h” for creating beautiful and flexible menus, in this article I am not going to use it, we will create a menu with basic Ncurses functions. But before going into the program we will see how Ncurses handles the rows and columns of the terminal screen.

The above image shows how curses library maps the screen into rows and columns. ( As always programmers count form zero. ). With this basic understanding let’s go into the code.

Simple menu Programs with NCURSES

The above sample code will draw a box with menu items printed and the first menu item highlighted. And will wait for the user input, upon pressing the up and down arrow keys you can navigate the menu. Here is the code break-down and instruction on how to run a C program with Ncurses library.

First we should include the ncurses.h header to use the Ncurses functions – #include <ncurses.h>, then within the program we should start with initscr() function which initializes NCurses. Many say that it clears the terminal screen, but it actually sets up the internal memory structures and input/output interfaces between the NCurses functions and your computer’s terminal.

Then we create a new window, with the newwin() function. This function has to be given four co-ordinates which is rows, cols, y_orgin, and x_orgin respectively.

Then the call to box() function defines a window border clearly, so that you can have make it standout on your terminal screen, also know that, this just draws border, which is prone to overwriting and accidental erasing.

After creating the window we print all the menu items one below the other and highlight the first item. For high-lighting the text we use wattron() function, with A_STANDOUT attribute, few more high-lighting modes are available for which you can refer the Ncurses manual page.

Then we disable echo and enable keypad to capture the special keys and navigate the menu. We are also using sprintf to right pad the string with spaces to display them with even width.

Compiling and linking Ncurses programs

You should compile Ncurses programs by linking it to Ncurses library like this.

gcc program.c -lncurses

The above program will give you the following output, You can also expand it to the most advanced menu or bar menu or as you wish. Happy coding!!


Creating Menu with Curses Menu Library in C

Coments are closed