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

@ -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'

View File

@ -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,

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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!»  

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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':

View File

@ -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!»  

View File

@ -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

View File

@ -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