473,488 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Extend functionality of printf (Add colours)


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
3 3397
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3260
by: Eric Anderson | last post by:
I am trying to use XSLT to extend XHTML so that I can have custom widgets. For example I have a calendar control. Whenever I put the following in the psudo-XHTML doc: <calendarbox name="mycal"/>...
4
3937
by: Els | last post by:
Hi, I would like an opinion on the following: I have a page which is made up of background-images with transparent linked images in front of it, which on hover show text in CSS popups. Due to...
4
1337
by: jacster | last post by:
Hi, I want to extend the functionality of my Firefox browser. Can you write mozilla plugins in Javascript; can anyone point me to some resources for doing this? If not, can I save Javascript...
8
2234
by: Doug Laidlaw | last post by:
I tried to grab an image from a Web page the other day. It turned out that the page was made up of three horizontal bands, and part of the image was in each. One band was a JPEG, another was a...
10
2008
by: Jerzy Karczmarczuk | last post by:
Gurus, before I am tempted to signal this as a bug, perhaps you might convince me that it should be so. If I type l=range(4) l.extend() l gives , what else... On the other hand, try
6
2668
by: jk | last post by:
Looking through WebUIValidation.js, I discovered that the standard validators don't cater for non-numeric date formats (e.g. dd-MMM-yyyy) which I would like to do To keep code to a minimum, I...
1
1387
by: aaa | last post by:
Im using a datagrid object to view data, Is it possible to extend selected row and show other details at the extended part of the row? If the answer is Y: Is it part of the datagrid's...
1
1923
by: Jeremy S. | last post by:
I'm implementing logging via the TraceSource class and related TraceSwitch and TraceListeners classes. The TextWriterTraceListener does much of what I need. But it does not roll the log over at...
4
5375
by: spectrumdt | last post by:
Hello. I am trying to extend Python with some C code. I made a trivial "Hello World" program in C that I am trying to wrap in "boilerplate" for inclusion in a Python program. But I can't compile...
0
491
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
On Nov 10, 6:26 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote: You use the TOE_PLATFORM macro to choose your platform. 1 is Unix. 2 is Windows. Here's what I've got so far. Any comments are...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.