Last active
March 24, 2017 18:24
-
-
Save squizzi/9b2cdef6a6761298f60f9bd22b56c2c5 to your computer and use it in GitHub Desktop.
A cute little message printer that doesn't need any special libraries to run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (C) 2017, Kyle Squizzato <[email protected]> | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or | |
# (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
""" | |
Terminal colors | |
""" | |
class colors: | |
INFO = '\033[95m' # purple | |
OKBLUE = '\033[94m' # blue | |
OKGREEN = '\033[92m' # green | |
WARNING = '\033[93m' # yellow | |
ERROR = '\033[91m' # red | |
ENDC = '\033[0m' # white | |
BOLD = '\033[1m' # bold | |
UNDERLINE = '\033[4m' # underline | |
""" | |
Construct a message with the following syntax: | |
[STATE] Message contents | |
with optional colorization using the above colors class | |
""" | |
def print_message(message, state=None, color=None): | |
# color should be a member of above colors class, ie. colors.OKGREEN | |
if color == None: | |
# if no color is supplied use white | |
color = colors.ENDC | |
else: | |
# calls to this function must accept an item from the colors class | |
# above only | |
try: | |
color = color | |
except AttributeError as e: | |
raise | |
# if no state is supplied just build message with provided color | |
if state == None: | |
constructed_state = color + '' | |
else: | |
# else uppercase it | |
state = state.upper() | |
constructed_state = color + ('[{0}]'.format(state)) | |
# construct message from constructed_state | |
constructed_message = str(constructed_state).ljust(20) + colors.ENDC + message | |
return constructed_message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment