Solved

Python color text and splash screen

Posted on 2007-11-24
4
3,207 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 28

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
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…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now