How to Run a Terminal Application in ASCII on Linux

(learn about this date format)

Recently, I’ve discovered that some of the programs that I’ve written and some of their dependencies make a bad assumption. They assume that the system uses UTF-8 by default. That assumption is especially bad because Windows uses UTF-16.

As part of the debugging process, I tried to run my software with the encoding set to plain-old ASCII. Doing that was harder than I expected. Here’s what I had to do to. These’s instructions are specific to Arch Linux. I don’t know how well they’ll work on other distros.

  1. Find out what name locale uses for ASCII. /usr/share/i18n/charmaps should contain a file for each character encoding that your system supports. On my system, the encoding wasn’t called “ASCII”. Instead it was called “ANSI_X3.4-1968”. IANA’s character set list might be helpful here. It has a list of aliases for “US-ASCII”.
  2. Generate a locale for that character set:

    1. Open /etc/locale.gen
    2. Add the following on a new line:

      language[_country].charset charset

      language[_country].charset” will be the name of the new locale. language and country should be a valid two letter language code and a valid two letter country code respectively. charset should be the name of the character set you found before. For mine, I did:

      en_US.ANSI_X3.4-1968 ANSI_X3.4-1968

      In that example, the locale is named “en_US.ANSI_X3.4-1968”.

    3. Run sudo locale-gen
  3. Make sure that Konsole is installed
  4. Run:

    LANG='locale' konsole -p DefaultEncoding='charset'.

    On my system, the final command was:

    LANG='en_US.ANSI_X3.4-1968' konsole -p DefaultEncoding='ANSI_X3.4-1968'