Solved

Python color text and splash screen

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
Python Hue issue with import 12 89
object oriented programming comparison 5 85
Pass stdin text to Python subprocess 3 47
Getting Variable not defined error in Python 1 38
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 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 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 …

735 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