#!/usr/bin/env python
import os

def main10():
    from IPython.Shell import IPShellEmbed

    banner = welcome()
    exit_msg = ''
    args = ['-colors','Linux','-noconfirm_exit', '-readline', 
            '-xmode', 'Plain', '-autocall', '2', '-autoindent',
            '-pi1', 'ASAP> ', '-po', 'asap>: ', '-pprint']
    ipshell = IPShellEmbed(args,banner,exit_msg)
    return ipshell


def main11():
    from IPython.config.loader import Config
    cfg = Config()
    prompt_config = cfg.PromptManager
    prompt_config.in_template = 'ASAP> '
    prompt_config.out_template = 'asap>: '
    cfg.InteractiveShell.autoindent = True
    cfg.InteractiveShell.autocall = 2
    cfg.InteractiveShell.magic_pprint = True
    cfg.InteractiveShell.use_readline=True
    cfg.InteractiveShell.confirm_exit=False
    cfg.InteractiveShell.xmode='Plain'

    from IPython.frontend.terminal.embed import InteractiveShellEmbed
    ipshell = InteractiveShellEmbed(config=cfg,
                                    banner1 = welcome(),
                                    exit_msg = '')
    return ipshell

try: 
    os.system('clear')
    import IPython
    from asap import *
    vers = int(IPython.__version__.split(".")[1])
    if vers >= 11:
        ipshell = main11()
    else:
        ipshell = main10()
    ipshell()

except ImportError:
    banner =  "No ipython found. Running standard python"
    import code
    from asap import *
    del main
    code.interact(banner, local=locals())
