0

I'm trying to write a simple shell. I just want to change the color of the text the user types in which in the future will be used for stuff like syntax highlighting. Can I use the standard library for this or do I need to use something like ncurses. Its pretty easy to change the output color. Is there a similar solution?

Thanks in advance.

rushdabs
  • 5
  • 3

1 Answers1

1

Have a look at here and here.

I think this Sample Code should help you,

#include<stdio.h>

int main()
{
    int num;
    printf("%s", "\033[92mEnter Number : \033[34m");
    scanf("%d", &num);
    printf("%s", "\033[0m");
    return 0;
}

Above coe will print Enter number : in green and typing number in blue,

Note : Make sure that your terminal supports ANSI escape color code see here for windows 10.

Dharman
  • 30,962
  • 25
  • 85
  • 135
srilakshmikanthanp
  • 2,231
  • 1
  • 8
  • 25