470,641 Members | 1,570 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

How do I print out in the standard output coloured lines

Hi,

I'm interested in printing out coloured lines of my application and
I don't know what to use. Can anybody give me an idea??

Regards.

Carlos Niharra López

Feb 2 '07 #1
9 2470
cn*******@gmail.com wrote in
news:11**********************@v45g2000cwv.googlegr oups.com:
Hi,

I'm interested in printing out coloured lines of my
application and
I don't know what to use. Can anybody give me an idea??
You could speed up the process if you explain what your application
is and what you mean by colored lines. Does your application emit
output to a plotter, an ink-jet printer, or a color laser printer? Is
it a drawing program? An editor in which you want lines colored to
highlight context? It might be useful to know what system you are
running as well. Just a little detail here.

--
rzed
Feb 2 '07 #2
On Feb 2, 1:16 pm, rzed <rzan...@gmail.comwrote:
cnihar...@gmail.com wrote innews:11**********************@v45g2000cwv.google groups.com:
Hi,
I'm interested in printing out coloured lines of my
application and
I don't know what to use. Can anybody give me an idea??

You could speed up the process if you explain what your application
is and what you mean by colored lines. Does your application emit
output to a plotter, an ink-jet printer, or a color laser printer? Is
it a drawing program? An editor in which you want lines colored to
highlight context? It might be useful to know what system you are
running as well. Just a little detail here.

--
rzed
Well, yes, it's a program that prints out lines to the standard output
with a print command, and I want to print them coloured. For example:

print "Hello World!!"

I want it in red colour.

That's all.

Feb 2 '07 #3
cn*******@gmail.com wrote in
news:11**********************@h3g2000cwc.googlegro ups.com:
On Feb 2, 1:16 pm, rzed <rzan...@gmail.comwrote:
>cnihar...@gmail.com wrote
innews:11**********************@v45g2000cwv.googl egroups.com:
Hi,
I'm interested in printing out coloured lines of my
application and
I don't know what to use. Can anybody give me an idea??

You could speed up the process if you explain what your
application is and what you mean by colored lines. Does your
application emit output to a plotter, an ink-jet printer, or a
color laser printer? Is it a drawing program? An editor in
which you want lines colored to highlight context? It might be
useful to know what system you are running as well. Just a
little detail here.

--
rzed

Well, yes, it's a program that prints out lines to the standard
output with a print command, and I want to print them coloured.
For example:

print "Hello World!!"

I want it in red colour.

That's all.

If you're on Linux, you could use the curses module. There may be
a precompiled Windows version compatible with your Python version,
or maybe not, but the Windows source is available, and you may be
able to get it to work with your Python with some effort. Linux
distros include curses, I think. For Windows curses, take a look
at <http://adamv.com/dev/python/curses/>. You will understand why
the phrase "Windows curses" is used, I expect.

--
rzed
Feb 2 '07 #4
On Feb 2, 1:38 pm, rzed <rzan...@gmail.comwrote:
cnihar...@gmail.com wrote innews:11**********************@h3g2000cwc.googleg roups.com:
On Feb 2, 1:16 pm, rzed <rzan...@gmail.comwrote:
cnihar...@gmail.com wrote
innews:11**********************@v45g2000cwv.google groups.com:
Hi,
I'm interested in printing out coloured lines of my
application and
I don't know what to use. Can anybody give me an idea??
You could speed up the process if you explain what your
application is and what you mean by colored lines. Does your
application emit output to a plotter, an ink-jet printer, or a
color laser printer? Is it a drawing program? An editor in
which you want lines colored to highlight context? It might be
useful to know what system you are running as well. Just a
little detail here.
--
rzed
Well, yes, it's a program that prints out lines to the standard
output with a print command, and I want to print them coloured.
For example:
print "Hello World!!"
I want it in red colour.
That's all.

