Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-13-2008, 03:31 AM   #1
Registered: Jul 2008
Posts: 33

Rep: Reputation: 15
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 ?

Last edited by john.daker; 11-13-2008 at 03:50 AM.
Old 11-13-2008, 04:29 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,390

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
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

Last edited by keefaz; 11-13-2008 at 04:34 AM.
Old 11-13-2008, 05:26 AM   #3
Registered: Jul 2008
Posts: 33

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

Or vim's escape codes:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Less outputs ANSI escape sequences sprocketboy Mandriva 2 08-05-2009 08:22 PM
Sending escape codes through CUPS Tracker77 Linux - Desktop 1 02-10-2008 11:45 AM
LXer: CLI Magic: Use ANSI escape sequences to display a clock in your terminal LXer Syndicated Linux News 0 01-22-2008 10:20 PM
Escape Codes for Console Color trainpic Linux - General 1 03-13-2006 07:45 PM
Using escape codes to print barcodes c2tidis Linux - Software 0 09-29-2005 11:44 AM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration