Web server hosting - 712 Part VI . Programming in Linux Creating

712 Part VI . Programming in Linux Creating TUIs with Ncurses Screen manipulation libraries such as S-Lang and ncurses create more attractive programs, but, as you might expect, the trade-off for a nicer looking interface is more complicated code. Ncurses, which stands for new curses, is free re-implementation of the classic curses UNIX screen-handling library. The term curses derives from the phrase cursor optimization, which succinctly describes what the curses library does: computes the fastest way to redraw a text-mode screen and places the cursor in the proper location. Ncurses provides a simple, high-level interface for screen control and manipulation. It also contains powerful routines for handling keyboard and mouse input, creating and managing multiple windows, and using menus, forms, and panels. Ncurses works by generalizing the interface between an application program and the screen or terminal on which it is running. Given the literally hundreds of varieties of terminals, screens, and terminal emulation programs available, and the different features they possess (not to mention the different commands to use these features and capabilities), UNIX programmers quickly developed a way to abstract screen manipulation. Rather than write a lot of extra code to take into account the different terminal types, ncurses provides a uniform and generalized interface for the programmer. The ncurses API insulates the programmer from the underlying hardware. Ncurses gives to character-based applications many of the same features found in graphical X Window applications multiple windows, forms, menus, and panels. ncurses windows can be managed independently, may contain the same or different text, scroll or not scroll, be visible or hidden. Forms enable the programmer to create easy-to-use data entry and display windows, simplifying what is usually a difficult and application-specific coding task. Panels extend ncurses capability to deal with overlapping and stacked windows. Menus provide, well, menus, again with a simpler, generalized programming interface. To give you an idea of how ncurses works and what is involved in writing code to use it, Listing 27-3 shows the readkey.c program introduced in Listing 27-2 adapted to work with ncurses (now named nreadkey.c). Listing 27-3: Reading Input and Writing Output with Ncurses /* * readkey.c - reads characters from stdin */ #include #include int main(int argc, char *argv[]) { int c, i = 0; int maxx, maxy; int y, x;
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply