LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to handle ansi escape codes in C? (http://www.linuxquestions.org/questions/programming-9/how-to-handle-ansi-escape-codes-in-c-683080/)

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?

Thanks.

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:
Code:

#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;
}

[edit]
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:
ESC[?1000hESC[?1049hESC[?1hESC=ESC[1;30rESC[?12;25hESC[?12lESC[?25hESC[27mESC[mESC[HESC[2JESC[?25lESC[2;1HESC[1mESC[3.................


All times are GMT -5. The time now is 02:41 PM.