Meanings of terminal codes \033[E and \033[07, which appear in printf() statements?

陌路散爱 提交于 2019-12-23 04:24:10

问题


In the C implementation for the Game of Life program, as shown here the codes I mentioned appear in the show() function. I can't find any information at all about what 033[E means and as for \033[07 this is usually a color code in linux bash terminal, where with \033[07m we begin the color coding and with \033[m we end the predefined color coding. However, according to this website it means "reverse". I'm not sure what that means.

I'm more interested though in \033[E code, for which I can find no information. From testing and debugging the program with gcc on Linux bash, I see that without this command, the output is not displayed as intended. If anyone can share knowledge on this, I would appreciate it. Thanks in advance.


回答1:


The sequence ESC [ E is an error – or possibly, a hypercorrect version – in that source. The code is ESC E, and it serves to move the cursor to the next line. The [ indicates it can take an optional numerical parameter (zero or more), and in this case there are none, so it can be omitted. (A numerical parameter would indicate how many lines to skip; 0 or 1 shows a regular newline, and higher values makes it skip lines.)

The definition is hard to find because it's more usual to just use \n – the regular newline code – to move the cursor to the start of the next line in a terminal program.

The sequence ESC [07m also contains a redundant code, ESC [7m is enough to put the terminal into Reverse mode. You are probably used to adding this to the start of a color sequence so you can set the foreground color of the text (numbers from 30..37) instead of background (40..47), and use spaces to draw a colored block.



来源:https://stackoverflow.com/questions/41485511/meanings-of-terminal-codes-033e-and-03307-which-appear-in-printf-statemen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!