Rearrange renderers: move *_prompt modules one level up
Renames powerline.renderers.zsh_prompt to powerline.renderers.shell.zsh, same for other *sh_prompt modules.
This commit is contained in:
parent
b5b91afcae
commit
4a8b81e68b
|
@ -279,12 +279,14 @@ class Powerline(object):
|
|||
colorschemes, render module (``powerline.renders.{ext}``).
|
||||
:param str renderer_module:
|
||||
Overrides renderer module (defaults to ``ext``). Should be the name of
|
||||
the package imported like this: ``powerline.renders.{render_module}``.
|
||||
the package imported like this: ``powerline.renderers.{render_module}``.
|
||||
If this parameter contains a dot, ``powerline.renderers.`` is not
|
||||
prepended. There is also a special case for renderers defined in
|
||||
toplevel modules: ``foo.`` (note: dot at the end) tries to get renderer
|
||||
from module ``foo`` (because ``foo`` (without dot) tries to get renderer
|
||||
from module ``powerline.renderers.foo``).
|
||||
from module ``powerline.renderers.foo``). When ``.foo`` (with leading
|
||||
dot) variant is used ``renderer_module`` will be
|
||||
``powerline.renderers.{ext}{renderer_module}``.
|
||||
:param bool run_once:
|
||||
Determines whether .renderer.render() method will be run only once
|
||||
during python session.
|
||||
|
@ -307,15 +309,20 @@ class Powerline(object):
|
|||
shutdown_event=None,
|
||||
config_loader=None):
|
||||
self.ext = ext
|
||||
self.renderer_module = renderer_module or ext
|
||||
self.run_once = run_once
|
||||
self.logger = logger
|
||||
self.use_daemon_threads = use_daemon_threads
|
||||
|
||||
if '.' not in self.renderer_module:
|
||||
self.renderer_module = 'powerline.renderers.' + self.renderer_module
|
||||
elif self.renderer_module[-1] == '.':
|
||||
self.renderer_module = self.renderer_module[:-1]
|
||||
if not renderer_module:
|
||||
self.renderer_module = 'powerline.renderers.' + ext
|
||||
elif '.' not in renderer_module:
|
||||
self.renderer_module = 'powerline.renderers.' + renderer_module
|
||||
elif renderer_module.startswith('.'):
|
||||
self.renderer_module = 'powerline.renderers.' + ext + renderer_module
|
||||
elif renderer_module.endswith('.'):
|
||||
self.renderer_module = renderer_module[:-1]
|
||||
else:
|
||||
self.renderer_module = renderer_module
|
||||
|
||||
self.find_config_files = generate_config_finder(self.get_config_paths)
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ _powerline_prompt() {
|
|||
# Arguments: side, last_exit_code, jobnum
|
||||
$POWERLINE_COMMAND shell $1 \
|
||||
--width="${COLUMNS:-$(_powerline_columns_fallback)}" \
|
||||
-r bash_prompt \
|
||||
-r.bash \
|
||||
--last_exit_code=$2 \
|
||||
--jobnum=$3 \
|
||||
--renderer_arg="client_id=$$"
|
||||
|
@ -64,7 +64,7 @@ _powerline_set_prompt() {
|
|||
local jobnum="$(jobs -p|wc -l)"
|
||||
PS1="$(_powerline_prompt aboveleft $last_exit_code $jobnum)"
|
||||
if test -n "$POWERLINE_SHELL_CONTINUATION$POWERLINE_BASH_CONTINUATION" ; then
|
||||
PS2="$(_powerline_local_prompt left -rbash_prompt $last_exit_code $jobnum continuation)"
|
||||
PS2="$(_powerline_local_prompt left -r.bash $last_exit_code $jobnum continuation)"
|
||||
fi
|
||||
if test -n "$POWERLINE_SHELL_SELECT$POWERLINE_BASH_SELECT" ; then
|
||||
PS3="$(_powerline_local_prompt left '' $last_exit_code $jobnum select)"
|
||||
|
@ -79,7 +79,7 @@ _powerline_setup_prompt() {
|
|||
fi
|
||||
test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" ||
|
||||
PROMPT_COMMAND=$'_powerline_set_prompt\n'"${PROMPT_COMMAND}"
|
||||
PS2="$(_powerline_local_prompt left -rbash_prompt 0 0 continuation)"
|
||||
PS2="$(_powerline_local_prompt left -r.bash 0 0 continuation)"
|
||||
PS3="$(_powerline_local_prompt left '' 0 0 select)"
|
||||
}
|
||||
|
||||
|
|
|
@ -122,8 +122,8 @@ _powerline_tmux_set_columns() {
|
|||
|
||||
_powerline_set_renderer_arg() {
|
||||
case "$1" in
|
||||
bb|ash) _POWERLINE_RENDERER_ARG="-rbash_prompt" ;;
|
||||
mksh|ksh) _POWERLINE_RENDERER_ARG="-rksh_prompt" ;;
|
||||
bb|ash) _POWERLINE_RENDERER_ARG="-r .bash" ;;
|
||||
mksh|ksh) _POWERLINE_RENDERER_ARG="-r .ksh" ;;
|
||||
bash|dash) _POWERLINE_RENDERER_ARG= ;;
|
||||
esac
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ if ( { $POWERLINE_CONFIG shell --shell=tcsh uses prompt } ) then
|
|||
alias _powerline_above '$POWERLINE_COMMAND shell above --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS'
|
||||
endif
|
||||
|
||||
alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r tcsh_prompt --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"'
|
||||
alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r tcsh_prompt --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS` "'
|
||||
alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r .tcsh --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"'
|
||||
alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r .tcsh --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS` "'
|
||||
alias _powerline_set_columns 'set POWERLINE_COLUMNS=`stty size|cut -d" " -f2` ; set POWERLINE_COLUMNS=`expr $POWERLINE_COLUMNS - 2`'
|
||||
|
||||
alias precmd 'set POWERLINE_STATUS=$? ; '"`alias precmd`"' ; _powerline_set_columns ; _powerline_above ; _powerline_set_prompt ; _powerline_set_rprompt'
|
||||
|
|
|
@ -26,7 +26,7 @@ def get_var_config(var):
|
|||
class Args(object):
|
||||
__slots__ = ('last_pipe_status', 'last_exit_code')
|
||||
ext = ['shell']
|
||||
renderer_module = 'zsh_prompt'
|
||||
renderer_module = '.zsh'
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
|
|
|
@ -129,7 +129,7 @@ _powerline_setup_prompt() {
|
|||
POWERLINE_COMMAND=( "$($POWERLINE_CONFIG shell command)" )
|
||||
fi
|
||||
|
||||
local add_args='-r zsh_prompt'
|
||||
local add_args='-r .zsh'
|
||||
add_args+=' --last_exit_code=$?'
|
||||
add_args+=' --last_pipe_status="$pipestatus"'
|
||||
add_args+=' --renderer_arg="client_id=$$"'
|
||||
|
|
|
@ -26,7 +26,7 @@ class IpythonPowerline(Powerline):
|
|||
def __init__(self, is_prompt, old_widths):
|
||||
super(IpythonPowerline, self).__init__(
|
||||
'ipython',
|
||||
renderer_module=('ipython_prompt' if is_prompt else 'ipython'),
|
||||
renderer_module=('.prompt' if is_prompt else None),
|
||||
use_daemon_threads=True
|
||||
)
|
||||
self.old_widths = old_widths
|
||||
|
|
|
@ -432,7 +432,7 @@ def check_matcher_func(ext, match_name, data, context, echoerr):
|
|||
match_function = match_name
|
||||
with WithPath(import_paths):
|
||||
try:
|
||||
func = getattr(__import__(match_module, fromlist=[match_function]), unicode(match_function))
|
||||
func = getattr(__import__(str(match_module), fromlist=[str(match_function)]), str(match_function))
|
||||
except ImportError:
|
||||
echoerr(context='Error while loading matcher functions',
|
||||
problem='failed to load module {0}'.format(match_module),
|
||||
|
@ -823,7 +823,7 @@ def check_key_compatibility(segment, data, context, echoerr):
|
|||
def check_segment_module(module, data, context, echoerr):
|
||||
with WithPath(data['import_paths']):
|
||||
try:
|
||||
__import__(unicode(module))
|
||||
__import__(str(module))
|
||||
except ImportError as e:
|
||||
if echoerr.logger.level >= logging.DEBUG:
|
||||
echoerr.logger.exception(e)
|
||||
|
@ -875,7 +875,7 @@ def import_segment(name, data, context, echoerr, module=None):
|
|||
|
||||
with WithPath(data['import_paths']):
|
||||
try:
|
||||
func = getattr(__import__(unicode(module), fromlist=[unicode(name)]), unicode(name))
|
||||
func = getattr(__import__(str(module), fromlist=[str(name)]), str(name))
|
||||
except ImportError:
|
||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
||||
problem='failed to import module {0}'.format(module),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from powerline.renderers.zsh_prompt import ZshPromptRenderer
|
||||
from powerline.renderers.shell.zsh import ZshPromptRenderer
|
||||
|
||||
|
||||
class TcshPromptRenderer(ZshPromptRenderer):
|
|
@ -50,7 +50,7 @@ def get_argparser(parser=None, *args, **kwargs):
|
|||
p.add_argument('ext', nargs=1, help='Extension: application for which powerline command is launched (usually `shell\' or `tmux\')')
|
||||
p.add_argument('side', nargs='?', choices=('left', 'right', 'above', 'aboveleft'), help='Side: `left\' and `right\' represent left and right side respectively, `above\' emits lines that are supposed to be printed just above the prompt and `aboveleft\' is like concatenating `above\' with `left\' with the exception that only one Python instance is used in this case.')
|
||||
p.add_argument('-r', '--renderer_module', metavar='MODULE', type=str,
|
||||
help='Renderer module. Usually something like `bash_prompt\' or `zsh_prompt\', is supposed to be set only in shell-specific bindings file.')
|
||||
help='Renderer module. Usually something like `.bash\' or `.zsh\', is supposed to be set only in shell-specific bindings file.')
|
||||
p.add_argument('-w', '--width', type=int, help='Maximum prompt with. Triggers truncation of some segments')
|
||||
p.add_argument('--last_exit_code', metavar='INT', type=int, help='Last exit code')
|
||||
p.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()], help='Like above, but is supposed to contain space-separated array of statuses, representing exit statuses of commands in one pipe.')
|
||||
|
|
|
@ -42,7 +42,7 @@ class TestParser(TestCase):
|
|||
(['shell', '--config_path'], 'expected one argument'),
|
||||
(['shell', '--renderer_arg'], 'expected one argument'),
|
||||
(['shell', '--jobnum'], 'expected one argument'),
|
||||
(['-r', 'zsh_prompt'], 'too few arguments|the following arguments are required: ext'),
|
||||
(['-r', '.zsh'], 'too few arguments|the following arguments are required: ext'),
|
||||
(['shell', '--last_exit_code', 'i'], 'invalid int value'),
|
||||
(['shell', '--last_pipe_status', '1 i'], 'invalid <lambda> value'),
|
||||
]:
|
||||
|
@ -57,12 +57,12 @@ class TestParser(TestCase):
|
|||
err = StrIO()
|
||||
with replace_attr(sys, 'stdout', out, 'stderr', err):
|
||||
for argv, expargs in [
|
||||
(['shell'], {'ext': ['shell']}),
|
||||
(['shell', '-r', 'zsh_prompt'], {'ext': ['shell'], 'renderer_module': 'zsh_prompt'}),
|
||||
(['shell'], {'ext': ['shell']}),
|
||||
(['shell', '-r', '.zsh'], {'ext': ['shell'], 'renderer_module': '.zsh'}),
|
||||
([
|
||||
'shell',
|
||||
'left',
|
||||
'-r', 'zsh_prompt',
|
||||
'-r', '.zsh',
|
||||
'--last_exit_code', '10',
|
||||
'--last_pipe_status', '10 20 30',
|
||||
'--jobnum=10',
|
||||
|
@ -76,7 +76,7 @@ class TestParser(TestCase):
|
|||
], {
|
||||
'ext': ['shell'],
|
||||
'side': 'left',
|
||||
'renderer_module': 'zsh_prompt',
|
||||
'renderer_module': '.zsh',
|
||||
'last_exit_code': 10,
|
||||
'last_pipe_status': [10, 20, 30],
|
||||
'jobnum': 10,
|
||||
|
|
|
@ -86,7 +86,7 @@ class TestConfig(TestCase):
|
|||
|
||||
def test_zsh(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
args = Args(last_pipe_status=[1, 0], jobnum=0, ext=['shell'], renderer_module='zsh_prompt')
|
||||
args = Args(last_pipe_status=[1, 0], jobnum=0, ext=['shell'], renderer_module='.zsh')
|
||||
segment_info = {'args': args}
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
powerline.render(segment_info=segment_info)
|
||||
|
@ -102,7 +102,7 @@ class TestConfig(TestCase):
|
|||
|
||||
def test_bash(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='bash_prompt', config={'ext': {'shell': {'theme': 'default_leftonly'}}})
|
||||
args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='.bash', config={'ext': {'shell': {'theme': 'default_leftonly'}}})
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
powerline.render(segment_info={'args': args})
|
||||
with ShellPowerline(args, run_once=False) as powerline:
|
||||
|
|
Loading…
Reference in New Issue