Transform pane_id to unicode before using

Tmux-2.1 appears not to output leading `%` when using `tmux display -p '#D'`.
This change changes type of the `pane_id` argument: leading `%` turns it into
a literal string, number in front makes it be parsed as a JSON number.

Fixes #1470
This commit is contained in:
Foo 2015-10-19 21:56:46 +03:00
parent 3b3d8f0188
commit c4b4097b0c
3 changed files with 20 additions and 3 deletions

View File

@ -467,7 +467,8 @@ Shell
``client_id`` ``client_id``
Identifier unique to one shell instance. Is used to record instance Identifier unique to one shell instance. Is used to record instance
state by powerline daemon. state by powerline daemon. In tmux this is the same as :ref:`pane_id
<dev-seginfo-shell-renarg-pane_id>`.
It is not guaranteed that existing client ID will not be retaken It is not guaranteed that existing client ID will not be retaken
when old shell with this ID quit: usually process PID is used as when old shell with this ID quit: usually process PID is used as
@ -481,6 +482,14 @@ Shell
Local theme that will be used by shell. One should not rely on the Local theme that will be used by shell. One should not rely on the
existence of this key. existence of this key.
.. _dev-seginfo-shell-renarg-pane_id:
``pane_id``
Identifier unique to each tmux pane. Is always an integer, optional.
Obtained by using ``tmux display -p '#D'``, then all leading spaces
and per cent signs are stripped and the result is converted into an
integer.
Other keys, if any, are specific to segments. Other keys, if any, are specific to segments.
Ipython Ipython

View File

@ -10,7 +10,7 @@ from itertools import chain
from powerline.lib.overrides import parsedotval, parse_override_var from powerline.lib.overrides import parsedotval, parse_override_var
from powerline.lib.dict import mergeargs from powerline.lib.dict import mergeargs
from powerline.lib.encoding import get_preferred_arguments_encoding from powerline.lib.encoding import get_preferred_arguments_encoding
from powerline.lib.unicode import u from powerline.lib.unicode import u, unicode
if sys.version_info < (3,): if sys.version_info < (3,):
@ -49,6 +49,14 @@ def finish_args(environ, args):
)) ))
if args.renderer_arg: if args.renderer_arg:
args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True) args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True)
if 'pane_id' in args.renderer_arg:
if isinstance(args.renderer_arg['pane_id'], (bytes, unicode)):
try:
args.renderer_arg['pane_id'] = int(args.renderer_arg['pane_id'].lstrip(' %'))
except ValueError:
pass
if 'client_id' not in args.renderer_arg:
args.renderer_arg['client_id'] = args.renderer_arg['pane_id']
args.config_path = ( args.config_path = (
[path for path in environ.get('POWERLINE_CONFIG_PATHS', '').split(':') if path] [path for path in environ.get('POWERLINE_CONFIG_PATHS', '').split(':') if path]
+ (args.config_path or []) + (args.config_path or [])

View File

@ -63,7 +63,7 @@ class TmuxRenderer(Renderer):
if segment_info: if segment_info:
r.update(segment_info) r.update(segment_info)
if 'pane_id' in r: if 'pane_id' in r:
varname = 'TMUX_PWD_' + r['pane_id'].lstrip('% ') varname = 'TMUX_PWD_' + str(r['pane_id'])
if varname in r['environ']: if varname in r['environ']:
r['getcwd'] = lambda: r['environ'][varname] r['getcwd'] = lambda: r['environ'][varname]
r['mode'] = mode r['mode'] = mode