mirror of
https://github.com/powerline/powerline.git
synced 2025-05-03 06:11:09 +02:00
Now imports follow the following structure: 1. __future__ line: exactly one line allowed: from __future__ import (unicode_literals, division, absolute_import, print_function) (powerline.shell is the only exception due to problems with argparse). 2. Standard python library imports in a form `import X`. 3. Standard python library imports in a form `from X import Y`. 4. and 5. 2. and 3. for third-party (non-python and non-powerline imports). 6. 3. for powerline non-test imports. 7. and 8. 2. and 3. for powerline testing module imports. Each list entry is separated by exactly one newline from another import. If there is module docstring it goes between `# vim:` comment and `__future__` import. So the structure containing all items is the following: #!/usr/bin/env python # vim:fileencoding=utf-8:noet '''Powerline super module''' import sys from argparse import ArgumentParser import psutil from colormath.color_diff import delta_e_cie2000 from powerline.lib.unicode import u import tests.vim as vim_module from tests import TestCase .
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
# vim:fileencoding=utf-8:noet
|
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
|
|
|
from powerline import Powerline
|
|
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):
|
|
def init(self):
|
|
super(IPythonPowerline, self).init(
|
|
'ipython',
|
|
use_daemon_threads=True
|
|
)
|
|
|
|
def get_config_paths(self):
|
|
if self.paths:
|
|
return self.paths
|
|
else:
|
|
return super(IPythonPowerline, self).get_config_paths()
|
|
|
|
def get_local_themes(self, local_themes):
|
|
return dict(((type, {'config': self.load_theme_config(name)}) for type, name in local_themes.items()))
|
|
|
|
def load_main_config(self):
|
|
r = super(IPythonPowerline, self).load_main_config()
|
|
if self.config_overrides:
|
|
mergedicts(r, self.config_overrides)
|
|
return r
|
|
|
|
def load_theme_config(self, name):
|
|
r = super(IPythonPowerline, self).load_theme_config(name)
|
|
if name in self.theme_overrides:
|
|
mergedicts(r, self.theme_overrides[name])
|
|
return r
|
|
|
|
def do_setup(self, wrefs):
|
|
for wref in wrefs:
|
|
obj = wref()
|
|
if obj is not None:
|
|
setattr(obj, 'powerline', self)
|