Solved

Python color text and splash screen

Posted on 2007-11-24
4
3,228 Views
Last Modified: 2012-08-14
I am working on a telnet python BBS and have ran into two problems.

The first one is, I can not find any way to have the server print something in color on the client's screen like having the line:

self.conn.send("Name? ")

print "Name?" in red or having the line:

print "Handling message: ",msg

print "Handling Message: Message" come up green.

The second problem I am having is the splash screen print. The only way I know how to handle the splash screen is like the following:


self.conn.send("                                         .__            ")
self.conn.send("      ____ ___  ________    _____ ______ |  |   ____    ")
self.conn.send("    _/ __ \\  \/  /\__  \  /     \\____ \|  | _/ __ \   ")
self.conn.send("    \  ___/ >    <  / __ \|  Y Y  \  |_> >  |_\  ___/   ")
self.conn.send("     \___  >__/\_ \(____  /__|_|  /   __/|____/\___  >  ")
self.conn.send("         \/      \/     \/      \/|__|             \/   ")

But that always seems to error. (I know the last part does not look very good so you might want to past it into note pad to view it).
0
Comment
Question by:ZoeticNepenthe
4 Comments
 
LVL 29

Expert Comment

by:pepr
ID: 20344191
It is not clear what OS do you use. Anyway, if console is responsible for displaying the coloured text at the client side and server sends the text, then also the colour attributes must be sent somehow from the server.

The curses module may be the answer for you (http://docs.python.org/lib/module-curses.html). See "Curses Programming with Python" by A.M. Kuchling and Eric S. Raymond (http://www.amk.ca/python/howto/curses/curses.html). Focus on parts "4 Displaying Text" and "4.1 Attributes and Color".
0
 
LVL 1

Accepted Solution

by:
ZoeticNepenthe earned 0 total points
ID: 20363036
I found my own solution here but thinks pepr.

To print color text this works:

print '\033[1;31mSome Red Text\033[0m'
print '\033[1;32mSome Green Text\033[0m'
print '\033[1;33mSome Yellow text\033[0m'
print '\033[1;34mSome Blue Text\033[0m'

http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html has other information on the color codes.

self.conn.send("                                         .__            ")
self.conn.send("      ____ ___  ________    _____ ______ |  |   ____    ")
self.conn.send("    _/ __ \\  \/  /\__  \  /     \\____ \|  | _/ __ \   ")
self.conn.send("    \  ___/ >    <  / __ \|  Y Y  \  |_> >  |_\  ___/   ")
self.conn.send("     \___  >__/\_ \(____  /__|_|  /   __/|____/\___  >  ")
self.conn.send("         \/      \/     \/      \/|__|             \/   ")

should have been

self.conn.send("                                         .__            \r\n")
self.conn.send("      ____ ___  ________    _____ ______ |  |   ____    \r\n")
self.conn.send("    _/ __ \\  \/  /\__  \  /     \\____ \|  | _/ __ \   \r\n")
self.conn.send("    \  ___/ >    <  / __ \|  Y Y  \  |_> >  |_\  ___/   \r\n")
self.conn.send("     \___  >__/\_ \(____  /__|_|  /   __/|____/\___  >  \r\n")
self.conn.send("         \/      \/     \/      \/|__|             \/   \r\n")

I just needed the "\r\n" command at the end.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20412425
Closed, 250 points refunded.
modus_operandi
EE Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question