#!/usr/bin/env python
import os

def _main010():
    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 _main011():
    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'
    try:        
        from IPython.terminal.embed import InteractiveShellEmbed
    except ImportError:
        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 *    
    vitems = IPython.__version__.split(".")
    vmaj = int(vitems[0])
    vmin = int(vitems[1])
    if vmaj == 0:
        if vmin >= 11:
            ipshell = _main011()
        else:
            ipshell = _main010()
    else:
        ipshell = _main011()
    ipshell()

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