Thread: Extended ASCII/ANSI in Linux Shell

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    8

    Extended ASCII/ANSI in Linux Shell

    I want to write a basic "windowed" text-based program run from the command line. What is required to display extended ASCII or ANSI in the Linux bash shell with C or C++? Does a UTF-8 mode or special text mode need to be enabled or will characters 128-255 be displayed properly automatically?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, it should work just fine without any extensions. Be aware, however, that there are several different definitions of which character is which at the 128..255 set, so things may look different on for example a Windows machine, a DOS machine, a Mac or a Linux machine.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by JupiterV2 View Post
    I want to write a basic "windowed" text-based program run from the command line. What is required to display extended ASCII or ANSI in the Linux bash shell with C or C++? Does a UTF-8 mode or special text mode need to be enabled or will characters 128-255 be displayed properly automatically?
    What is "extended ASCII?" I know of at least 208 variants on the ASCII character set and that's just in MY line of work. ASCII only covers the codes 0-127 as it is a 7-bit code. Anything higher than that is not ASCII, period. You are probably referring to IBM PC-8, which is a historical character set that has been used on PCs for many years.

    Now, it just so happens that the bottom 7 bits of IBM PC-8 are identical to ASCII. But that DOESN'T MEAN IT'S ASCII.

    To print a given character from a given character set, you must first program the terminal to use that character set. You should not make assumptions about the default character set.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8
    Thanks, this is exactly what I want to know. The PC-8 set is indeed what I was referring too. How can I specify that this is the code set I want to use, or for portability reasons, how can I take the guess-work out of OS-specific character-sets in order for my program to display characters correctly irregardless of its environment?

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If you are trying to draw solid boxes, then ncurses is the way to go.

    http://www.linux.com/base/ldp/howto/...ramming-HOWTO/

    http://www.linux.com/base/ldp/howto/...c.html#ACSVARS

    gg

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by JupiterV2 View Post
    Thanks, this is exactly what I want to know. The PC-8 set is indeed what I was referring too. How can I specify that this is the code set I want to use, or for portability reasons, how can I take the guess-work out of OS-specific character-sets in order for my program to display characters correctly irregardless of its environment?
    I don't think there is a solution regardless of environment because a given environment isn't guaranteed to even have PC-8 available.

    At any rate, the method by which you select the character set is also going to be OS specific. As codeplug said, ncurses can take care of a lot of the details but is UNIX-specific (so far as I know, maybe there is a Windows port?)

    The other option is to use an actual font of your own. Then you can guarantee that the necessary glyphs are available.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  2. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  3. Linux Shell and mp3
    By afreedboy in forum Linux Programming
    Replies: 2
    Last Post: 06-24-2004, 12:08 PM
  4. 3 linux shell environments
    By SpEkTrE in forum Linux Programming
    Replies: 3
    Last Post: 10-21-2003, 02:26 PM