Merge branch 'ipython-rewrite' into develop
This commit is contained in:
commit
42a9a5a5fc
|
@ -1,5 +1,5 @@
|
||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
from powerline.ipython import IpythonPowerline
|
from powerline.ipython import IpythonPowerline, RewriteResult
|
||||||
|
|
||||||
from IPython.core.prompts import PromptManager
|
from IPython.core.prompts import PromptManager
|
||||||
from IPython.core.hooks import TryNext
|
from IPython.core.hooks import TryNext
|
||||||
|
@ -35,7 +35,11 @@ class PowerlinePromptManager(PromptManager):
|
||||||
)
|
)
|
||||||
self.txtwidth = len(res_nocolor)
|
self.txtwidth = len(res_nocolor)
|
||||||
self.width = self.txtwidth
|
self.width = self.txtwidth
|
||||||
return res if color else res_nocolor
|
ret = res if color else res_nocolor
|
||||||
|
if name == 'rewrite':
|
||||||
|
return RewriteResult(ret)
|
||||||
|
else:
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class ConfigurableIpythonPowerline(IpythonPowerline):
|
class ConfigurableIpythonPowerline(IpythonPowerline):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
from powerline.ipython import IpythonPowerline
|
from powerline.ipython import IpythonPowerline, RewriteResult
|
||||||
|
from powerline.lib.unicode import string
|
||||||
from IPython.Prompts import BasePrompt
|
from IPython.Prompts import BasePrompt
|
||||||
from IPython.ipapi import get as get_ipython
|
from IPython.ipapi import get as get_ipython
|
||||||
from IPython.ipapi import TryNext
|
from IPython.ipapi import TryNext
|
||||||
|
@ -7,30 +8,6 @@ from IPython.ipapi import TryNext
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def string(s):
|
|
||||||
if type(s) is not str:
|
|
||||||
return s.encode('utf-8')
|
|
||||||
else:
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
# HACK: ipython tries to only leave us with plain ASCII
|
|
||||||
class RewriteResult(object):
|
|
||||||
def __init__(self, prompt):
|
|
||||||
self.prompt = string(prompt)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.prompt
|
|
||||||
|
|
||||||
def __add__(self, s):
|
|
||||||
if type(s) is not str:
|
|
||||||
try:
|
|
||||||
s = s.encode('utf-8')
|
|
||||||
except AttributeError:
|
|
||||||
raise NotImplementedError
|
|
||||||
return RewriteResult(self.prompt + s)
|
|
||||||
|
|
||||||
|
|
||||||
class IpythonInfo(object):
|
class IpythonInfo(object):
|
||||||
def __init__(self, cache):
|
def __init__(self, cache):
|
||||||
self._cache = cache
|
self._cache = cache
|
||||||
|
|
|
@ -2,6 +2,24 @@
|
||||||
|
|
||||||
from powerline import Powerline
|
from powerline import Powerline
|
||||||
from powerline.lib import mergedicts
|
from powerline.lib import mergedicts
|
||||||
|
from powerline.lib.unicode import string
|
||||||
|
|
||||||
|
|
||||||
|
# HACK: ipython tries to only leave us with plain ASCII
|
||||||
|
class RewriteResult(object):
|
||||||
|
def __init__(self, prompt):
|
||||||
|
self.prompt = string(prompt)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.prompt
|
||||||
|
|
||||||
|
def __add__(self, s):
|
||||||
|
if type(s) is not str:
|
||||||
|
try:
|
||||||
|
s = s.encode('utf-8')
|
||||||
|
except AttributeError:
|
||||||
|
raise NotImplementedError
|
||||||
|
return RewriteResult(self.prompt + s)
|
||||||
|
|
||||||
|
|
||||||
class IpythonPowerline(Powerline):
|
class IpythonPowerline(Powerline):
|
||||||
|
|
|
@ -56,3 +56,10 @@ class FailedUnicode(unicode):
|
||||||
FailedUnicode.
|
FailedUnicode.
|
||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def string(s):
|
||||||
|
if type(s) is not str:
|
||||||
|
return s.encode('utf-8')
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
|
Loading…
Reference in New Issue