Strovent SystemsSign in
Reference

Boxes show as q, x and lqqqk in a terminal

Why borders appear as letters like lqqqk and x in SSH and Mosh sessions, how the VT100 line-drawing character set works, and how TERM and the locale affect it.

A menu or dialog drawn with lqqqk across the top, x down the sides and mqqqj at the bottom is a box whose corners and lines were sent as letters. The terminal was meant to swap those letters for line-drawing symbols, and it did not.

How line drawing works

The VT100 had a second character set. When a program switched to it, the letters at ASCII codes 0x60 to 0x7E were drawn as graphics, and a switch back restored normal letters. The ncurses documentation lists the mapping for these letters:

  • l: upper left corner
  • k: upper right corner
  • m: lower left corner
  • j: lower right corner
  • q: horizontal line
  • x: vertical line
  • t: tee pointing right
  • u: tee pointing left
  • w: tee pointing down
  • v: tee pointing up
  • n: crossover
  • a: checkerboard

The switch is made with escape sequences. The xterm control sequences reference lists ESC ( 0 to select the DEC Special Character and Line Drawing set as G0 and ESC ) 0 for G1, and the controls Shift Out (Ctrl+N) and Shift In (Ctrl+O) to switch between G1 and G0. A program that uses ncurses gets the sequences from the terminfo entry for your TERM: the smacs and rmacs capabilities start and end the alternate set, and acsc gives the characters.

Why you see letters

  • The terminal did not switch. Some clients, or some modes, ignore the sequences, so the letters stay letters.
  • The host's terminal type does not match the client. The ncurses manual says that, in a UTF-8 locale, the Linux console and GNU screen ignore the VT100 line-drawing sequences, so ncurses checks TERM for names like linux and screen and prints Unicode box characters instead. A wrong TERM pushes the program onto the wrong path. See TERM and terminfo.
  • The set was never switched back. Text that follows the switch is drawn as graphics, not as letters. If a program ended without switching back, or you displayed a binary file, the terminal stays in the wrong set. Type reset. Ctrl+O (Shift In) selects the G0 set again, which helps only when the stuck set is G1.
  • The program is not using the terminal's set at all. Check the program's manual for an ASCII-only or plain-characters option.

What to try

  1. Check echo $TERM and locale. Use a type the host knows, such as xterm-256color, and a UTF-8 locale.
  2. For ncurses programs on a terminal where the sequences are ignored, set NCURSES_NO_UTF8_ACS=1 before starting the program. The ncurses manual says ncurses then outputs the Unicode code points for the line-drawing characters instead.
  3. Run reset if everything after the box is odd.

The VT emulator in this app handles ESC ( 0 and ESC ) 0 with Shift Out and Shift In, and draws the VT100 line-drawing characters when a host selects them.

Sources

Spotted a mistake? Email [email protected].