I'm working on code for a serial terminal and I'm implementing the ANSI escape codes for moving around the cursor, clearing the screen, etc, and I am curious how to know which to use since there doesn't seem to be a clear stopping point for the codes.

I'm using https://www2.ccs.neu.edu/research/gpc/VonaUtils/vona/terminal/vtansi.htm as a reference

For example, if I receive the code, I start reading characters, but if I get the value 75='K', that could be ESC[K = Erase End of Line, or a 75 as a count for a code like ESC[{COUNT=75}C for move cursor 75 columns right. What if I was receiving the code to erase the line followed by a printed A? As far as I know the code for that and the cursor 75 cols right would receive the exact same sequence.

I'm probably missing something obvious but could someone please give me a hint? Thank you

1 Answer 1


For "ANSI" (actually ECMA-48), the characters which begin the control sequence, determine the set of final characters. It's documented near the beginning of ECMA-48 (section 5.4 is particularly pertinent, though you may need an ASCII chart to understand its terminology).

The parameter 75 in a control sequence would be the characters 75, rather than a character whose value happened to be 75. There's no confusion between the two.

The link you cited was for a document written by someone who was unfamiliar with the standard. It's mentioned in the ncurses FAQ How do I get color with VT100?.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .