How to get the fancy text-graphic frames?

How to get the fancy text-graphic frames?

Post by Oliver Gebel » Sat, 30 Nov 2002 00:43:06



Hi,

in the old DOS time it was no problem to draw frames
by using the "ASCII" characters 128-255.
(btw. i am aware that ASCII is only 7bit ;-)

Recently i tried this on my Linux box, and i found
that i am using the ISO 8859-1 character set. So my
question is how can I use the same table like
DOS inside my c program?

(I do not understand if this has something to do
with the terminal settings. On my box i have
TERM=xterm).

TIA, Oliver
--
Wer Druckfehler findet, darf die behalten.

 
 
 

How to get the fancy text-graphic frames?

Post by Ralf Fasse » Sat, 30 Nov 2002 01:39:14



| Recently i tried this on my Linux box, and i found that i am using
| the ISO 8859-1 character set. So my question is how can I use the
| same table like DOS inside my c program?

Most probably on your DOS box you used Windows code page 850 (?),
which contained the box-frame-characters in character positions above
127.  ISO8859-1 contains various Umlauts and other symbols instead in
these positions, so there are no box-building characters in that
encoding.  Check your manpages for `code page' and/or `font encoding'.

Good luck...
R'

 
 
 

How to get the fancy text-graphic frames?

Post by Andrew Giert » Sat, 30 Nov 2002 08:11:19


 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/>

 
 
 

How to get the fancy text-graphic frames?

Post by Oliver Gebel » Sat, 30 Nov 2002 17:44:45



> 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,

OK, i did not want to use the curses library - so my prog's
would still run on windows (shame on me).

I was thinking of changeing the character set,
and i used to think this was the way curses does it.
Now i hear i have to change the terminal and use
escape sequences, so how would i do this?

TIA, Oliver

 
 
 

How to get the fancy text-graphic frames?

Post by Joerg Brueh » Sat, 30 Nov 2002 20:32:07


Hi Oliver!



> > 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,

> OK, i did not want to use the curses library - so my prog's
> would still run on windows (shame on me).

> I was thinking of changeing the character set,
> and i used to think this was the way curses does it.
> Now i hear i have to change the terminal and use
> escape sequences, so how would i do this?

AFAIR, this may be implemented by terminals (either hardware,
or emulators in software) as "alternate character set",
and the terminal can be switched into / out of that set.
The escape sequences to do that switching are called
"smacs" ("Set Mode Alternate Character Set") and "rmacs"
("Reset ...") in the "terminfo" stuff, see the "ACS..."
character names in Andrew's post. AIUI, in the ACS mode
you have no Umlauts or other ISO characters beyond ASCII.

I do not remember how you determine the character you need
to send (when in ACS mode) to get it translated to line-drawing
graphics, but there is a list somewhere. RTFineM "terminfo".
IMHO, most of this stuff is modeled after the old "VT 100"
terminals, so any description of these might also help.
As a start, try   http://www.cs.utk.edu/~shuford/terminal/dec.html

HTH,
Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
     (speaking only for himself)

 
 
 

How to get the fancy text-graphic frames?

