Back to article
Discovering ncurses, the GUI for the Linux Console
ncurses, a GUI for the Linux Console
January 25, 2010
The CLI versus GUI debate is well-known, but sometimes, drawing a hard line between text-only interfaces and graphical interfaces is too restrictive. Most of the time, if you're using a terminal (whether over SSH or on the console), the CLI and text-only interface works great. Sometimes, though, it can be a real advantage to be able to use at least some graphical logic, without having to fire up an X server. Not all servers run X; you don't always want to forward X to your remote terminal; or you may be at a stage of system or hardware install that prevents you from running a regular graphical interface.
This is where ncurses comes in. The ncurses library allows you to write programs that work in a GUI-like way, but which will run within a normal terminal emulator. You've almost certainly already encountered programs that use ncurses, including:
Midnight Commander, the powerful ncurses-based file manager
ncurses is a C library which provides a variety of functions for handling screen drawing, cursor management, mouse management, and so on. It isn't released under the GPL, but under a specific free software copyright notice which is discussed in the FAQ.
As a programmer, using ncurses means that you don't have to deal with the massive variety of slightly different terminal codes that exist. Instead, you can just deal with the more abstract concept of a display with multiple windows, and ncurses will handle the translation into control codes for whichever terminal emulator it detects that the program is running under. It can also handle mouse events, so if you have a mouse handler running (either on console or via X), you can use links and clickable menus within your terminal.
w3m, the ncurses Web browser. It take the same colors as your X terminal
There are ways of interacting with ncurses in numerous languages other than C itself (including Python, Perl, and C++), so anything you learn in one language will transfer with reasonable ease to another. If you're interested in writing your own ncurses programs, there's an introduction here (technically obsolete, but still useful as a starting point), and a HOWTO.