Solved

Python color text and splash screen

Posted on 2007-11-24
4
3,243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

626 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