简体   繁体   中英

Space characters inside the ESC[ (0x1b/0x5b) sequence invalidate the sequence?

I can not find information about what should be done to spaces within ESC sequence. Example: position cursor

ESC[10;20H

is a valid ESC sequence, but is the one including spaces like

ESC[ 10; 20H

valid too? The point is that while ESC character is a control character with code 0x1b, text following it is human and machine readable text, and in general spaces should not harm the meaning of ESC sequence, thus I would just remove all the spaces found within ESC sequence.

Lots of article on the internet talking what ESC sequence is and what they may consist of (however there're only just few good and really informative ones), but none of them clarify this matter.

I found this one , and it says

Since ASCII control functions do not follow a structured syntax, the notation used to describe function sequences and parameters is important to avoid confusion. Escape sequences are shown with a space between each character to make them easier to read. These spaces are not part of the Escape sequence.

While it says that space char separates characters for readability, they do not say if keeping space invalidates the ESC sequence.

Is there any related RFC for it? I hope it unambiguously defines this case.

Update: thanks Thomas to pointing to space char being one of the ESC sequence operators. So now it is clear that [ should follow ESC character, and space is not allowed between them.

But what is about following arguments? As in the example above, spaces in row and column coordinates ESC[ SP 10; SP 20H makes sequence invalid and I must stop processing it starting displaying space character instead?

Update1: I did small test using Windows telnet application. Logged into the remote server, and that server responds with ESC sequence. The result is:

ESC[2;5H positions properly row 2 column 5

ESC[ 2; 5H ESC[ 2; 5H displays "2; 5H" in current cursor position

ESC[2 ; 5H ESC[2 ; 5H displays "; 5H" in current cursor position

So basing on the empirical findings I suspect spaces are NOT allowed, and space char invalidates/cancels the sequence.

ECMA-48 's the place to look (if you want an RFC). Look for mention of 02/00 (the way it represents the hexadecimal 0x20 for space).

For what it's worth, there are DEC control sequences (VT220 and up) with an embedded space, eg, the ones marked with SP :

Controls beginning with ESC

This excludes controls where ESC  is part of a 7-bit equivalent to 8-bit
C1 controls, ordered by the final character(s).

ESC SP F  7-bit controls (S7C1T), VT220.

ESC SP G  8-bit controls (S8C1T), VT220.

ESC SP L  Set ANSI conformance level 1 (dpANS X3.134.1).

ESC SP M  Set ANSI conformance level 2 (dpANS X3.134.1).

ESC SP N  Set ANSI conformance level 3 (dpANS X3.134.1).

In your examples, the whitespace is just for readability, and non-printing characters such as ASCII escape (decimal 27, hexadecimal 01xb) are shown by a name such as ESC .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM