ANSI Control Handling in Terminals & Telnet Clients


I’m in the fairly early stages of developing a Node.js based BBS (yes, really!), and in doing so need to recognize and understand the differences in which various terminals and Telnet clients such as SyncTERM handle ANSI control/escape sequences.

As of now, this entry is mostly a placeholder, but I will update it as these are found.

Clients & Terminals

Here are some of the terminals in which I’d like my system to work with:


Clearing the Screen

Control: ESC[2J

Some client/terminals seem to both clear and go home (position 1,1) while others simply clear:

  • SyncTERM: Clear+Home
  • mTCP telnet: Clear+Home
  • telnet under iTerm2, rxvt, PuTTY: Clear only

Workaround: ESC[2J + ESC[H

Bonus: ESC[0m + ESC[2J + ESC[H for DOS style “cls”.

Thanks to Michael Griffin for pointing out my typos!

Terminal Size Negotiation

Most terminals tested seem to support one or more ways to negotiate terminal size: NAWS, ENV, and/or nonstandard ANSI device status report of ESC[255n.

Netrunner currently returns Telnet “wont”‘s in response to NAWS and ENV and gives a response of 1x1 for ESC[255n – not particularly useful. In this case, I’m defaulting to 80x24.

…to be continued.