If you're on Linux, you could use the curses module. There may be
a precompiled Windows version compatible with your Python version,
or maybe not, but the Windows source is available, and you may be
able to get it to work with your Python with some effort. Linux
distros include curses, I think. For Windows curses, take a look
at <http://adamv.com/dev/python/curses/>. You will understand why
the phrase "Windows curses" is used, I expect.

--
rzed
Yes, I'm on a Linux box. I've tried with the curses module, but I
don't how I could fetch the current use of curses of my shell. I don't
know if I'm talking about something impossible. I've made some tests
with the curses module and works fine, but I need to capture the
current window and change the attributes of texts.

Carlos Niharra López

Feb 2 '07 #5
It was 2 Feb 2007 04:27:06 -0800, when cn*******@gmail.com wrote:
print "Hello World!!"

I want it in red colour.

That's all.
Use colour escape codes:

print "\033[1;31mHello World\033[0m"

That's all. :-)

--
groetjes,
BBBart

Golly, I'd hate to have a kid like me!
-- Calvin
Feb 2 '07 #6
On Feb 2, 2:08 pm, Bart Van Loon <bbb...@inGen.bewrote:
It was 2 Feb 2007 04:27:06 -0800, when cnihar...@gmail.com wrote:
print "Hello World!!"
I want it in red colour.
That's all.

Use colour escape codes:

print "\033[1;31mHello World\033[0m"

That's all. :-)

--
groetjes,
BBBart

Golly, I'd hate to have a kid like me!
-- Calvin

Well, this is fine. It's what I was looking for. I have done something
similar with a system command execution (echo) but it was not really
smart, but this fit my needs.

Thanks a lot.

Regards.

Carlos Niharra López

Feb 2 '07 #7
On 2007-02-02, rzed <rz*****@gmail.comwrote:
cn*******@gmail.com wrote in
news:11**********************@h3g2000cwc.googlegro ups.com:
>On Feb 2, 1:16 pm, rzed <rzan...@gmail.comwrote:
>>cnihar...@gmail.com wrote
innews:11**********************@v45g2000cwv.goog legroups.com:

Hi,

I'm interested in printing out coloured lines of my
application and
I don't know what to use. Can anybody give me an idea??

You could speed up the process if you explain what your
application is and what you mean by colored lines. Does your
application emit output to a plotter, an ink-jet printer, or a
color laser printer? Is it a drawing program? An editor in
which you want lines colored to highlight context? It might be
useful to know what system you are running as well. Just a
little detail here.

--
rzed

Well, yes, it's a program that prints out lines to the standard
output with a print command, and I want to print them coloured.
For example:

print "Hello World!!"

I want it in red colour.

That's all.

If you're on Linux, you could use the curses module. There may
be a precompiled Windows version compatible with your Python
version, or maybe not, but the Windows source is available, and
you may be able to get it to work with your Python with some
effort. Linux distros include curses, I think. For Windows
curses, take a look at <http://adamv.com/dev/python/curses/>.
You will understand why the phrase "Windows curses" is used, I
expect.
On Windows, there's pdcurses for DOS or ncurses for the Cygwin
platform, but I don't know how to get either to work with Python.

Far simpler to get working in Windows is Fredrik Lundh's Console.

http://www.effbot.org/downloads/#console

If you're using Windowd 98 or earlier there are versions of a
Python readline library that provide cursor addressing and color
using the ANSI excape sequences.

--
Neil Cerutti
Feb 2 '07 #8
Hello Carlos,
I'm interested in printing out coloured lines of my application and
I don't know what to use. Can anybody give me an idea??
I use the following script:
#!/usr/bin/env python
'''Print message using ANSI terminal codes'''

__author__ = "Miki Tebeka <mi*********@gmail.com>"
# $Id: ansiprint 1229 2005-05-16 05:50:22Z mikit $

# ================================================== ===
# Copyright (c) Miki Tebeka <mi*********@gmail.com>
# This file is under the GNU Public License (GPL), see
# http://www.gnu.org/copyleft/gpl.html for more details
# ================================================== ===

from sys import stdout, stderr

