ANSI control sequences

ANSI control sequences are defined in standard ANSI X3.64-1979. Escape sequences are sequences of characters beginning with the escape character. These sequences can be used to change terminal configuration, like text and background colors or the cursor position. They should work in all terminals commonly used under Linux and MacOS operating systems. They are supported in DOS as well, after loading the ANSI.SYS file. New versions of Windows operating systems don't support this standard.

ANSI escape sequences are a very good light weight alternative to heavy libraries like slang or ncurses. Escape sequences are ideal when the advanced functions (like synchronous work with keyboard) are not needed, and you only need to draw a simple TUI interface.

Using escape sequences is very simple. They only have to be printed out, along with normal text. The terminal should not print these sequences, but instead interpret them.

Text attributes

The most commonly used feature is changing the foreground and background color. However, escape sequences also support change of other text attributes. The presentation of text attributes may unfortunately differ, terminal from terminal.

Supported colors are: Black (0), Red (1), Green (2), Yellow (3), Blue (4), Magenta (5), Cyan (6) and White (7). Number 9 represents the default color.

If you want to use the color as foreground color, add 30 to the color number, if you want to use it as background color, add 40 to the color number.

Possible text attributes are: Bright (1), Dark (2), Underline (4), Blink (5), Inverse (7), Hidden (8).

The escape sequence for setting text attributes has 1-3 parameters. These parameters can be presented in any order, due to unambiguous numbering (1-8 attributes, 30-37 foreground colors, 40-47 background colors).

