Listing 28-4 shows the same program as
Listing 28-3, with appropriate updates to reflect use of S-Lang instead of ncurses.
LISTING 28-4
Reading Input and Writing Output with S-Lang
/*
* sreadkey.c - simple S-Lang-based UI
*/
#include
#include
#include
continued
NOTE
769
Programming Environments and Interfaces 28
LISTING 28-3 (continued)
int main(int argc, char *argv[])
{
int i = 0;
unsigned int ch;
/* start s-lang */
SLtt_get_terminfo();
SLang_init_tty(-1, 0, 1);
SLsmg_init_smg();
/* draw a purty border */
SLsmg_draw_box(0, 0, 24, 80);
SLsmg_gotorc(1, 1);
SLsmg_write_nchars("INPUT: ", 7);
SLsmg_refresh();
/* read characters until newline read */
while(1) {
++i;
ch = SLang_getkey();
if (ch == 13)
break;
if (SLsmg_get_column() == 79)
SLsmg_gotorc(2, 1);
SLsmg_write_char(ch);
SLsmg_refresh();
}
/* print the character count */
SLsmg_gotorc(22, 1);
SLsmg_write_nchars("characters read: ", 17);
SLsmg_printf("%d", i);
SLsmg_refresh();
/* time to look at the screen */
sleep(3);
/* shutdown s-lang */
SLsmg_reset_smg();
SLang_reset_tty();
return 0;
}
770
Programming in Linux Part VI
To compile this program use the following command:
$ gcc sreadkey.c -lslang -o sreadkey
You will need the slang, slang-devel, ncurses, and ncurses-devel packages to compile and run this
program.
Pages:
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399