To see if
the additional code is worth it, compile nreadkey.c using the following command:
$ gcc nreadkey.c -lncurses -o nreadkey
To run the program, type ./nreadkey. Figure 28-5 shows the result after typing the same text as
typed for readkey.c earlier.
FIGURE 28-5
An ncurses-based TUI
768
Programming in Linux Part VI
Ncurses-based programs can also read input piped from stdin. Figure 28-6 shows the results of the
command cat /etc/passwd | ./nreadkey.
FIGURE 28-6
Displaying input piped to an ncurses-based program
As you saw with the command pipeline used with the readkey.c program (shown in Listing 28-2),
the input is truncated at the end of the first line because each line in /etc/passwd ends with the
newline character, and readkey.c uses the newline character to signal the end of input.
For more information about ncurses, including download information, visit the ncurses
Web page at http://dickey.his.com/ncurses/ncurses.html.
Creating Text-Mode User Interfaces with S-Lang
S-Lang, created by John Davis, is an alternative to ncurses for creating TUIs. In addition to providing
screen manipulation and cursor control routines, S-Lang also consists of an embeddable S-Lang
interpreter, a large library of built-in (intrinsic) routines that simplify certain parts of programming,
and a variety of predefined data types and data structures.
Pages:
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398