Add IPython prompt support

This commit is contained in:
ZyX 2013-01-24 22:36:46 +04:00 committed by Kim Silkebækken
parent 98269a4bb5
commit 0b251425da
8 changed files with 134 additions and 0 deletions

View File

@ -134,3 +134,26 @@ Add the following line to your :file:`tmux.conf`, where ``{path}`` is the
absolute path to your Powerline installation directory::
source '{path}/powerline/bindings/tmux/powerline.conf'
IPython prompt
^^^^^^^^^^^^^^
For IPython<0.11 add the following lines to your
:file:`.ipython/ipy_user_conf.py`::
# top
from powerline.bindings.ipython.pre_0_11 import setup as powerline_setup
# main() function (assuming you launched ipython without configuration to
# create skeleton ipy_user_conf.py file):
powerline_setup()
For IPython>=0.11 add the following line to your :file:`ipython_config.py`
file in the profile you are using::
c.InteractiveShellApp.extensions = [
'powerline.bindings.ipython.post_0_11'
]
IPython=0.11* is not supported and does not work. IPython<0.10 was not
tested (not installable by pip).

View File

View File

@ -0,0 +1,23 @@
from powerline.core import Powerline
from IPython.core.prompts import PromptManager
class PowerlinePromptManager(PromptManager):
powerline = None
def __init__(self, powerline, **kwargs):
self.powerline = powerline
super(PowerlinePromptManager, self).__init__(**kwargs)
def _render(self, name, color=True, *args, **kwargs):
if name != 'in':
return super(PowerlinePromptManager, self)._render(name, color, *args, **kwargs)
return self.powerline.renderer.render(color=color)
def load_ipython_extension(ip):
powerline = Powerline('ipython')
ip.prompt_manager = PowerlinePromptManager(powerline=powerline,
shell=ip.prompt_manager.shell, config=ip.prompt_manager.config)

View File

@ -0,0 +1,27 @@
from powerline.core import Powerline
from IPython.Prompts import BasePrompt
from IPython.ipapi import get as get_ipython
class PowerlinePrompt(BasePrompt):
def __init__(self, powerline, *args, **kwargs):
self.powerline = powerline
super(PowerlinePrompt, self).__init__(*args, **kwargs)
def set_p_str(self):
self.p_str = self.powerline.renderer.render()
self.p_str_nocolor = self.powerline.renderer.render(color=False)
def setup(prompt='1'):
ip = get_ipython()
powerline = Powerline('ipython')
attr = 'prompt' + prompt
def late_startup_hook():
old_prompt = getattr(ip.IP.outputcache, attr)
setattr(ip.IP.outputcache, attr, PowerlinePrompt(powerline,
old_prompt.cache, old_prompt.sep, '', old_prompt.pad_left))
ip.IP.hooks.late_startup_hook.add(late_startup_hook)

View File

@ -0,0 +1,25 @@
{
"name": "Default color scheme for IPython prompt",
"colors": {
"black": 16,
"white": 231,
"darkcyan": 74,
"gray0": 233,
"gray1": 235,
"gray2": 236,
"gray3": 239,
"gray4": 240,
"gray5": 241,
"gray6": 244,
"gray7": 245,
"gray8": 247,
"gray9": 250,
"gray10": 252
},
"groups": {
"virtualenv": { "fg": "white", "bg": "darkcyan" },
"prompt": { "fg": "gray9", "bg": "gray4" }
}
}

View File

@ -27,6 +27,10 @@
"local_themes": {
"help": "help"
}
},
"ipython": {
"colorscheme": "default",
"theme": "default"
}
}
}

View File

@ -0,0 +1,16 @@
{
"default_module": "powerline.segments.common",
"segments": {
"left": [
{
"name": "virtualenv"
},
{
"type": "string",
"contents": "In:",
"highlight_group": ["prompt"],
"draw_divider": false
}
]
}
}

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from powerline.renderers.shell import ShellRenderer
class IpythonRenderer(ShellRenderer):
'''Powerline ipython segment renderer.'''
def render(self, color=True, *args, **kwargs):
self.color = color
return super(IpythonRenderer, self).render(*args, **kwargs)
def hl(self, *args, **kwargs):
if not self.color:
return ''
else:
return '\x01' + super(IpythonRenderer, self).hl(*args, **kwargs) + '\x02'