By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,424 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

Re: Extend functionality of printf (Add colours)

P: n/a

Tomás Ó hÉilidhe <to*@lavabit.comwrote in message news:39**********************************@a29g2000 pra.googlegroups.com...
>
Firstly... before the guns go off... I realise that the C Standard
doesn't mention anything about the existence of colour, which is why
I'm writing a small little cross-platform library for setting the
console text colour.
Just curious...have you ever heard of something called "conio.h"
and functions like "cprintf()"? Definitely NOT a C "standard" library,
just wondering if you've heard of it, you might want to check it out
for possible linking/defines on "some" platforms...

---
William Ernest Reid

Nov 10 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Nov 10, 9:38 pm, "Bill Reid" <hormelf...@happyhealthy.netwrote:
Just curious...have you ever heard of something called "conio.h"
There's an easier way. For instance on Linux, you can do:

printf("\033[37mHello!");

They call them escape sequences or something like that.

I've already got the code written and working for Linux, and now I'm
writing it for Windows. I had thought that under Windows I might be
able to do:

printf("$e[37mHello!");

but I tried it just there and it didn't work (as far as I know it
worked in DOS). I know under Windows there's a Win32 API function
called "SetConsoleTextAttribute", but I was hoping the above would
work because I'm not too keen on explicitly linking with gdi32.lib,
nor am I keen on including the whore of a file that is <windows.h>.
Anyone know another way of changing the console text colour in
Windows?

Just as an aside, I'm also writing a cross-platform library for
dealing with raw sockets. I pretty much have it simplified to four
functions:

OpenRawsock
SendEthernetFrame
RecvEthernetFrame
CloseRawsock

So far I have it working for Linux and Windows (The Linux version used
Berkeley Sockets and the Windows version uses pcap because WinSock no
longer allows raw sockets). Anyone who's interested can e-mail me.
Nov 10 '08 #2

P: n/a
In article <1d**********************************@b31g2000prb. googlegroups.com>,
Tomás Ó hÉilidhe <to*@lavabit.comwrote:
>There's an easier way. For instance on Linux, you can do:

printf("\033[37mHello!");

They call them escape sequences or something like that.
This isn't a specifically Linux feature. It's a feature of the
terminal emulator (or real terminal) that you're using. Xterm (in
"VT" mode) uses ANSI escape sequences, which are what you're
describing.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 10 '08 #3

P: n/a
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article
<1d**********************************@b31g2000prb. googlegroups.com>,
Tomás Ó hÉilidhe <to*@lavabit.comwrote:
>>There's an easier way. For instance on Linux, you can do:

printf("\033[37mHello!");

They call them escape sequences or something like that.

This isn't a specifically Linux feature. It's a feature of the
terminal emulator (or real terminal) that you're using. Xterm (in
"VT" mode) uses ANSI escape sequences, which are what you're
describing.
Note that "ANSI" here refers to the ANSI standard that describes the
behavior of VT100-compatible display terminals (including emulators);
it's completely separate from the ANSI (and/or ISO) C standard.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 10 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.