16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C Libraries<br />

What is curses?<br />

- library of routines for screen management<br />

- located in "/usr/lib/libcurses.a"<br />

- link editor "cc file.c -lcurses -o file"<br />

/* example program: */<br />

#include <br />

main()<br />

{<br />

initscr(); /* initialise terminal settings */<br />

move(LINES/2 - 1, COLS/2 - 4);<br />

addstr("Bulls");<br />

refresh(); /* send output to terminal screen */<br />

addstr("Eye");<br />

refresh();<br />

endwin(); /* restore all terminal settings */<br />

}<br />

What is terminfo ?<br />

- routines <strong>with</strong>in curses library, e. g. to program function keys<br />

- database of terminal capabilities<br />

# example - clear screen script<br />

tput clear<br />

tput cup 11 36<br />

echo "BullsEye"<br />

Screen management programs using curses obtain info on terminals at run time from terminfo database.<br />

TERM;vt100<br />

export TERM<br />

tput init<br />

/usr/lib/termintolv/vtl00<br />

Components:<br />

captoinfo(lM)<br />

curses(3x)<br />

infocmp(1m)<br />

tabs(1)<br />

terminfo(4)<br />

tic(1M)<br />

tput(1)<br />

tool to convert termcap to terminfo<br />

tool for printing compiled terminal info<br />

tool for setting non-standard tab stops<br />

tool to compile terminal info<br />

tool for outputting terminal capability<br />

Output:<br />

int addch(chtype ch)<br />

int addstr(char *str)<br />

int printw(fmt)<br />

int move(int y, x)<br />

int clear()<br />

write a character at a time<br />

write a string (calls addch)<br />

similar to printf<br />

move cursor to row y, column x<br />

clear screen<br />

Input:<br />

int getch()<br />

int getstr(char *str)<br />

int scanw(fmt)<br />

read character from terminal<br />

read string until <br />

similar to scan<br />

Output Attributes:<br />

int attron(chtype attrs)<br />

turns on attribute in addition<br />

76

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!