Oliver> Hi,
Oliver> in the old DOS time it was no problem to draw frames by using
Oliver> the "ASCII" characters 128-255. (btw. i am aware that ASCII
Oliver> is only 7bit ;-)
Oliver> Recently i tried this on my Linux box, and i found that i am
Oliver> using the ISO 8859-1 character set. So my question is how can
Oliver> I use the same table like DOS inside my c program?
Oliver> (I do not understand if this has something to do with the
Oliver> terminal settings. On my box i have TERM=xterm).
It does indeed depend on the terminal settings. Most terminal descriptions
contain a table of linedraw characters and the necessary escape sequences
needed to tell the terminal to use them.
The simplest way to do this, as usual, is to use the curses library,
which allows you to write full-screen character-mode programs which
take advantage of most terminal features and which work on almost any
terminal type for which a working description exists. A simple example,
which should use line-drawing characters if available but fall back to
using '+', '-' and '|' if not:
#include <ncurses.h>
int main(void)
{
WINDOW *win;
initscr(); /* curses initialisation */
cbreak();
noecho();
curs_set(0); /* turn cursor off if possible */
clear();
leaveok(stdscr, TRUE);
/* draw a "window" pattern two-thirds of the way down the screen */
move((2*LINES/3)-2, COLS/2-2);
addch(ACS_ULCORNER);
addch(ACS_HLINE);
addch(ACS_TTEE);
addch(ACS_HLINE);
addch(ACS_URCORNER);
move((2*LINES/3)-1, COLS/2-2);
addch(ACS_VLINE);
addch(' ');
addch(ACS_VLINE);
addch(' ');
addch(ACS_VLINE);
move((2*LINES/3), COLS/2-2);
addch(ACS_LTEE);
addch(ACS_HLINE);
addch(ACS_PLUS);
addch(ACS_HLINE);
addch(ACS_RTEE);
move((2*LINES/3)+1, COLS/2-2);
addch(ACS_VLINE);
addch(' ');
addch(ACS_VLINE);
addch(' ');
addch(ACS_VLINE);
move((2*LINES/3)+2, COLS/2-2);
addch(ACS_LLCORNER);
addch(ACS_HLINE);
addch(ACS_BTEE);
addch(ACS_HLINE);
addch(ACS_LRCORNER);
/* update the virtual screen (no actual output yet) */
wnoutrefresh(stdscr);
/* create a new window one-third of the way down the screen,
* draw a border box in it (goes _inside_ the window),
* and display a message
*/
win = newwin(5, 24, (LINES/3)-2, (COLS-24)/2);
box(win,0,0);
mvwaddstr(win, 2, 6, "Hello World!");
leaveok(win, TRUE);
/* update the new window to the virtual screen */
wnoutrefresh(win);
/* finally, actually display everything */
doupdate();
/* wait for a keystroke */
getch();
/* restore terminal modes */
endwin();
return 0;
Quote:}
--
Andrew.
comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>