473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3395
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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,...

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.