Post by Andrew Giert » Sun, 01 Dec 2002 01:49:01


 Joerg> AFAIR, this may be implemented by terminals (either hardware,
 Joerg> or emulators in software) as "alternate character set", and
 Joerg> the terminal can be switched into / out of that set.  The
 Joerg> escape sequences to do that switching are called "smacs" ("Set
 Joerg> Mode Alternate Character Set") and "rmacs" ("Reset ...") in
 Joerg> the "terminfo" stuff, see the "ACS..."  character names in
 Joerg> Andrew's post. AIUI, in the ACS mode you have no Umlauts or
 Joerg> other ISO characters beyond ASCII.

 Joerg> I do not remember how you determine the character you need to
 Joerg> send (when in ACS mode) to get it translated to line-drawing
 Joerg> graphics, but there is a list somewhere.

the 'acsc' string capability ('ac' in termcap) contains pairs of
characters, where the first character in each pair is the character you
have to send to a vt100 to get the specific graphic, and the second is
the character you have to send for the type of terminal being described.
(Of course, for vt100-emulators like xterm, these are the same.)

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>

 
 
 

How to get the fancy text-graphic frames?

Post by Oliver Gebel » Sun, 01 Dec 2002 04:23:14



> the 'acsc' string capability ('ac' in termcap) contains pairs of
> characters, where the first character in each pair is the character you
> have to send to a vt100 to get the specific graphic, and the second is
> the character you have to send for the type of terminal being described.
> (Of course, for vt100-emulators like xterm, these are the same.)

Unfortunately i still don't get it. Therefore here's my testprog.
I tried TERM=xterm and TERM=vt100. And after a look at /etc/termcap
some ways to switch to the alternate characterset, which won't work.
(clearing the screen and setting the cursor is no problem however).

Any ideas what i am doing wrong here?

#include <stdio.h>
int main(void)
{
  char esc=27;

  printf("%c[2J",esc);         /* clear screen */
  printf("%c[%d;%dH",esc,5,5); /* set cursor to positon */

  printf("%c[12m",esc);        /* switch to alternate charset */
  printf("jjkkllmm");          /* try some... */
  printf("%c[10m",esc);        /* reset from alt. chars */
  printf("\n");

  return 0;

Quote:}

Thanx, Oliver
--
Wer Druckfehler findet, darf die behalten.
 
 
 

How to get the fancy text-graphic frames?

Post by Andrew Giert » Sun, 01 Dec 2002 06:54:27


 Oliver> Unfortunately i still don't get it. Therefore here's my testprog.
 Oliver> I tried TERM=xterm and TERM=vt100. And after a look at /etc/termcap
 Oliver> some ways to switch to the alternate characterset, which won't work.
 Oliver> (clearing the screen and setting the cursor is no problem however).

 Oliver> Any ideas what i am doing wrong here?

 Oliver> #include <stdio.h>
 Oliver> int main(void)
 Oliver> {
 Oliver>   char esc=27;

 Oliver>   printf("%c[2J",esc);         /* clear screen */
 Oliver>   printf("%c[%d;%dH",esc,5,5); /* set cursor to positon */

 Oliver>   printf("%c[12m",esc);        /* switch to alternate charset */

for a vt100 or xterm that needs to be "%c(0" to set the alternate charset
and "%c(B" to reset it to normal. You should, ideally, get these strings
from the termcap 'as' and 'ae' capabilities (smacs and rmacs in terminfo).
With that change, your program works as expected.

 Oliver>   printf("jjkkllmm");          /* try some... */
 Oliver>   printf("%c[10m",esc);        /* reset from alt. chars */
 Oliver>   printf("\n");

 Oliver>   return 0;
 Oliver> }

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>

 
 
 

How to get the fancy text-graphic frames?

Post by Oliver Gebel » Sun, 01 Dec 2002 19:46:18



> for a vt100 or xterm that needs to be "%c(0" to set the alternate charset
> and "%c(B" to reset it to normal. You should, ideally, get these strings
> from the termcap 'as' and 'ae' capabilities (smacs and rmacs in terminfo).
> With that change, your program works as expected.

I already tried this but didn't realize that i had to use \E(0 (zero)
and not \E(O (the uppercase character of o)!

Thanks for all the help!

Oliver
--
Wer Druckfehler findet, darf die behalten.

 
 
 

1. Glk: portable fancy text I/O lib (text adventures, etc)

Wow, that's about the most compressed subject line I've ever had to
write. Hopefully, if you're reading this, you're interested in what I'm
doing.

Glk is a cross-platform programming interface for information display and
user input. It is designed to be lightweight, portable, and adaptable,
rather than universal, detailed, and bloated. Glk does not try to do
everything; it tries to do common things well.

The origins of Glk are in the text-adventure community, and that influence
is still visible. Text input and output are still the main focus -- an API
which can conform to good UI convention on every platform (MacOS, X,
Windows, pen-based systems, or even terminal-window libraries such as
curses).

However, Glk is expandable, and functionality will continue to be added to
it. Image display is already in the API; future plans include sound and
networking capabilities.

Glk makes a good basis for any program which needs to be cross-platform,
whose interface needs are largely text, perhaps with graphical
illustration or enhancement. It's also good for prototypes, since it's
very quick to get a program running.

And, of course, I hope that Glk is useful as the I/O side of any new text
adventure development systems. (I've seen a couple being announced.) Most
text IF systems are innovations in world design, programming, and parsing.
The actual user input and output is an afterthought. I hold that these two
areas should be cleanly separated. Glk allows a system to concentrate on
internals, and get good I/O and portability for free.

Glk libraries -have been implemented- for MacOS, X, Win32, DOS, and the
Curses terminal-window library. All of these are freeware, and the
specification is available; implementations for new platforms are welcome.
(PalmOS would be particularly welcome, not to mention BeOS? ...GTK or KDE?
...an Emacs major mode?)

--Z

--

"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
borogoves..."

2. Opinion Poll? SUSE vs SLACKWARE vs REDHAT vs DEBIAN vs CALDERA

3. Getting Graphic Mode and Text Mode during Startup

4. X freezes after an undefined time

5. CDRECORD errors with "fancy formatted" text files

6. Modem on Compaq Armada & Turbo Linux

7. What Fancy graphics card should i get for xfree 3.3.1

8. slow text on my TNT card

9. Problem with boot in text mode using frame buffer

10. Getting/setting eth frame interface for raw socket

11. gdb: missing frames in frame stack or function name garbled

12. HELP WITH PRINTING OF GRAPHICS AND TEXT

13. Graphics Libs with Text, BGlib?