# Format
bright = 1
dim = 2
underline = 4
blink = 5
reverse = 7
hidden = 8

# Forground
black = 30
red = 31
green = 32
yellow = 33
blue = 34
magenta = 35
cyan = 36
white = 37

# Background
on_black = 40
on_red = 41
on_green = 42
on_yellow = 43
on_blue = 44
on_magenta = 45
on_cyan = 46
on_white = 47

def ansiformat(msg, *args):
'''Format msg according to args.

See http://www.termsys.demon.co.uk/vtansi.htm for more details/
'''
return "\033[%sm%s\033[0m" % (";".join(["%s" % f for f in args]),
msg)

def ansiprint(msg, *args, **kw):
'''Print formatted message.

Should work on ANSI compatible terminal.
'''

if kw.get("stderr", 0):
outfo = stderr
else:
outfo = stdout

outfo.write(ansiformat(msg, *args))
outfo.flush()

if __name__ == "__main__":
from sys import argv, exit
from os.path import basename

h = {
"bright" : bright,
"dim" : dim,
"underline" : underline,
"blink" : blink,
"reverse" : reverse,
"hidden" : hidden,
"black" : black,
"red" : red,
"green" : green,
"yellow" : yellow,
"blue" : blue,
"magenta" : magenta,
"cyan" : cyan,
"white" : white,
"on_black" : on_black,
"on_red" : on_red,
"on_green" : on_green,
"on_yellow" : on_yellow,
"on_blue" : on_blue,
"on_magenta" : on_magenta,
"on_cyan" : on_cyan,
"on_white" : on_white
}

eg = "e.g. ansiprint hello red on_green underline -%s" % \
ansiformat("hello", red, on_green, underline)

# Check command line
if len(argv) < 2:
print >stderr, "usage: %s message [format ...]" %
basename(argv[0])
print >stderr, eg
exit(1)
for i in argv[2:]:
if i not in h:
ansiprint("%s: Unknown format\n" % i, red, bright,
stderr=True)
print >stderr, "Formats can be:",
msg = ", ".join([ansiformat(f, h[f]) for f in h.keys()])
print msg
print >stderr, eg
exit(1)

# Print
ansiprint(argv[1], *[h[i] for i in argv[2:]])
print

# vim: ft=python

Hope you find it useful.
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com

Feb 2 '07 #9
<cn*******@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
On Feb 2, 1:38 pm, rzed <rzan...@gmail.comwrote:
cnihar...@gmail.com wrote
innews:11**********************@h3g2000cwc.googleg roups.com:
On Feb 2, 1:16 pm, rzed <rzan...@gmail.comwrote:
cnihar...@gmail.com wrote
innews:11**********************@v45g2000cwv.google groups.com:
Hi,
I'm interested in printing out coloured lines of my
application and
I don't know what to use. Can anybody give me an idea??
[snip]
>
If you're on Linux, you could use the curses module. There may be
a precompiled Windows version compatible with your Python version,
or maybe not, but the Windows source is available, and you may be
able to get it to work with your Python with some effort. Linux
distros include curses, I think. For Windows curses, take a look
at <http://adamv.com/dev/python/curses/>. You will understand why
the phrase "Windows curses" is used, I expect.

--
rzed

Yes, I'm on a Linux box. I've tried with the curses module, but I
don't how I could fetch the current use of curses of my shell. I don't
know if I'm talking about something impossible. I've made some tests
with the curses module and works fine, but I need to capture the
current window and change the attributes of texts.
You may find the following useful, it's from Gentoo's portage:
http://sources.gentoo.org/viewcvs.py...80&view=markup

--
Geoff
Feb 2 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by neutrino | last post: by
5 posts views Thread by Tom Louchbaum | last post: by
2 posts views Thread by Neil Rowe | last post: by
3 posts views Thread by oraustin | last post: by
7 posts views Thread by Ron | last post: by
2 posts views Thread by Phoe6 | last post: by
6 posts views Thread by Greg Esres | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.