콘솔창에 출력되는 글자를 알록달록 이쁘게 만들고 싶은데 방법이 없을까?

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f0102e13-baa9-46a9-a295-840934734309/Untitled.png

Shell을 자주 사용했거나 Makefile좀 꾸며본 사람이라면 C언어에서도 무리없이 할 수 있을 것이다.

바로 ANSI Color를 사용하면 간단하게 표현할 수 있다!

printf에 넘길 문자열에 Escape code와 color code를 전달하면 끝!

이제 원하는 색을 표현하고 싶은 곳 앞에 원하는 색상을 표기해주면 된다.

printf(“\\033[0;31m”); // Set the text to the color red
printf(“Hello\\n”); // Display Hello in red
printf(“\\033[0m”); // Resets the text to default color

물론 위의 코드를 합쳐서 쓸 수도 있다.

printf("\\033[0;31mHello\\n\\033[0m");

어떤 색상이 있는지 아래를 참고해보자!

Black  : \\033[0;30m
Red    : \\033[0;31m
Green  : \\033[0;32m
Yellow : \\033[0;33m
Blue   : \\033[0;34m
Purple : \\033[0;35m
Cyan   : \\033[0;36m
White  : \\033[0;37m

👉 조금 더 많은 색을 쓰고싶다면..?