-   Programming (
-   -   How to handle ansi escape codes in C? (

john.daker 11-13-2008 03:31 AM

How to handle ansi escape codes in C?
I'm writing terminal program in C with ncurses, and I have no idea how to handle ansi escape codes like "ESC[;4;5m",does ncurses provide some routine to handle this, or is there any lib can help?


And is there any stuff explains ansi escape codes ?

keefaz 11-13-2008 04:29 AM

man ascii would be a start

You could define some color escape strings like:

#include <stdio.h>

#define COLOR_RED "\033[;1;31m"
#define COLOR_END "\033[0m"

int main() {
    printf("%sHello World%s\n", COLOR_RED, COLOR_END);
    return 0;

Wait, curses has already colors macro defined, try:
man curs_color

john.daker 11-13-2008 05:26 AM

But how to handle it?
For example, I read a string like "\033[;1;31mHello World\033[0m"

Or vim's escape codes:

All times are GMT -5. The time now is 04:45 AM.