Merge pull request #1284 from ZyX-I/update-zpython

Update zpython bindings according to new zpython changes
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2015-01-25 02:23:20 +03:00
commit 9dfd40a6a7
1 changed files with 19 additions and 8 deletions

View File

@ -101,7 +101,20 @@ class Environment(object):
return False
environ = getattr(zsh, 'environ', Environment())
if hasattr(getattr(zsh, 'environ', None), '__contains__'):
environ = zsh.environ
else:
environ = Environment()
if hasattr(zsh, 'expand') and zsh.expand('${:-}') == '':
zsh_expand = zsh.expand
else:
def zsh_expand(s):
zsh.eval('_POWERLINE_REPLY="' + s + '"')
ret = zsh.getvalue('_POWERLINE_REPLY')
zsh.setvalue('_POWERLINE_REPLY', None)
return ret
class ZshPowerline(ShellPowerline):
@ -135,8 +148,8 @@ class Prompt(object):
self.theme = theme
def __str__(self):
zsh.eval('_POWERLINE_PARSER_STATE="${(%):-%_}"')
zsh.eval('_POWERLINE_SHORTENED_PATH="${(%):-%~}"')
parser_state = u(zsh_expand('${(%):-%_}'))
shortened_path = u(zsh_expand('${(%):-%~}'))
try:
mode = u(zsh.getvalue('_POWERLINE_MODE'))
except IndexError:
@ -150,13 +163,11 @@ class Prompt(object):
'environ': environ,
'client_id': 1,
'local_theme': self.theme,
'parser_state': zsh.getvalue('_POWERLINE_PARSER_STATE'),
'shortened_path': zsh.getvalue('_POWERLINE_SHORTENED_PATH'),
'parser_state': parser_state,
'shortened_path': shortened_path,
'mode': mode,
'default_mode': default_mode,
}
zsh.setvalue('_POWERLINE_PARSER_STATE', None)
zsh.setvalue('_POWERLINE_SHORTENED_PATH', None)
try:
zle_rprompt_indent = zsh.getvalue('ZLE_RPROMPT_INDENT')
except IndexError:
@ -194,7 +205,7 @@ def set_prompt(powerline, psvar, side, theme, above=False):
savedps = None
zpyvar = 'ZPYTHON_POWERLINE_' + psvar
prompt = Prompt(powerline, side, theme, psvar, savedps, above)
zsh.eval('unset ' + zpyvar)
zsh.setvalue(zpyvar, None)
zsh.set_special_string(zpyvar, prompt)
zsh.setvalue(psvar, '${' + zpyvar + '}')
return ref(prompt)