Last updated: December 12, 2018
Learn Ncurses: Get Started Developing Text Interfaces
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
Ncurses is a library used primarily in Linux- and Unix-based operating systems that provides a text-based visual interface for a variety of tools. This means that a program using ncurses can display a GUI-like interface within a terminal window that supports keyboard and mouse navigation. In other words, it provides functions to move the cursor, create windows, produce colors, and more without writing directly for any specific terminal type.
It is as a clone of System V Release 4.0 curses and it’s freely distributed under under the Permissive Free Software Licence, similar to the MIT License.
Brief History of Ncurses
Ncurses has an evolved history that dates back to curses. The first curses library was developed at the University of California at Berkeley and it used the termcap database, which documented how different terminals are controlled. After the success of the new library, Bell Labs released an enhanced curses library in their System V Release 2 which used terminfo database. But due to the licensing restrictions, this library didn’t have much acceptance in the BSD community.
In the early 80s, Pavel Curtis started working on a freeware clone of the Bell Labs library called pcurses which was maintained all the way through 1986. This new library was further improved when Zeyd Ben-Halim took over the development and it was eventually released as ncurses in November 1993. Throughout the following years, dozens of people contributed to ncurses which led to its active development and improvement. Since 1996, ncurses has been maintained by Thomas E Dickey.
Ncurses has been ported to many systems and it’s used in almost every system based on the Linux kernel, as the system curses library on OpenBSD, FreeBSD and OSX, and in environments such as Cygwin and MinGW.
The ncurses library provides a robust framework which allows programmers to create visually appealing user interfaces in text mode. Its functions allow programmers and developers to create applications containing multiple windows, forms, menus, and panels which facilitate command selection, data entry, and dealing with overlapping and stacked windows.
Some of the advantages of ncurses include:
- The ability to provide users with a menu-driven interface
- The ability to use check-boxes, multiple sub-menus, and even text input for selecting options and commands
- A more user-friendly environment for users who are comfortable with graphical interfaces.
Examples of Programs Using Ncurses
Some programs that use ncurses include:
- GNU Midnight Commander: a visual file manager.
- Aptitude: a visual frontend for the APT package management tool used in Debian and other operating systems.
- Lynx: the text-based internet browser.
- Nvi: new vi, a re-implementation of the classic vi editor traditionally distributed with BSD and Unix systems.
- Emacs: another text editor found in many Unix systems.
The resources below cover everything under the sun related to ncurses: from history to practical examples and applications in various programming languages such as C, Python, and PHP.
- Official Website: the official website for ncurses with a detailed overview and download links.
- A Hacker’s Guide to Ncurses: this guide discusses design philosophy, implementation methods, and the conventions used for coding and documentation. It’s aimed at those who would like to contribute, port, or modify the package.
- Ncurses FAQ: a detailed FAQ provided by Thomas Dickey who is responsible for ncurses maintenance.
- Ncurses: a very detailed and thorough overview of ncurses, its history, development, and features.
- Ncurses Programming How To: this tutorial provides comprehensive information on using ncurses and guides you from writing a simple “Hello World!” program to more complex form manipulation. It assumes no prior experience and includes plenty of details and examples.
- How To Install Ncurses Library on a Linux: basic and to-the-point tutorial that explains how to install ncurses on several Linux distributions.
- Game Programming in C with the ncurses Library: slightly more advanced tutorial which walks you through creating a simple simulation of a ball that bounces back and forth across the screen.
- Ncurses Terminal Screen Control: complete manual for using ncurses with PHP.
- Ncurses Library Tutorial for Beginners: this tutorial guides you through creating a simple interface for a text editor.
- Code Project: Build an Ncurses UI With Python: another slightly more advanced tutorial that explains how to use Python and ncurses to create a user interface.
- Ncurses Examples: this page has several examples of simple programs and games that use ncurses.
- Creating Menu with Ncurses In C: a tutorial that focuses on using the C programming language and basic ncurses functions to create a simple menu.
Several books cover ncurses in great detail and provide useful references and examples.
- Programmer’s Guide to NCurses (2007) by Dan Gookin: this book serves as a straightforward guide to the ncurses library and includes a complete reference of more than 175 functions which are cross-referenced and illustrated with examples.
- Guile NCurses Library (2015) by The NCurses Team: this book provides an in-depth overview of different terminals and explains how the ncurses library helps simplify the task of programming for character-cell terminals.
- Termcap & Terminfo (O’Reilly Nutshell) (1988) by Mui, O’Reilly, and Strang: while the book doesn’t deal specifically with ncurses, it provides useful information on termcap and terminfo databases. Terminfo is used by ncurses so this book is a great companion to the books mentioned above as it provides examples of capabilities and syntax for termcap and terminfo, writing and debugging terminal descriptions, and terminal initialization.
Don’t Swear, Use Ncurses
Even though almost every application, software, and gadget we use today has a graphical user interface, knowing how to work with a text based UI has its applications and advantages too. It comes in handy if you’re interested in working with remote servers or using hardware with limited capabilities. The resources above will set you on the right path of mastering ncurses.
Further Reading and Resources
We have more guides, tutorials, and infographics related to coding and development:
- Mantis Hosting: find out what web hosting companies offer good deals that include this popular bug tracking program.
- Ubuntu Primer: learn all about one of the most popular Linux distributions.
- Object-Oriented Programming: learn about the wide range of object-oriented programming languages — some may surprise you.
Would the Internet Survive the End of the World?
Have you ever wondered what a major catastrophe would do to the internet? Check out our infographic, Would the Internet Survive the End of the World? It’s possible we could all be destroyed but the internet would live on.