LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-13-2008, 03:31 AM   #1
john.daker
Member
 
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?

Thanks.

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
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

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

Last edited by keefaz; 11-13-2008 at 04:34 AM.
 
Old 11-13-2008, 05:26 AM   #3
john.daker
Member
 
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:
ESC[?1000hESC[?1049hESC[?1hESC=ESC[1;30rESC[?12;25hESC[?12lESC[?25hESC[27mESC[mESC[HESC[2JESC[?25lESC[2;1HESC[1mESC[3.................
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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