What is Ansi Escape Code?

1

For manipulation of the linux terminal (other OS console as well) , it is using a string started with a value in hexadecimal 0x1B known as ANSI Escape Code .

As for example printf("\x1B[32mMy Text\n") .

How does ASNI Escape Code work?

What is it Exactly?

    
asked by anonymous 14.04.2017 / 05:55

1 answer

0

ANSI Escape Code

There is a standard made based on an ANSI to control the outputs made in a text terminal.

The manipulation of these outputs is done by commands called ANSI Escape Codes , which are enabled by the 27 or 1B value character in hexadecimal ( Esc button) followed by [ (opens bracket), after that, a value and a letter are passed to represent your action.

Examples

To position the cursor in a certain position on the screen, use the letters H or f , passing along the line and the column to the cursor. p>

printf("\x1B[%d;%dH",6, 5);
printf("\x1B[%d;%df",6, 5);

To clear the screen, use 2 followed by the J character.

printf("\x1B[2J");

To change the color of the text to be written, use the color value followed by m .

printf("\x1B[31mRed"); // Escreve em vermelho
printf("\x1B[01;32mBoldGreen"); // Escreve em verde e negrito
printf("\x1B[00mTexto Normal"); // Retira estilo
    
14.04.2017 / 05:55