Simple Question

M

Materialised

Ok, I need some info on how to print in colours to the xterm using c.

take a simple program

#include <stdio.h>
voice main(void)
{
printf("I want this in colour\n";
return 0;
}

How would I go about getting coloured output?

Thanks
 
M

Materialised

Materialised said:
Ok, I need some info on how to print in colours to the xterm using c.

take a simple program

#include <stdio.h>
voice main(void)
{
printf("I want this in colour\n";
return 0;
}

How would I go about getting coloured output?

Thanks

lol oppps teach me to write code drunk no matter how simple

*void main(void)
 
C

Christopher Benson-Manica

Materialised said:
Ok, I need some info on how to print in colours to the xterm using c.

I'll spare all the regulars the hassle (you're welcome, lol) by stating that
Standard C has nothing to do with colors or xterm. You'll want to post this
question in a newsgroup dedicated to your platform (comp.unix.programmer comes
mind). This newsgroup is dedicated to ANSI C, and all other questions are
off-topic.
 
M

Materialised

Christopher said:
I'll spare all the regulars the hassle (you're welcome, lol) by stating that
Standard C has nothing to do with colors or xterm. You'll want to post this
question in a newsgroup dedicated to your platform (comp.unix.programmer comes
mind). This newsgroup is dedicated to ANSI C, and all other questions are
off-topic.
Thanks sorry for the waste of bandwidth.
 
C

Christopher Benson-Manica

Materialised said:
*void main(void)

void_main_corrections++; /* and you thought INT_MAX was big ;) */

The only standard prototypes for main() are
int main( void );
int main( int argc, char** argv );

Whatever source you're using that says your prototype is correct is wrong.
 
M

Mark Gordon


You can't in standard C. Try in Unix programming news group.
lol oppps teach me to write code drunk no matter how simple

*void main(void)

I would say that is more wrong, but you can't get more wrong than
completely wrong. main returns an int so it is
int main(void)
 
C

CBFalconer

Materialised said:
Ok, I need some info on how to print in colours to the xterm using c.

take a simple program

#include <stdio.h>
voice main(void)
{
printf("I want this in colour\n";
return 0;
}

How would I go about getting coloured output?

Take a sheet of tinted transparent plastic and place it over the
CRT screen. If you have several sheets of different colors you
can adjust the color to suit.

In other words standard C can't do this. It depends on your
hardware and OS etc.
 
D

Dan Pop

In said:
You can't in standard C. Try in Unix programming news group.

Bad redirection. The question belongs to comp.terminals, because Unix
is as colour blind as standard C.

Dan
 
S

Sheldon Simms

Bad redirection. The question belongs to comp.terminals, because Unix
is as colour blind as standard C.

Programming directly to the terminal would be silly.

Since *ix provides libraries to do this a unix programming
news group is a very appropriate place to ask.
 
D

Dan Pop

In said:
Programming directly to the terminal would be silly.

It depends on what exactly you want to achieve.
Since *ix provides libraries to do this a unix programming
news group is a very appropriate place to ask.

The Unix interface is generic enough not to allow exploiting the full
capabilities of a given terminal. So, depending on what exactly you want
to achieve, it may or may not be the right thing.

When the OP mentions an OS, a redirection to the OS programming related
newsgroup is the right thing. When the OP mentions a terminal, the
redirection is to a newsgroup dealing with terminals.

I might be running this xterm on a Unix box, but the application that
generates output on it may very well be running on a platform that
has nothing to do with Unix or its standards.

Dan
 
S

Sheldon Simms

It depends on what exactly you want to achieve.


The Unix interface is generic enough not to allow exploiting the full
capabilities of a given terminal. So, depending on what exactly you want
to achieve, it may or may not be the right thing.

The OP wanted to achieve "coloured output". Which is easily
achievable using curses -- a library which is standardized
by POSIX and available on every POSIX-conforming system.
When the OP mentions an OS, a redirection to the OS programming related
newsgroup is the right thing. When the OP mentions a terminal, the
redirection is to a newsgroup dealing with terminals.

I might be running this xterm on a Unix box, but the application that
generates output on it may very well be running on a platform that
has nothing to do with Unix or its standards.

The probability is good that the OP is programming on an Unix/Linux
platform. The probability is exceedingly great that the OP is programming
on either some version of Windows or Unix/Linux. In every one of these
possibilities, the curses library is available.

The probability is low that the OP wants to learn how to program
"coloured" output on only one particular type of terminal. The
probability is exceedingly low that the OP wants to write his/her
very own terminal-independant "coloured output" library.

Your argument is pedantry and your answer almost certainly points
the OP in a direction he does not want to go. I can understand
being pedantic about what is and is not standard C. I do not
understand why you feel the need to mislead people who are
just looking for some help.
 
D

Dan Pop

In said:
The OP wanted to achieve "coloured output". Which is easily
achievable using curses -- a library which is standardized
by POSIX and available on every POSIX-conforming system.

Without colour support, in the POSIX version. It is the SUS version of
curses that adds colour support.
The probability is low that the OP wants to learn how to program
"coloured" output on only one particular type of terminal.

Then, how do you explain the fact that the OP explicitly mentioned a
terminal name in his request?

Dan
 
S

Sheldon Simms

Without colour support, in the POSIX version. It is the SUS version of
curses that adds colour support.

Ok. I failed to consider the fact that SUS-Curses is an "extension" and
was not incorporated into POSIX. It is nonetheless a widely implemented
standard.
Then, how do you explain the fact that the OP explicitly mentioned a
terminal name in his request?

Because he knows that his program will run in an xterm. That doesn't
mean he would prefer to write his program in an xterm-specific way
when he can do it easier and more portably by using curses.

-Sheldon
 
D

Dan Pop

In said:
Ok. I failed to consider the fact that SUS-Curses is an "extension" and
was not incorporated into POSIX. It is nonetheless a widely implemented
standard.

On Unix systems. Doesn't help much if your application doesn't run on
one.
Because he knows that his program will run in an xterm. That doesn't
mean he would prefer to write his program in an xterm-specific way
when he can do it easier and more portably by using curses.

It's debatable which is more portable, but it's certainly easier NOT to
use curses for this purpose.

As for the portability: if you use xterm escape sequences, your code
will run *everywhere*, but will produce the intended output only when
its terminal is an xterm (i.e. exactly what the OP was asking for).
If you use SUS-curses, the program will produce the intended output
(or an approximation of it, if some capabilities are missing)
on any terminal but it will be portable *only* to systems with a
SUS-conforming curses implementation.

Dan
 
T

Thomas Dickey

Without colour support, in the POSIX version. It is the SUS version of
curses that adds colour support.

hmm - where's a reference to POSIX specifying curses?
 
S

Sheldon Simms

hmm - where's a reference to POSIX specifying curses?

I don't know what Dan was thinking of, but I was thinking
of curses being part of the Single Unix Specification, which
was incorporated into POSIX. As Dan pointed out, however,
Xopen/Curses is not part of base SUS, and wasn't one of the
things incorporated into POSIX.
 
T

Thomas Dickey

Sheldon Simms said:
hmm - where's a reference to POSIX specifying curses?
[/QUOTE]
I don't know what Dan was thinking of, but I was thinking
of curses being part of the Single Unix Specification, which
was incorporated into POSIX. As Dan pointed out, however,
Xopen/Curses is not part of base SUS, and wasn't one of the
things incorporated into POSIX.

As I read the thread, it states that curses is part of POSIX.
Not having seen this before, I'm curious if there is a reference to it online.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top