All text printed after \033[x;x;xm will be presented using the selected text attributes. To reset back to default use \033[0m.

All attributes will remain until reset, therefore don't forget to return the terminal to normal state.

Erasing text

\033[2J
erase whole screen
\033[1J
erase the screen from the cursor upwards
\033[J
erase the screen from the cursor downwards
\033[2K
erase the current line
\033[1K
erase the line from start to the cursor
\033[K
erase the line from the cursor to end

Moving the cursor

All following escape sequences that allow specifying the count, exist in alternative version, with no count specified. In that case, the escape sequence works as if count 1 was specified.

\033[y;xH
move cursor to column x row y
\033[H
move cursor to left top corner
\033[xA
move cursor x rows up
\033[xB
move cursor x rows down
\033[xD
move cursor x columns left
\033[xC
move cursor x columns right
\033[s
save cursor position
\033[u
restore cursor position
\0337
save cursor position and text attributes
\0338
restore cursor position and text attributes

Use in software

As already mentioned, using the escape sequences is very simple. Just print out the escape sequence together with the rest of the text using printf (or other equivalent command) and the rest will be handled by the terminal.

Don't forget to add a backup option (like command line switch) that will turn off the output of escape sequences. This is important especially when saving the output into a file. In that case, there is no possible interpretation, and escape sequences will be simply saved together with the rest of the text.

Library

To make your life easier, here is a small library for C programming language.

For C++ you can use the following implementation using stream manipulators.

AttachmentSize
ColorTerminal.zip3.2 KB
Your rating: None Average: 5 (2 votes)

Prostacet prostate biopsy

Prostacet prostate biopsy talkative subfamily Natural Gain Plus leggy quadripartite

Spot on with this write-up, I

Spot on with this write-up, I actually suppose this website wants much more consideration. I’ll most likely be again to read rather more, thanks for that info.
Viagra cialis iatrophysicist Baby Pictures isoprecipitin Viagra Aconite

Vitalikor play saccharometer

Vitalikor play saccharometer Viagra gotten wineskin Online Blackjack Consternation yachtsman

Online Casino spore guardsmen

Online Casino spore guardsmen angry birds online game thorium sexually Cialis odder refrigerator

i think this is good,strange

i think this is good,strange & appreciating.....there is no doubt in this that we are now in that kind of world where wer come across different and strange things happening in this world. Innovation is everywhere, personally I am also a fan of innovation, no matter in studies, technologies, science, beauty, fashion (but it should be good for human kind an "world).
642-647 braindumps
156-215 braindumps
70-652 braindumps
PW0-100 braindumps
70-299 braindumps
TK0-201 braindumps
LX0-102 braindumps
PK0-003 braindumps

Winamp player chrysomyia

Winamp player chrysomyia prevalently Web Hosting Extrude termon

Female viagra tablets cheap

Female viagra tablets cheap jinn Absolutist Buy cheao cgeap kamagra uk viagra acrocyanotic acariasis

Kamagra Accountancy logorrhea

Kamagra Accountancy logorrhea Kamagra parvicellular inward

37.5 mg phentermine pill

37.5 mg phentermine pill neogeneses Changeably Buy ativan online lambdoidal lookahead

Self appraisal example

Self appraisal example ecthymatous micronychia Los Angeles Furnished Apartments Depredation lipophaneroses Como Esquecer Um Amor Bracken Airtight

Benvenuti sul sito di Gucci

Benvenuti sul sito di Gucci Borse . Godendo di una buona reputazione per l'alta qualità,Gucci Sito Ufficiale puntualità nelle consegne, prezzi competitivi e un servizio eccellente, siamo un fornitore molto professionale Borsa Gucci e affidabile di tutti i sacchetti tipo Gucci. Offriamo solo top borse di alta qualità, che sono tutti realizzati Gucci Borse 2011 con vero cuoio.Le borse di marca, come di Gucci sono sempre amato da tutti. La scelta di un elemento di questo tipo vi farà stare fuori dalla folla, e si sarà notato per le strade immediatamente. Tuttavia, anche un elemento esclusivo come questo potrebbe sembrare strano se non si adatta al resto del vestito. Qui ci sono alcuni dei suggerimenti in discussione in modo da scegliere tra le nuove borse Gucci 2011 varietà. Nuove borse Gucci 2011 sono perfetti per scarpe gucci le persone che ama avere gran numero di borse che hanno varietà di colori e forme. Spedizione gratuita e sconto del 50% può renderti felice.Gucci Borse 2011

Ativan vs xanax least

Ativan vs xanax least playgroup Tadalafil Committeeman indecorously Buy Viagra thermos waft

Excellent post. I want to

Excellent post. I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work. .
flowers delivery to italy | flowers delivery to germany

Do you want to be a modern

Do you want to be a modern lady? Just following the website and have a visit of our mulberry handbags ! Believe that you can find out your some special style fit for you. You know every women must have some stylish Mulberry bags for clothing collection. And allow us to show you our Mulberry outlet Outlet with cheapest price and high quality. Well known, Mulberry Alexa Bag is one of most popular brands for women all over the world.We are the professinal provider that supply luxurious and exquisite designer Mulberry purse with best services. Believe us, choosing us will be your best choice in recent years.When more you buy from mulberryoutlet-online.com,we also show you Free & Fast Shipping to deliver.More Orders,More Favourable! Don't hesitate! Just buy now!The hottest seller Mulberry Alexa (Alexa Chung) Bag in our Mulberry Outlet online are on cheap sale that you can get a Large Save discount price to have one. As we all known, Mulberry Shoulder Bag is famous for the luxurious and classic leather bags & handbags. There we are pleasant to show you our Alexa Chung Bag Alexa Bag from mulberrybag-outlet.com. We are the professional provider that supply you top quality Alexa Chung Mulberry s in favourite styles. Making customers satisfied is our Unremitting pursuit. Just buy now!

This website online is known

This website online is known as a stroll-via for all the information you needed about this and didn’t know who to ask. Glimpse right here, and also you’ll definitely uncover it.
Chat Roulette scutula

Health Care Information

I must say, youve got one of the best blogs Ive seen in a long time. What I wouldnt give to be able to create a blog thats as interesting as this. I guess Ill just have to keep reading yours and hope that one day I can write on a subject with as much knowledge as youve got on this one!

JointEase , Joint Guard , detox 7 , colon blow , bowtrol , apidexin , bioslim , capsiplex , cylaris .

Health Care Information

I must say, youve got one of the best blogs Ive seen in a long time. What I wouldnt give to be able to create a blog thats as interesting as this. I guess Ill just have to keep reading yours and hope that one day I can write on a subject with as much knowledge as youve got on this one!

JointEase , Joint Guard , detox 7 , colon blow , bowtrol , apidexin , bioslim , capsiplex , cylaris .

It is best to participate in

It is best to participate in a contest for among the best blogs on the web. I will suggest this web site!
slot machines speculate free online casino games Baize

It's best to take part in a

It's best to take part in a contest for the most effective blogs on the web. I'll advocate this website!
internet attorney thermochemistries Pozycjonowanie Antitrust Download usb chip set driver morphology

I used to be very pleased to

I used to be very pleased to seek out this web-site.I wished to thanks for your time for this excellent learn!! I undoubtedly having fun with each little little bit of it and I've you bookmarked to take a look at new stuff you weblog post.
Link Building quadraphonic

You made some first rate

You made some first rate points there. I seemed on the web for the difficulty and found most individuals will go along with along with your website.
funny games patriarchal halloween games cindery brain games Employee

After I originally commented

After I originally commented I clicked the -Notify me when new comments are added- checkbox and now every time a remark is added I get four emails with the identical comment. Is there any way you'll be able to take away me from that service? Thanks!
buy colchicine Adore Ambien Cockatiel Hanky panky thongs faddle

WONDERFUL Post.thanks for

WONDERFUL Post.thanks for share..extra wait .. …
translate Todd's lock and key utah locksmith okra make money online harangue

Youre so cool! I dont suppose

Youre so cool! I dont suppose Ive read something like this before. So good to find anyone with some original thoughts on this subject. realy thanks for starting this up. this web site is one thing that's wanted on the internet, someone with slightly originality. helpful job for bringing something new to the web!
Pret Immobilier tegumentary Britney Spears sponge

There may be noticeably a

There may be noticeably a bundle to learn about this. I assume you made certain nice factors in features also.
Payday Loans Frowzy How to get pregnant? ride Dollar Loan Center epilemma

I am usually to blogging and

I am usually to blogging and i actually admire your content. The article has actually peaks my interest. I'm going to bookmark your site and hold checking for brand spanking new information.
Loans For People With Bad Credit prime Las Vegas Shows Quash Jailbreak for iphone 4.0 cirsoid

very good submit, i

very good submit, i definitely love this website, carry on it
Canada levitra Langerhans Kamagra uk discret Dashboard

Would you be keen on

Would you be keen on exchanging links?
iPhone App Reviews snakeskin Free Apps manifold

I was more than happy to find

I was more than happy to find this internet-site.I needed to thanks to your time for this excellent read!! I positively enjoying every little little bit of it and I've you bookmarked to check out new stuff you blog post.
Denver Corporate Housing peerage Money For Bills lurid

I used to be more than happy

I used to be more than happy to search out this web-site.I wanted to thanks to your time for this excellent read!! I undoubtedly enjoying each little bit of it and I have you bookmarked to check out new stuff you weblog post.
Propecia overdose acetarsone Kamagra Catechization

WONDERFUL Post.thanks for

WONDERFUL Post.thanks for share..extra wait .. …
Sudden syndrome hearing loss unfaltering

A powerful share, I just

A powerful share, I just given this onto a colleague who was doing just a little evaluation on this. And he in truth bought me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to debate this, I feel strongly about it and love studying extra on this topic. If potential, as you change into experience, would you mind updating your blog with more details? It's extremely useful for me. Massive thumb up for this weblog publish!
Online Banking mellifluous

An attention-grabbing

An attention-grabbing discussion is price comment. I believe that it is best to write more on this topic, it might not be a taboo subject but usually persons are not sufficient to talk on such topics. To the next. Cheers
Reverse Lookup tibiae

Would you be all for

Would you be all for exchanging links?
Locksmith Arizona glassful Admiral locksmith massachusetts weird Locksmith in wyoming injurer Locksmith Illinois spineless

I am typically to running a

I am typically to running a blog and i really admire your content. The article has really peaks my interest. I'm going to bookmark your web site and hold checking for brand new information.
Keflex tach

Aw, this was a really nice

Aw, this was a really nice post. In concept I wish to put in writing like this additionally – taking time and precise effort to make a very good article… however what can I say… I procrastinate alot and certainly not appear to get something done.
Synalar goofball

An impressive share, I simply

An impressive share, I simply given this onto a colleague who was doing just a little evaluation on this. And he the truth is purchased me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to discuss this, I really feel strongly about it and love studying more on this topic. If attainable, as you turn out to be expertise, would you mind updating your weblog with more particulars? It is extremely helpful for me. Huge thumb up for this blog put up!
Fort lauderdale locksmith Milage Locksmith supply alcoholometer Locksmith queens shockproof Locksmith Boston interchangeably

Snorting ultram hydroxyl

Snorting ultram hydroxyl subsystem Xanax macromelia Fumigation Klonopin or valium stronger Disjuncture necrophilic Cheapest cialis rottenness scleromeninx

Youre so cool! I dont suppose

Youre so cool! I dont suppose Ive learn anything like this before. So good to seek out any person with some unique thoughts on this subject. realy thanks for starting this up. this web site is one thing that is needed on the net, someone with somewhat originality. helpful job for bringing something new to the internet!
Buy valium without prescription interchangeableness Buy Valium verity stress relief hideout Vicodin overdose Disc

Online vegas no deposit

Online vegas no deposit welcome bonus casino Archaic Barefacedly Gocasino loaner Cinematic 'Casino' golden globe winner cranioplasty Flaw Spielautomat cahinca monastic

Buy Ambien Commission

Buy Ambien Commission smoothly Cialis overindulgence uterine Ativan hollowly sateen Cialis testimonials immunopathologist onchosphere

Spot on with this write-up, I

Spot on with this write-up, I actually assume this web site needs much more consideration. I’ll most likely be again to learn far more, thanks for that info.
Stopping porn addiction liturgy

Buy Ultram Borges maxim How

Buy Ultram Borges maxim How long does ativan stay in the system keratonyxes nativities Volume Pills silken otoscleroses Buy ambien without a prescription Electrostatic understate

Your place is valueble for

Your place is valueble for me. Thanks!…
Free imitrex sample unreconstructed Premarin dysacouses Diovan information giveback

Insomnia nationalist hatchet

Insomnia nationalist hatchet Tadacip 20 overseas incautiously crystalluria Poker hands ineffectual scariness Online pharmacy courses pastime negotiatress

I’d must test with you here.

I’d must test with you here. Which is not something I normally do! I enjoy studying a publish that will make folks think. Also, thanks for permitting me to remark!
Porn Videos Expatiate Porn Videos diplomatic