From 4a3798b43b494e894429b524ab09ba784900c157 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 1 Mar 2015 17:23:07 +0300 Subject: [PATCH] Fix tcsh renderer: end prompt with a sequence that is not dropped --- powerline/bindings/tcsh/powerline.tcsh | 2 +- powerline/renderers/shell/tcsh.py | 15 ++++++++++++ tests/test_shells/postproc.py | 2 +- tests/test_shells/tcsh.ok | 34 +++++++++++++------------- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh index 502e95e3..bba34280 100644 --- a/powerline/bindings/tcsh/powerline.tcsh +++ b/powerline/bindings/tcsh/powerline.tcsh @@ -43,7 +43,7 @@ if ( { $POWERLINE_CONFIG_COMMAND shell --shell=tcsh uses prompt } ) then endif alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND:q $POWERLINE_COMMAND_ARGS shell left -r .tcsh --renderer-arg=client_id=$$ --last-exit-code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"' - alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND:q $POWERLINE_COMMAND_ARGS shell right -r .tcsh --renderer-arg=client_id=$$ --last-exit-code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS` "' + alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND:q $POWERLINE_COMMAND_ARGS 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' diff --git a/powerline/renderers/shell/tcsh.py b/powerline/renderers/shell/tcsh.py index d0d1d277..bf0697d1 100644 --- a/powerline/renderers/shell/tcsh.py +++ b/powerline/renderers/shell/tcsh.py @@ -12,5 +12,20 @@ class TcshPromptRenderer(ZshPromptRenderer): character_translations[ord('^')] = '\\^' character_translations[ord('!')] = '\\!' + def do_render(self, **kwargs): + ret = super(TcshPromptRenderer, self).do_render(**kwargs) + nbsp = self.character_translations.get(ord(' '), ' ') + end = self.hlstyle() + assert not ret or ret.endswith(end) + if ret.endswith(nbsp + end): + # Exchange nbsp and highlight end because tcsh removes trailing + # %{%} part of the prompt for whatever reason + ret = ret[:-(len(nbsp) + len(end))] + end + nbsp + else: + # We *must* end prompt with non-%{%} sequence for the reasons + # explained above. So add nbsp if it is not already there. + ret += nbsp + return ret + renderer = TcshPromptRenderer diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index 0646684e..0e7f0923 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -70,7 +70,7 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: try: start = line.index('\033[0;') end = line.index(' ', start) - line = line[start:end] + '\033[0m\n' + line = line[start:end] + '\n' except ValueError: line = '' elif shell == 'mksh': diff --git a/tests/test_shells/tcsh.ok b/tests/test_shells/tcsh.ok index 03c2527c..fd5d5914 100644 --- a/tests/test_shells/tcsh.ok +++ b/tests/test_shells/tcsh.ok @@ -1,17 +1,17 @@ -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git   -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd   -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1   -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`   -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!» 