mirror of
https://github.com/powerline/powerline.git
synced 2025-07-26 23:35:04 +02:00
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}``).
|
colorschemes, render module (``powerline.renders.{ext}``).
|
||||||
:param str renderer_module:
|
:param str renderer_module:
|
||||||
Overrides renderer module (defaults to ``ext``). Should be the name of
|
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
|
If this parameter contains a dot, ``powerline.renderers.`` is not
|
||||||
prepended. There is also a special case for renderers defined in
|
prepended. There is also a special case for renderers defined in
|
||||||
toplevel modules: ``foo.`` (note: dot at the end) tries to get renderer
|
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 ``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:
|
:param bool run_once:
|
||||||
Determines whether .renderer.render() method will be run only once
|
Determines whether .renderer.render() method will be run only once
|
||||||
during python session.
|
during python session.
|
||||||
@ -307,15 +309,20 @@ class Powerline(object):
|
|||||||
shutdown_event=None,
|
shutdown_event=None,
|
||||||
config_loader=None):
|
config_loader=None):
|
||||||
self.ext = ext
|
self.ext = ext
|
||||||
self.renderer_module = renderer_module or ext
|
|
||||||
self.run_once = run_once
|
self.run_once = run_once
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.use_daemon_threads = use_daemon_threads
|
self.use_daemon_threads = use_daemon_threads
|
||||||
|
|
||||||
if '.' not in self.renderer_module:
|
if not renderer_module:
|
||||||
self.renderer_module = 'powerline.renderers.' + self.renderer_module
|
self.renderer_module = 'powerline.renderers.' + ext
|
||||||
elif self.renderer_module[-1] == '.':
|
elif '.' not in renderer_module:
|
||||||
self.renderer_module = self.renderer_module[:-1]
|
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)
|
self.find_config_files = generate_config_finder(self.get_config_paths)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ _powerline_prompt() {
|
|||||||
# Arguments: side, last_exit_code, jobnum
|
# Arguments: side, last_exit_code, jobnum
|
||||||
$POWERLINE_COMMAND shell $1 \
|
$POWERLINE_COMMAND shell $1 \
|
||||||
--width="${COLUMNS:-$(_powerline_columns_fallback)}" \
|
--width="${COLUMNS:-$(_powerline_columns_fallback)}" \
|
||||||
-r bash_prompt \
|
-r.bash \
|
||||||
--last_exit_code=$2 \
|
--last_exit_code=$2 \
|
||||||
--jobnum=$3 \
|
--jobnum=$3 \
|
||||||
--renderer_arg="client_id=$$"
|
--renderer_arg="client_id=$$"
|
||||||
@ -64,7 +64,7 @@ _powerline_set_prompt() {
|
|||||||
local jobnum="$(jobs -p|wc -l)"
|
local jobnum="$(jobs -p|wc -l)"
|
||||||
PS1="$(_powerline_prompt aboveleft $last_exit_code $jobnum)"
|
PS1="$(_powerline_prompt aboveleft $last_exit_code $jobnum)"
|
||||||
if test -n "$POWERLINE_SHELL_CONTINUATION$POWERLINE_BASH_CONTINUATION" ; then
|
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
|
fi
|
||||||
if test -n "$POWERLINE_SHELL_SELECT$POWERLINE_BASH_SELECT" ; then
|
if test -n "$POWERLINE_SHELL_SELECT$POWERLINE_BASH_SELECT" ; then
|
||||||
PS3="$(_powerline_local_prompt left '' $last_exit_code $jobnum select)"
|
PS3="$(_powerline_local_prompt left '' $last_exit_code $jobnum select)"
|
||||||
@ -79,7 +79,7 @@ _powerline_setup_prompt() {
|
|||||||
fi
|
fi
|
||||||
test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" ||
|
test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" ||
|
||||||
PROMPT_COMMAND=$'_powerline_set_prompt\n'"${PROMPT_COMMAND}"
|
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)"
|
PS3="$(_powerline_local_prompt left '' 0 0 select)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,8 +122,8 @@ _powerline_tmux_set_columns() {
|
|||||||
|
|
||||||
_powerline_set_renderer_arg() {
|
_powerline_set_renderer_arg() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
bb|ash) _POWERLINE_RENDERER_ARG="-rbash_prompt" ;;
|
bb|ash) _POWERLINE_RENDERER_ARG="-r .bash" ;;
|
||||||
mksh|ksh) _POWERLINE_RENDERER_ARG="-rksh_prompt" ;;
|
mksh|ksh) _POWERLINE_RENDERER_ARG="-r .ksh" ;;
|
||||||
bash|dash) _POWERLINE_RENDERER_ARG= ;;
|
bash|dash) _POWERLINE_RENDERER_ARG= ;;
|
||||||
esac
|
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'
|
alias _powerline_above '$POWERLINE_COMMAND shell above --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS'
|
||||||
endif
|
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_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_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 --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 _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'
|
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):
|
class Args(object):
|
||||||
__slots__ = ('last_pipe_status', 'last_exit_code')
|
__slots__ = ('last_pipe_status', 'last_exit_code')
|
||||||
ext = ['shell']
|
ext = ['shell']
|
||||||
renderer_module = 'zsh_prompt'
|
renderer_module = '.zsh'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self):
|
def config(self):
|
||||||
|
@ -129,7 +129,7 @@ _powerline_setup_prompt() {
|
|||||||
POWERLINE_COMMAND=( "$($POWERLINE_CONFIG shell command)" )
|
POWERLINE_COMMAND=( "$($POWERLINE_CONFIG shell command)" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local add_args='-r zsh_prompt'
|
local add_args='-r .zsh'
|
||||||
add_args+=' --last_exit_code=$?'
|
add_args+=' --last_exit_code=$?'
|
||||||
add_args+=' --last_pipe_status="$pipestatus"'
|
add_args+=' --last_pipe_status="$pipestatus"'
|
||||||
add_args+=' --renderer_arg="client_id=$$"'
|
add_args+=' --renderer_arg="client_id=$$"'
|
||||||
|
@ -26,7 +26,7 @@ class IpythonPowerline(Powerline):
|
|||||||
def __init__(self, is_prompt, old_widths):
|
def __init__(self, is_prompt, old_widths):
|
||||||
super(IpythonPowerline, self).__init__(
|
super(IpythonPowerline, self).__init__(
|
||||||
'ipython',
|
'ipython',
|
||||||
renderer_module=('ipython_prompt' if is_prompt else 'ipython'),
|
renderer_module=('.prompt' if is_prompt else None),
|
||||||
use_daemon_threads=True
|
use_daemon_threads=True
|
||||||
)
|
)
|
||||||
self.old_widths = old_widths
|
self.old_widths = old_widths
|
||||||
|
@ -432,7 +432,7 @@ def check_matcher_func(ext, match_name, data, context, echoerr):
|
|||||||
match_function = match_name
|
match_function = match_name
|
||||||
with WithPath(import_paths):
|
with WithPath(import_paths):
|
||||||
try:
|
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:
|
except ImportError:
|
||||||
echoerr(context='Error while loading matcher functions',
|
echoerr(context='Error while loading matcher functions',
|
||||||
problem='failed to load module {0}'.format(match_module),
|
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):
|
def check_segment_module(module, data, context, echoerr):
|
||||||
with WithPath(data['import_paths']):
|
with WithPath(data['import_paths']):
|
||||||
try:
|
try:
|
||||||
__import__(unicode(module))
|
__import__(str(module))
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
if echoerr.logger.level >= logging.DEBUG:
|
if echoerr.logger.level >= logging.DEBUG:
|
||||||
echoerr.logger.exception(e)
|
echoerr.logger.exception(e)
|
||||||
@ -875,7 +875,7 @@ def import_segment(name, data, context, echoerr, module=None):
|
|||||||
|
|
||||||
with WithPath(data['import_paths']):
|
with WithPath(data['import_paths']):
|
||||||
try:
|
try:
|
||||||
func = getattr(__import__(unicode(module), fromlist=[unicode(name)]), unicode(name))
|
func = getattr(__import__(str(module), fromlist=[str(name)]), str(name))
|
||||||
except ImportError:
|
except ImportError:
|
||||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
||||||
problem='failed to import module {0}'.format(module),
|
problem='failed to import module {0}'.format(module),
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
from powerline.renderers.zsh_prompt import ZshPromptRenderer
|
from powerline.renderers.shell.zsh import ZshPromptRenderer
|
||||||
|
|
||||||
|
|
||||||
class TcshPromptRenderer(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('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('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,
|
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('-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_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.')
|
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', '--config_path'], 'expected one argument'),
|
||||||
(['shell', '--renderer_arg'], 'expected one argument'),
|
(['shell', '--renderer_arg'], 'expected one argument'),
|
||||||
(['shell', '--jobnum'], '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_exit_code', 'i'], 'invalid int value'),
|
||||||
(['shell', '--last_pipe_status', '1 i'], 'invalid <lambda> value'),
|
(['shell', '--last_pipe_status', '1 i'], 'invalid <lambda> value'),
|
||||||
]:
|
]:
|
||||||
@ -57,12 +57,12 @@ class TestParser(TestCase):
|
|||||||
err = StrIO()
|
err = StrIO()
|
||||||
with replace_attr(sys, 'stdout', out, 'stderr', err):
|
with replace_attr(sys, 'stdout', out, 'stderr', err):
|
||||||
for argv, expargs in [
|
for argv, expargs in [
|
||||||
(['shell'], {'ext': ['shell']}),
|
(['shell'], {'ext': ['shell']}),
|
||||||
(['shell', '-r', 'zsh_prompt'], {'ext': ['shell'], 'renderer_module': 'zsh_prompt'}),
|
(['shell', '-r', '.zsh'], {'ext': ['shell'], 'renderer_module': '.zsh'}),
|
||||||
([
|
([
|
||||||
'shell',
|
'shell',
|
||||||
'left',
|
'left',
|
||||||
'-r', 'zsh_prompt',
|
'-r', '.zsh',
|
||||||
'--last_exit_code', '10',
|
'--last_exit_code', '10',
|
||||||
'--last_pipe_status', '10 20 30',
|
'--last_pipe_status', '10 20 30',
|
||||||
'--jobnum=10',
|
'--jobnum=10',
|
||||||
@ -76,7 +76,7 @@ class TestParser(TestCase):
|
|||||||
], {
|
], {
|
||||||
'ext': ['shell'],
|
'ext': ['shell'],
|
||||||
'side': 'left',
|
'side': 'left',
|
||||||
'renderer_module': 'zsh_prompt',
|
'renderer_module': '.zsh',
|
||||||
'last_exit_code': 10,
|
'last_exit_code': 10,
|
||||||
'last_pipe_status': [10, 20, 30],
|
'last_pipe_status': [10, 20, 30],
|
||||||
'jobnum': 10,
|
'jobnum': 10,
|
||||||
|
@ -86,7 +86,7 @@ class TestConfig(TestCase):
|
|||||||
|
|
||||||
def test_zsh(self):
|
def test_zsh(self):
|
||||||
from powerline.shell import ShellPowerline
|
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}
|
segment_info = {'args': args}
|
||||||
with ShellPowerline(args, run_once=False) as powerline:
|
with ShellPowerline(args, run_once=False) as powerline:
|
||||||
powerline.render(segment_info=segment_info)
|
powerline.render(segment_info=segment_info)
|
||||||
@ -102,7 +102,7 @@ class TestConfig(TestCase):
|
|||||||
|
|
||||||
def test_bash(self):
|
def test_bash(self):
|
||||||
from powerline.shell import ShellPowerline
|
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:
|
with ShellPowerline(args, run_once=False) as powerline:
|
||||||
powerline.render(segment_info={'args': args})
|
powerline.render(segment_info={'args': args})
|
||||||
with ShellPowerline(args, run_once=False) as powerline:
|
with ShellPowerline(args, run_once=False) as powerline:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user