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/bindings/zsh/__init__.py b/powerline/bindings/zsh/__init__.py index cbe5f957..1f93d272 100644 --- a/powerline/bindings/zsh/__init__.py +++ b/powerline/bindings/zsh/__init__.py @@ -178,7 +178,8 @@ class Prompt(object): width=zsh.columns() - zle_rprompt_indent, segment_info=segment_info, ): - r += line + '\n' + if line: + r += line + '\n' r += self.powerline.render( width=zsh.columns(), side=self.side, diff --git a/powerline/commands/main.py b/powerline/commands/main.py index 8c41b476..7a4751dc 100644 --- a/powerline/commands/main.py +++ b/powerline/commands/main.py @@ -159,7 +159,8 @@ def write_output(args, powerline, segment_info, write): segment_info=segment_info, mode=segment_info.get('mode', None), ): - write(line + '\n') + if line: + write(line + '\n') args.side = args.side[len('above'):] if args.side: diff --git a/powerline/renderer.py b/powerline/renderer.py index c03c42e8..13c7a04f 100644 --- a/powerline/renderer.py +++ b/powerline/renderer.py @@ -378,7 +378,9 @@ class Renderer(object): elif output_width: current_width = self._render_length(theme, segments, divider_widths) - rendered_highlighted = ''.join([segment['_rendered_hl'] for segment in self._render_segments(theme, segments)]) + self.hlstyle() + rendered_highlighted = ''.join([segment['_rendered_hl'] for segment in self._render_segments(theme, segments)]) + if rendered_highlighted: + rendered_highlighted += self.hlstyle() return construct_returned_value(rendered_highlighted, segments, current_width, output_raw, output_width) 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/bash.daemon.ok b/tests/test_shells/bash.daemon.ok index e4535b1e..4f25eb13 100644 --- a/tests/test_shells/bash.daemon.ok +++ b/tests/test_shells/bash.daemon.ok @@ -26,5 +26,16 @@ def   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)'   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`'   BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»' +  BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.segments.above "$ABOVE_LEFT" +  BRANCH  ⋯  shell  3rd  «Unicode!»  export DISPLAYED_ENV_VAR=foo + foo   +  BRANCH  ⋯  shell  3rd  «Unicode!»  unset DISPLAYED_ENV_VAR +  BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.segments.above "$ABOVE_FULL" +                                                                                                                                                                                                                                                                                                             +  BRANCH  ⋯  shell  3rd  «Unicode!»  export DISPLAYED_ENV_VAR=foo +                                                                                                                                                                                                                                                                                                       foo  +  BRANCH  ⋯  shell  3rd  «Unicode!»  unset DISPLAYED_ENV_VAR +                                                                                                                                                                                                                                                                                                             +  BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.segments.above   BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.dividers.left.hard \$ABC   BRANCH $ABC⋯  shell  3rd  «Unicode!» $ABCfalse diff --git a/tests/test_shells/bash.nodaemon.ok b/tests/test_shells/bash.nodaemon.ok index 56dd1fc5..9bfc9cfe 100644 --- a/tests/test_shells/bash.nodaemon.ok +++ b/tests/test_shells/bash.nodaemon.ok @@ -26,5 +26,16 @@ def   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)'   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`'   BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»' +  BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.segments.above "$ABOVE_LEFT" +  BRANCH  ⋯  shell  3rd  «Unicode!»  export DISPLAYED_ENV_VAR=foo + foo   +  BRANCH  ⋯  shell  3rd  «Unicode!»  unset DISPLAYED_ENV_VAR +  BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.segments.above "$ABOVE_FULL" +                                                                                                                                                                                                                                                                                                             +  BRANCH  ⋯  shell  3rd  «Unicode!»  export DISPLAYED_ENV_VAR=foo +                                                                                                                                                                                                                                                                                                       foo  +  BRANCH  ⋯  shell  3rd  «Unicode!»  unset DISPLAYED_ENV_VAR +                                                                                                                                                                                                                                                                                                             +  BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.segments.above   BRANCH  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.dividers.left.hard \$ABC   BRANCH $ABC⋯  shell  3rd  «Unicode!» $ABCfalse diff --git a/tests/test_shells/fish.ok b/tests/test_shells/fish.ok index c69abfc5..e1044450 100644 --- a/tests/test_shells/fish.ok +++ b/tests/test_shells/fish.ok @@ -19,6 +19,22 @@    BRANCH     BRANCH     BRANCH  + USER  ⋯  shell  3rd  «Unicode!»   +   BRANCH  +   BRANCH  +   BRANCH  + foo   + USER  ⋯  shell  3rd  «Unicode!»   +   BRANCH  +   BRANCH  +   BRANCH  +                                                                                                                                                                                                                                                                                                            +                                                                                                                                                                                                                                                                                                      foo  +                                                                                                                                                                                                                                                                                                            + USER  ⋯  shell  3rd  «Unicode!»   +   BRANCH  +   BRANCH  +   BRANCH   INSERT  USER  ⋯  shell  3rd  «Unicode!»      BRANCH   DEFAULT  USER  ⋯  shell  3rd  «Unicode!»   diff --git a/tests/test_shells/input.bash b/tests/test_shells/input.bash index 0a1c0165..bbd8d0bb 100644 --- a/tests/test_shells/input.bash +++ b/tests/test_shells/input.bash @@ -5,6 +5,30 @@ set_theme() { export POWERLINE_CONFIG_OVERRIDES="ext.shell.theme=$1" } set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false +ABOVE_LEFT='[{ + "left": [ + { + "function": "powerline.segments.common.env.environment", + "args": {"variable": "DISPLAYED_ENV_VAR"} + } + ] +}]' +ABOVE_FULL='[{ + "left": [ + { + "type": "string", + "name": "background", + "draw_hard_divider": false, + "width": "auto" + } + ], + "right": [ + { + "function": "powerline.segments.common.env.environment", + "args": {"variable": "DISPLAYED_ENV_VAR"} + } + ] +}]' set_theme default_leftonly export VIRTUAL_ENV= source powerline/bindings/bash/powerline.sh @@ -31,6 +55,13 @@ cd ../'(echo)' cd ../'$(echo)' cd ../'`echo`' cd ../'«Unicode!»' +set_theme_option default_leftonly.segments.above "$ABOVE_LEFT" +export DISPLAYED_ENV_VAR=foo +unset DISPLAYED_ENV_VAR +set_theme_option default_leftonly.segments.above "$ABOVE_FULL" +export DISPLAYED_ENV_VAR=foo +unset DISPLAYED_ENV_VAR +set_theme_option default_leftonly.segments.above set_theme_option default_leftonly.dividers.left.hard \$ABC false true is the last line diff --git a/tests/test_shells/input.fish b/tests/test_shells/input.fish index 968248f1..4be37c31 100644 --- a/tests/test_shells/input.fish +++ b/tests/test_shells/input.fish @@ -4,6 +4,31 @@ end function set_theme set -g -x POWERLINE_CONFIG_OVERRIDES "ext.shell.theme=$argv" end +set -g -x POWERLINE_ +set -g ABOVE_LEFT '[{ + "left": [ + { + "function": "powerline.segments.common.env.environment", + "args": {"variable": "DISPLAYED_ENV_VAR"} + } + ] +}]' +set -g ABOVE_FULL '[{ + "left": [ + { + "type": "string", + "name": "background", + "draw_hard_divider": false, + "width": "auto" + } + ], + "right": [ + { + "function": "powerline.segments.common.env.environment", + "args": {"variable": "DISPLAYED_ENV_VAR"} + } + ] +}]' set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false set_theme default_leftonly set fish_function_path "$PWD/powerline/bindings/fish" $fish_function_path @@ -30,6 +55,13 @@ cd ../'$(echo)' cd ../'`echo`' cd ../'«Unicode!»' set_theme default +set_theme_option default.segments.above "$ABOVE_LEFT" +set -g -x DISPLAYED_ENV_VAR foo +set -g -x -e DISPLAYED_ENV_VAR +set_theme_option default.segments.above "$ABOVE_FULL" +set -g -x DISPLAYED_ENV_VAR foo +set -g -x -e DISPLAYED_ENV_VAR +set_theme_option default.segments.above '' set -g fish_key_bindings fish_vi_key_bindings ii false diff --git a/tests/test_shells/input.zsh b/tests/test_shells/input.zsh index 7775ba97..ab71ee6c 100644 --- a/tests/test_shells/input.zsh +++ b/tests/test_shells/input.zsh @@ -16,6 +16,30 @@ fi source powerline/bindings/zsh/powerline.zsh set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false set_theme_option default.segment_data.hostname.args.only_if_ssh false +ABOVE_LEFT='[{ + "left": [ + { + "function": "powerline.segments.common.env.environment", + "args": {"variable": "DISPLAYED_ENV_VAR"} + } + ] +}]' +ABOVE_FULL='[{ + "left": [ + { + "type": "string", + "name": "background", + "draw_hard_divider": false, + "width": "auto" + } + ], + "right": [ + { + "function": "powerline.segments.common.env.environment", + "args": {"variable": "DISPLAYED_ENV_VAR"} + } + ] +}]' set_theme default_leftonly export VIRTUAL_ENV= cd tests/shell/3rd @@ -51,6 +75,13 @@ done 1 cd . cd . +set_theme_option default.segments.above "$ABOVE_LEFT" +export DISPLAYED_ENV_VAR=foo +unset DISPLAYED_ENV_VAR +set_theme_option default.segments.above "$ABOVE_FULL" +export DISPLAYED_ENV_VAR=foo +unset DISPLAYED_ENV_VAR +set_theme_option default.segments.above hash -d foo=$PWD:h ; cd . set_theme_option default.dividers.left.hard \$ABC true 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!»   diff --git a/tests/test_shells/zsh.daemon.ok b/tests/test_shells/zsh.daemon.ok index 53ff5b4c..daf415dc 100644 --- a/tests/test_shells/zsh.daemon.ok +++ b/tests/test_shells/zsh.daemon.ok @@ -36,6 +36,17 @@ abc def  INSERT  ⋯  tests  shell  3rd  cd .  INSERT  ⋯  tests  shell  3rd  cd . + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_LEFT" + INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo + foo   + INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_FULL" +                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo +                                                                                                                                                                                                                                                                                                      foo  + INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR +                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above  INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd .  INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC  INSERT $ABC~foo  3rd $ABCtrue diff --git a/tests/test_shells/zsh.nodaemon.ok b/tests/test_shells/zsh.nodaemon.ok index 5883a780..6a813f93 100644 --- a/tests/test_shells/zsh.nodaemon.ok +++ b/tests/test_shells/zsh.nodaemon.ok @@ -36,6 +36,17 @@ abc def  INSERT  ⋯  tests  shell  3rd  cd .  INSERT  ⋯  tests  shell  3rd  cd . + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_LEFT" + INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo + foo   + INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above "$ABOVE_FULL" +                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  export DISPLAYED_ENV_VAR=foo +                                                                                                                                                                                                                                                                                                      foo  + INSERT  ⋯  tests  shell  3rd  unset DISPLAYED_ENV_VAR +                                                                                                                                                                                                                                                                                                            + INSERT  ⋯  tests  shell  3rd  set_theme_option default.segments.above  INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd .  INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC  INSERT $ABC~foo  3rd $ABCtrue