Merge pull request #1327 from ZyX-I/fix-1322

Do not write empty lines above prompt and fix tcsh
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2015-03-01 17:41:51 +03:00
commit 6b0cd3d37c
15 changed files with 195 additions and 22 deletions

View File

@ -178,6 +178,7 @@ class Prompt(object):
width=zsh.columns() - zle_rprompt_indent, width=zsh.columns() - zle_rprompt_indent,
segment_info=segment_info, segment_info=segment_info,
): ):
if line:
r += line + '\n' r += line + '\n'
r += self.powerline.render( r += self.powerline.render(
width=zsh.columns(), width=zsh.columns(),

View File

@ -159,6 +159,7 @@ def write_output(args, powerline, segment_info, write):
segment_info=segment_info, segment_info=segment_info,
mode=segment_info.get('mode', None), mode=segment_info.get('mode', None),
): ):
if line:
write(line + '\n') write(line + '\n')
args.side = args.side[len('above'):] args.side = args.side[len('above'):]

View File

@ -378,7 +378,9 @@ class Renderer(object):
elif output_width: elif output_width:
current_width = self._render_length(theme, segments, divider_widths) 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) return construct_returned_value(rendered_highlighted, segments, current_width, output_raw, output_width)

View File

@ -12,5 +12,20 @@ class TcshPromptRenderer(ZshPromptRenderer):
character_translations[ord('^')] = '\\^' character_translations[ord('^')] = '\\^'
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 renderer = TcshPromptRenderer

View File

@ -26,5 +26,16 @@ def
  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)'   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)'
  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`'   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`'
  BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»'   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  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.dividers.left.hard \$ABC
  BRANCH $ABC⋯  shell  3rd  «Unicode!» $ABCfalse   BRANCH $ABC⋯  shell  3rd  «Unicode!» $ABCfalse

View File

@ -26,5 +26,16 @@ def
  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)'   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)'
  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`'   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`'
  BRANCH  ⋯  shell  3rd  `echo`  cd ../'«Unicode!»'   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  ⋯  shell  3rd  «Unicode!»  set_theme_option default_leftonly.dividers.left.hard \$ABC
  BRANCH $ABC⋯  shell  3rd  «Unicode!» $ABCfalse   BRANCH $ABC⋯  shell  3rd  «Unicode!» $ABCfalse

View File

@ -19,6 +19,22 @@
   BRANCH     BRANCH 
   BRANCH     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!»    INSERT  USER  ⋯  shell  3rd  «Unicode!»  
   BRANCH     BRANCH 
 DEFAULT  USER  ⋯  shell  3rd  «Unicode!»    DEFAULT  USER  ⋯  shell  3rd  «Unicode!»  

View File

@ -5,6 +5,30 @@ set_theme() {
export POWERLINE_CONFIG_OVERRIDES="ext.shell.theme=$1" export POWERLINE_CONFIG_OVERRIDES="ext.shell.theme=$1"
} }
set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false 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 set_theme default_leftonly
export VIRTUAL_ENV= export VIRTUAL_ENV=
source powerline/bindings/bash/powerline.sh source powerline/bindings/bash/powerline.sh
@ -31,6 +55,13 @@ cd ../'(echo)'
cd ../'$(echo)' cd ../'$(echo)'
cd ../'`echo`' cd ../'`echo`'
cd ../'«Unicode!»' 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 set_theme_option default_leftonly.dividers.left.hard \$ABC
false false
true is the last line true is the last line

View File

@ -4,6 +4,31 @@ end
function set_theme function set_theme
set -g -x POWERLINE_CONFIG_OVERRIDES "ext.shell.theme=$argv" set -g -x POWERLINE_CONFIG_OVERRIDES "ext.shell.theme=$argv"
end 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_option default_leftonly.segment_data.hostname.args.only_if_ssh false
set_theme default_leftonly set_theme default_leftonly
set fish_function_path "$PWD/powerline/bindings/fish" $fish_function_path set fish_function_path "$PWD/powerline/bindings/fish" $fish_function_path
@ -30,6 +55,13 @@ cd ../'$(echo)'
cd ../'`echo`' cd ../'`echo`'
cd ../'«Unicode!»' cd ../'«Unicode!»'
set_theme default 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 set -g fish_key_bindings fish_vi_key_bindings
ii ii
false false

View File

@ -16,6 +16,30 @@ fi
source powerline/bindings/zsh/powerline.zsh source powerline/bindings/zsh/powerline.zsh
set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false 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 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 set_theme default_leftonly
export VIRTUAL_ENV= export VIRTUAL_ENV=
cd tests/shell/3rd cd tests/shell/3rd
@ -51,6 +75,13 @@ done
1 1
cd . cd .
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 . hash -d foo=$PWD:h ; cd .
set_theme_option default.dividers.left.hard \$ABC set_theme_option default.dividers.left.hard \$ABC
true true

View File

@ -70,7 +70,7 @@ with codecs.open(fname, 'r', encoding='utf-8') as R:
try: try:
start = line.index('\033[0;') start = line.index('\033[0;')
end = line.index(' ', start) end = line.index(' ', start)
line = line[start:end] + '\033[0m\n' line = line[start:end] + '\n'
except ValueError: except ValueError:
line = '' line = ''
elif shell == 'mksh': elif shell == 'mksh':

View File

@ -1,17 +1,17 @@
  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd     HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  
  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd     HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  
  HOSTNAME  USER  ⓔ  some-virtual-environment   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     HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  
  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1     HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  
  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd     HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]     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  $(echo)  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  
  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»     HOSTNAME  USER   BRANCH  ⋯  shell  3rd  «Unicode!»  

View File

@ -36,6 +36,17 @@ abc
def def
 INSERT  ⋯  tests  shell  3rd  cd .  INSERT  ⋯  tests  shell  3rd  cd .
 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  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd .
 INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC  INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC
 INSERT $ABC~foo  3rd $ABCtrue  INSERT $ABC~foo  3rd $ABCtrue

View File

@ -36,6 +36,17 @@ abc
def def
 INSERT  ⋯  tests  shell  3rd  cd .  INSERT  ⋯  tests  shell  3rd  cd .
 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  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd .
 INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC  INSERT  ~foo  3rd  set_theme_option default.dividers.left.hard \$ABC
 INSERT $ABC~foo  3rd $ABCtrue  INSERT $ABC~foo  3rd $ABCtrue