tags:

views:

42

answers:

3

Hi

I started to write a terminal text editor, something like the first text editors in unix like vi. The only purpose is have a good and fun time, but I want to let in show text in color, so I could use it for edit source code. How could achieve this? There some POSIX special API for this, or I have to used ncurses (i don't want use it)?

Any advice? maybe some textbooks on the unix api?

Thanks in advance

+1  A: 

Use ANSI escape sequences. This article goes into some detail about them. You can use them with printf as well.

Vivin Paliath
+1  A: 

You probably want ANSI color codes. Most *nix terminals support them.

Nathon
+1  A: 

This is a little C program that illustrates how you could use color codes:

#include <stdio.h>

#define KNRM  "\x1B[0m"
#define KRED  "\x1B[31m"
#define KGRN  "\x1B[32m"
#define KYEL  "\x1B[33m"
#define KBLU  "\x1B[34m"
#define KMAG  "\x1B[35m"
#define KCYN  "\x1B[36m"
#define KWHT  "\x1B[37m"

int main()
{
    printf("%sred\n", KRED);
    printf("%sgreen\n", KGRN);
    printf("%syellow\n", KYEL);
    printf("%sblue\n", KBLU);
    printf("%smagenta\n", KMAG);
    printf("%scyan\n", KCYN);
    printf("%swhite\n", KWHT);
    printf("%snormal\n", KNRM);

    return 0;
}
karlphillip