# Stollen from github.com/coderholic/config
# Most of these from http://sontek.net/tips-and-tricks-for-the-python-interpreter
import os
import sys

try:
    import readline
except ImportError:
    print("Module readline not available.")
else:
    import rlcompleter
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind ("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")

    # Enable a History
    HISTFILE="%s/.pyhistory" % os.environ["HOME"]

    # Read the existing history if there is one
    try:
        readline.read_history_file(HISTFILE)
    except:
        pass

    # Set maximum number of items that will be written to the history file
    readline.set_history_length(300)

    def savehist():
        import readline
        global HISTFILE
        readline.write_history_file(HISTFILE)

    import atexit
    atexit.register(savehist)
    del atexit
finally:
    del rlcompleter

WELCOME=''
# Color Support
class TermColors(dict):
    """Gives easy access to ANSI color codes. Attempts to fall back to no color
    for certain TERM values. (Mostly stolen from IPython.)"""

    COLOR_TEMPLATES = (
        ("Black"       , "0;30"),
        ("Red"         , "0;31"),
        ("Green"       , "0;32"),
        ("Brown"       , "0;33"),
        ("Blue"        , "0;34"),
        ("Purple"      , "0;35"),
        ("Cyan"        , "0;36"),
        ("LightGray"   , "0;37"),
        ("DarkGray"    , "1;30"),
        ("LightRed"    , "1;31"),
        ("LightGreen"  , "1;32"),
        ("Yellow"      , "1;33"),
        ("LightBlue"   , "1;34"),
        ("LightPurple" , "1;35"),
        ("LightCyan"   , "1;36"),
        ("White"       , "1;37"),
        ("Normal"      , "0"   ),
    )

    NoColor = ''
    _base  = '\001\033[%sm\002'

    def __init__(self):
        if os.environ.get('TERM') in ('xterm-color', 'xterm-256color', 'linux',
                                    'screen', 'screen-256color', 'screen-bce'):
            self.update(dict([(k, self._base % v) for k,v in self.COLOR_TEMPLATES]))
        else:
            self.update(dict([(k, self.NoColor) for k,v in self.COLOR_TEMPLATES]))
_c = TermColors()



import sys
# Enable Color Prompts
sys.ps1 = '%s>>> %s' % (_c['Green'], _c['Normal'])
sys.ps2 = '%s... %s' % (_c['Red'], _c['Normal'])

# Enable Pretty Printing for stdout
def my_displayhook(value):
    if value is not None:
        try:
            import __builtin__
            __builtin__._ = value
        except ImportError:
            __builtins__._ = value

        import pprint
        pprint.pprint(value)
        del pprint

sys.displayhook = my_displayhook

@@ -1459,24 +1459,16 @@
 %221;30%22),
-%0A       
  (%22Light
@@ -1482,24 +1482,24 @@
  , %221;31%22),%0A
+
         (%22Li
@@ -1718,19 +1718,16 @@
    , %220%22
-   
 ),%0A    )
@@ -2602,16 +2602,16 @@
 pprint%0A%0A
-
 sys.disp
@@ -2635,8 +2635,755 @@
 layhook%0A
+%0Aif 'DJANGO_SETTINGS_MODULE' in os.environ:%0A    from django.db.models.loading import get_models%0A    from django.test.client import Client%0A    from django.test.utils import setup_test_environment, teardown_test_environment%0A    from django.conf import settings as S%0A%0A    class DjangoModels(object):%0A        %22%22%22Loop through all the models in INSTALLED_APPS and import them.%22%22%22%0A        def __init__(self):%0A            for m in get_models():%0A                setattr(self, m.__name__, m)%0A%0A    A = DjangoModels()%0A    C = Client()%0A%0A    WELCOME += %22%22%22%25(Green)s%0A    Django environment detected.%0A* Your INSTALLED_APPS models are available as %60A%60.%0A* Your project settings are available as %60S%60.%0A* The Django test client is available as %60C%60.%0A%25(Normal)s%22%22%22 %25 _c%0A

Revert "I don't use Django (for now)" because I use it now.