I found this commit from facebook infer, and I have no idea what \027[0K
and \027[%iA
means.
What does these special string mean? And (I think) if there are more strings like this, where can I find the full documentation about this?

- 51,086
- 7
- 70
- 105

- 127
- 6
-
3https://en.wikipedia.org/wiki/ANSI_escape_code – KamilCuk Jul 06 '20 at 10:50
-
1What makes you think this related to `bash`? The code you linked to is written in OCaml. – chepner Jul 06 '20 at 12:36
-
@chepner I know it is written in OCaml, but the purpose of that code snippet is to draw a task bar in the shell. – sangwoo-joh Jul 07 '20 at 01:35
-
@KamilCuk Thank you, I will read that page. I think the code is related to ANSI Terminal, so I think the page name "ANSI escape code" is what I need! – sangwoo-joh Jul 07 '20 at 01:36
-
1@sangwoo-joh No, the purpose is to display something in the terminal. Terminal != shell. – chepner Jul 07 '20 at 12:18
-
@chepner Oh, thanks for your correction. I'm afraid I'm not aware of the difference between the terminal and shell. Is shell an element of terminal? – sangwoo-joh Jul 08 '20 at 05:18
-
1The terminal is an interface that provides input (via the keyboard) and output (to the screen). You can use it to interact with any program. The shell is command interpreter that makes it easy to run other commands, and it is just one program that can run in a terminal. – chepner Jul 08 '20 at 12:31
2 Answers
Those are escape sequences to tell your terminal what to do.
For example, the sequence of characters represented by \027[0K
(where \027
is ASCII decimal value for Esc
character) tells the terminal to "clear line from cursor to the end."
One helpful document/guide on this subject can be found at https://shiroyasha.svbtle.com/escape-sequences-a-quick-guide-1

- 604
- 4
- 7
The facebook code is copied from another source here, which uses hard-coded formatters imitating termcap (this page gives some background). The original has comments indicating where its information came from.
The formatter uses "%i" for integers. That's a repeat-count for the cursor movement "cursor-up" \033[A
In most languages, \033
(octal) is used for the ASCII escape character. But this source (according to the github analysis) is written in OCaml, and is using the decimal value for the ASCII escape character. According to the OCaml syntax, you could use an octal value like this: \o033
Once you see that the formatting parts (how the escape character is represented, the use of %i
to format a number), the rest of this is documented in several places.
- The relevant standard is ECMA-48
- the termcap (or analogous terminfo) information is in the terminal database.

- 51,086
- 7
- 70
- 105