* When RPROMPT != RPS1 @ 2017-06-20 17:08 Jim 2017-06-20 18:22 ` Jim 0 siblings, 1 reply; 10+ messages in thread From: Jim @ 2017-06-20 17:08 UTC (permalink / raw) To: zsh-workers [-- Attachment #1.1: Type: text/plain, Size: 1116 bytes --] zsh 5.3.1 (x86_64-pc-linux-gnu) When switching between prompt theme walters and some other themes I noticed that the right prompt remained. On checking I found walters was the only theme that used RPROMPT to set the right prompt. The only other theme to set the right prompt is bart, but it used RPS1. After switching from walters to say adam, I unset "RPS1", but the right prompt remained. I then typed "unset RPROMPT" and the right prompt was no longer there. The output of a script I wrote doesn't match what I though it should, but then again it was just strange. Current state of RPROMPT and RPS1 RPROMPT: RPS1: Set RPROMPT to RPROMPT RPROMPT: RPROMPT RPS1: Set RPS1 to RPS1 RPROMPT: RPS1 RPS1: RPS1 Unset RPRMOPT RPROMPT: RPS1: Unset RPS1 RPROMPT: RPS1: Set RPROMPT to RPROMPT Set RPS1 to RPS1 RPROMPT: RPS1 RPS1: RPS1 Unset RPS1 RPROMPT: RPS1: Unset RPRMOPT RPROMPT: RPS1: Strange! The results here contradict what I was seeing with the right prompt and unset RPS1. I'm also attaching the script. Thanks for zsh and your help. Jim [-- Attachment #1.2: Type: text/html, Size: 1542 bytes --] [-- Attachment #2: right_prompt_test --] [-- Type: application/octet-stream, Size: 766 bytes --] #!/bin/zsh print "Current state of RPROMPT and RPS1" print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Set RPROMPT to RPROMPT" ; RPROMPT="RPROMPT" print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Set RPS1 to RPS1" ; RPS1="RPS1" print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Unset RPRMOPT" ; unset RPROMPT print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Unset RPS1" ; unset RPS1 print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Set RPROMPT to RPROMPT" ; RPROMPT="RPROMPT" print "Set RPS1 to RPS1" ; RPS1="RPS1" print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Unset RPS1" ; unset RPS1 print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" print "Unset RPRMOPT" ; unset RPROMPT print -l "\tRPROMPT: $RPROMPT" "\tRPS1: $RPS1" ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-20 17:08 When RPROMPT != RPS1 Jim @ 2017-06-20 18:22 ` Jim 2017-06-21 17:16 ` Bart Schaefer 0 siblings, 1 reply; 10+ messages in thread From: Jim @ 2017-06-20 18:22 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 1898 bytes --] On Tue, Jun 20, 2017 at 12:08 PM, Jim <linux.tech.guy@gmail.com> wrote: > zsh 5.3.1 (x86_64-pc-linux-gnu) > > When switching between prompt theme walters and some > other themes I noticed that the right prompt remained. On > checking I found walters was the only theme that used > RPROMPT to set the right prompt. The only other theme > to set the right prompt is bart, but it used RPS1. > > After switching from walters to say adam, I unset "RPS1", > but the right prompt remained. I then typed > "unset RPROMPT" and the right prompt was no longer there. > > The output of a script I wrote doesn't match what I though it > should, but then again it was just strange. > > Current state of RPROMPT and RPS1 > RPROMPT: > RPS1: > Set RPROMPT to RPROMPT > RPROMPT: RPROMPT > RPS1: > Set RPS1 to RPS1 > RPROMPT: RPS1 > RPS1: RPS1 > Unset RPRMOPT > RPROMPT: > RPS1: > Unset RPS1 > RPROMPT: > RPS1: > Set RPROMPT to RPROMPT > Set RPS1 to RPS1 > RPROMPT: RPS1 > RPS1: RPS1 > Unset RPS1 > RPROMPT: > RPS1: > Unset RPRMOPT > RPROMPT: > RPS1: > > Strange! The results here contradict what I was seeing > with the right prompt and unset RPS1. I'm also attaching > the script. > > Thanks for zsh and your help. > > Jim > I should have checked earlier. I'm seeing the same thing with RPS2 and RPROMPT2. Current state of RPROMPT2 and RPS2 RPROMPT2: RPS2: Set RPROMPT2 to RPROMPT2 RPROMPT2: RPROMPT2 RPS2: Set RPS2 to RPS2 RPROMPT2: RPS2 RPS2: RPS2 Unset RPRMOPT2 RPROMPT2: RPS2: Unset RPS2 RPROMPT2: RPS2: Set RPROMPT2 to RPROMPT2 Set RPS2 to RPS2 RPROMPT2: RPS2 RPS2: RPS2 Unset RPS2 RPROMPT2: RPS2: Unset RPRMOPT2 RPROMPT2: RPS2: In addition the promptinit function doesn't set RPS2: local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 Again, thanks, Jim ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-20 18:22 ` Jim @ 2017-06-21 17:16 ` Bart Schaefer 2017-06-22 9:17 ` Peter Stephenson 0 siblings, 1 reply; 10+ messages in thread From: Bart Schaefer @ 2017-06-21 17:16 UTC (permalink / raw) To: zsh-workers; +Cc: linuxtechguy On Jun 20, 1:22pm, Jim wrote: } } > After switching from walters to say adam, I unset "RPS1", } > but the right prompt remained. I then typed } > "unset RPROMPT" and the right prompt was no longer there. } } I should have checked earlier. I'm seeing the same thing with } RPS2 and RPROMPT2. What's going on here is that RPROMPT, RPS1, RROMPT2, and RPS2 always start out as unset, so assigning to one of each pair does not cause the second one to magically become set. Then if you unset any one that is already unset, nothing happens (including not unsetting the paired one). The assumption is that under normal circumstances the user will not be arbitrarily/randomly switching which name he prefers to use. The prompt themes mess with that because they combine code from several different users. The reason they start out as unset is explained here: http://www.zsh.org/mla/workers/2014/msg00128.html The argument/complaint was that if those parameters have no meaning in an emulation mode, then they should not be set at all, thereby allowing scripts in the emulation to use those names any way they want without triggering the pairing behavior. I don't have a good suggestion for how to satisfy both constraints. Anyone? The parameter initialization code has been broken up into a few more sections already, maybe there's a way to rearrange these as well. } In addition the promptinit function doesn't set RPS2: } } local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 Yeah, I'm not sure why it's done that way; the prompt_bart_setup doc even says: If a fifth color is specified and there is no RPS2, PS2 (PROMPT2) is colored and moved to RPS2. Changes to RPS1/RPS2 are currently not reverted when the theme is switched off. Obviously, though, that "local" command was written before the change from workers/32337 was applied. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-21 17:16 ` Bart Schaefer @ 2017-06-22 9:17 ` Peter Stephenson 2017-06-23 20:07 ` Daniel Tameling 0 siblings, 1 reply; 10+ messages in thread From: Peter Stephenson @ 2017-06-22 9:17 UTC (permalink / raw) To: zsh-workers On Wed, 21 Jun 2017 10:16:45 -0700 Bart Schaefer <schaefer@brasslantern.com> wrote: > I don't have a good suggestion for how to satisfy both constraints. > Anyone? The parameter initialization code has been broken up into > a few more sections already, maybe there's a way to rearrange these > as well. We can at least make it less likely people are going to trip over the complications if they're simply using the prompt system. pws idiff --git a/Functions/Prompts/prompt_walters_setup b/Functions/Prompts/prompt_walters_setup index 7948254..9fea574 100644 --- a/Functions/Prompts/prompt_walters_setup +++ b/Functions/Prompts/prompt_walters_setup @@ -14,10 +14,10 @@ EOF prompt_walters_setup () { if [[ "$TERM" != "dumb" ]]; then - PROMPT='%B%(?..[%?] )%b%n@%U%m%u> ' - RPROMPT="%F{${1:-green}}%~%f" + PS1='%B%(?..[%?] )%b%n@%U%m%u> ' + RPS1="%F{${1:-green}}%~%f" else - PROMPT="%(?..[%?] )%n@%m:%~> " + PS1="%(?..[%?] )%n@%m:%~> " fi prompt_opts=(cr percent) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-22 9:17 ` Peter Stephenson @ 2017-06-23 20:07 ` Daniel Tameling 2017-06-24 3:37 ` Bart Schaefer 0 siblings, 1 reply; 10+ messages in thread From: Daniel Tameling @ 2017-06-23 20:07 UTC (permalink / raw) To: zsh-workers Peter Stephenson writes: > On Wed, 21 Jun 2017 10:16:45 -0700 > Bart Schaefer <schaefer@brasslantern.com> wrote: >> I don't have a good suggestion for how to satisfy both constraints. >> Anyone? The parameter initialization code has been broken up into >> a few more sections already, maybe there's a way to rearrange these >> as well. > > We can at least make it less likely people are going to trip over the > complications if they're simply using the prompt system. > > pws If I understand the problem correctly, the issue is not just limited to the right prompts. The different themes set different prompt variables, so when you change between themes you get a prompt setup that depends on the history of themes you used. For example, if I do autoload -Uz promptinit; promptinit prompt clint echo $PS3 I get ?# But if I do autoload -Uz promptinit; promptinit prompt adam1 prompt clint echo $PS3 I get %K{blue}%n@%m%k %B%F{green}%147<...<%~ %}%F{white} ?# %b%f%k Interestingly, there is no problem with the prompt functions like precmd, preexec etc. as the configuration of the previously active theme gets deleted in set_prompt right before the new theme is activated: local hook for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do add-zsh-hook -D "${hook}" "prompt_*_${hook}" done I think one solution for getting a consistent setup might be to add some code at the same place that restores the prompt variables to their default values. Maybe something along the lines of what I included below (which seems to solve the problem on my system). However, this breaks the bart theme as it has a mode of operation where one can set the right prompt before activating the theme. Best, Daniel diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 587248997..0bc9b1ab4 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -160,6 +160,11 @@ Use prompt -h <theme> for help on specific themes.' for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do add-zsh-hook -D "${hook}" "prompt_*_${hook}" done + PS1='%m%# ' + PS2='%_> ' + PS3='?# ' + PS4='+%N:%i> ' + unset RPROMPT RPS1 RPROMPT2 RPS2 typeset -ga zle_highlight=( ${zle_highlight:#default:*} ) (( ${#zle_highlight} )) || unset zle_highlight ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-23 20:07 ` Daniel Tameling @ 2017-06-24 3:37 ` Bart Schaefer 2017-06-24 20:09 ` Daniel Tameling 0 siblings, 1 reply; 10+ messages in thread From: Bart Schaefer @ 2017-06-24 3:37 UTC (permalink / raw) To: zsh-workers On Jun 23, 10:07pm, Daniel Tameling wrote: } } Maybe something along the lines of what I included below (which seems to } solve the problem on my system). However, this breaks the bart theme as } it has a mode of operation where one can set the right prompt before } activating the theme. Not just the right prompt, but the PS1 prompt as well. The reason there is "prompt -p" is so you can see what a prompt will look like without changing whatever you have already or needing to cycle the themes yourself. The better thing to do, I think, is either to add "prompt_default_setup" or expand "prompt_off_setup" so that there's an explicit command to put things back the way they were. Currently "prompt off" restores only the PS1 and PS2 settings. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-24 3:37 ` Bart Schaefer @ 2017-06-24 20:09 ` Daniel Tameling 2017-07-28 2:53 ` Bart Schaefer 0 siblings, 1 reply; 10+ messages in thread From: Daniel Tameling @ 2017-06-24 20:09 UTC (permalink / raw) To: zsh-workers > The reason there is "prompt -p" is so you can see what a prompt will look > like without changing whatever you have already or needing to cycle the > themes yourself. If I try out a prompt, I like to execute some commands and see how that affects the prompt, and with "prompt -p" that's not possible. So with the current setup, I have to be careful which prompt variables are changed, and then revert the changes. In principle, this is no big deal but it would be nicer if there was an automatic solution. > The better thing to do, I think, is either to add "prompt_default_setup" > or expand "prompt_off_setup" so that there's an explicit command to put > things back the way they were. Currently "prompt off" restores only the > PS1 and PS2 settings. I like both ideas. Best, Daniel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-06-24 20:09 ` Daniel Tameling @ 2017-07-28 2:53 ` Bart Schaefer 2017-07-31 16:24 ` Jim 0 siblings, 1 reply; 10+ messages in thread From: Bart Schaefer @ 2017-07-28 2:53 UTC (permalink / raw) To: zsh-workers I went on vacation for a while immediately after this discussion, so it got left sitting for a bit. Here's a patch which does several things for the prompt theme system: - introduces a standard way for themes to clean up after themselves, the prompt_cleanup callback (aka hook). I've modified "prompt bart" to use this by way of example. - added the "default" and "restore" themes. The "restore" theme is a special case that calls the cleanup hooks to put everything back as it was before you experimented with some other prompt theme. - adds documentation for the above plus a new subsection about how to write a new theme. There are still a few tweaks possible, I expect. There's an awful lot of state to keep track of here. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 35ab100..35ce915 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1920,8 +1920,9 @@ subsect(Installation) You should make sure all the functions from the tt(Functions/Prompts) directory of the source distribution are available; they all begin with the string `tt(prompt_)' except for the special function`tt(promptinit)'. -You also need the `tt(colors)' function from tt(Functions/Misc). All of -these functions may already have been installed on your system; if not, +You also need the `tt(colors)' and `tt(add-zsh-hook)' functions from +tt(Functions/Misc). +All these functions may already be installed on your system; if not, you will need to find them and copy them. The directory should appear as one of the elements of the tt(fpath) array (this should already be the case if they were installed), and at least the function tt(promptinit) @@ -1975,6 +1976,75 @@ normally call a theme's setup function directly. ) enditem() +subsect(Utility Themes) + +startitem() +item(tt(prompt off))( +The theme `tt(off)' sets all the prompt variables to minimal values with +no special effects. +) +item(tt(prompt default))( +The theme `tt(default)' sets all prompt variables to the same state as +if an interactive zsh was started with no initialization files. +) +item(tt(prompt restore))( +The special theme `tt(restore)' erases all theme settings and sets prompt +variables to their state before the first time the `tt(prompt)' function +was run, provided each theme has properly defined its cleanup (see below). + +Note that you can undo `tt(prompt off)' and `tt(prompt default)' with +`tt(prompt restore)', but a second restore does not undo the first. +) +enditem() + +subsect(Writing Themes) + +The first step for adding your own theme is to choose a name for it, +and create a file `tt(prompt_var(name)_setup)' in a directory in your +tt(fpath), such as tt(~/myfns) in the example above. The file should +at minimum contain assignments for the prompt variables that your +theme wishes to modify. By convention, themes use tt(PS1), tt(PS2), +tt(RPS1), etc., rather than the longer tt(PROMPT) and tt(RPROMPT). + +The file is autoloaded as a function in the current shell context, so +it may contain any necessary commands to customize your theme, including +defining additional functions. To make some complex tasks easier, your +setup function may also do any of the following: + +startitem() +item(Assign tt(prompt_opts))( +The array tt(prompt_opts) may be assigned any of tt("bang"), tt("cr"), +tt("percent"), tt("sp"), and/or tt("subst") as values. The corresponding +setopts (tt(promptbang), etc.) are turned on, all other prompt-related +options are turned off. The tt(prompt_opts) array preserves setopts even +beyond the scope of tt(localoptions), should your function need that. +) +item(Modify precmd and preexec)( +Use of tt(add-zsh-hook) is recommended. The tt(precmd) and tt(preexec) +hooks are automatically adjusted if the prompt theme changes or is +disabled. +) +item(Declare cleanup)( +If your function makes any other changes that should be undone when the +theme is disabled, your setup function may call +example(prompt_cleanup var(command)) +where var(command) should be suitably quoted. If your theme is ever +disabled or replaced by another, var(command) is executed with tt(eval). +You may declare more than one such cleanup hook. +) +item(Define preview)( +Define or autoload a function tt(prompt_var(name)_preview) to display +a simulated version of your prompt. A simple default previewer is +defined by tt(promptinit) for themes that do not define their own. +This preview function is called by `tt(prompt -p)'. +) +item(Provide help)( +Define or autoload a function tt(prompt_var(name)_help) to display +documentation or help text for your theme. +This help function is called by `tt(prompt -h)'. +) +enditem() + texinode(ZLE Functions)(Exception Handling)(Prompt Themes)(User Contributions) sect(ZLE Functions) diff --git a/Functions/Prompts/prompt_bart_setup b/Functions/Prompts/prompt_bart_setup index cb032de..6de4122 100644 --- a/Functions/Prompts/prompt_bart_setup +++ b/Functions/Prompts/prompt_bart_setup @@ -16,9 +16,13 @@ prompt_bart_help () { blue, and the default foreground) are used if no arguments are given. The defaults look best on a light background. - The "off" token temporarily disables the theme; "on" restores it. No background colors or hardwired cursor motion escapes are used, and it is not necessary to setopt promptsubst. + + The "off" token temporarily disables the theme; "on" restores it. + Note, this does NOT fully reset to the original prompt state, it + only hides/reveals the extra lines above the command line and + removes the supporting hooks. EOF [[ $(read -sek 1 "?${(%):-%S[press return]%s}") == [Qq] ]] && print -nP '\r%E' && return @@ -183,7 +187,7 @@ prompt_bart_setup () { add-zsh-hook -D preexec "prompt_*_preexec" functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}" [[ $prompt_theme[1] = bart ]] && PS1=${${(f)PS1}[-1]} - return 1 + return 1 # Prevent change of $prompt_theme ;; (on|enable) shift @@ -224,6 +228,8 @@ prompt_bart_setup () { add-zsh-hook precmd prompt_bart_precmd add-zsh-hook preexec prompt_bart_preexec + prompt_cleanup \ + 'functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}"' functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch} prompt_bart_winch" diff --git a/Functions/Prompts/prompt_default_setup b/Functions/Prompts/prompt_default_setup new file mode 100644 index 0000000..aed74eb --- /dev/null +++ b/Functions/Prompts/prompt_default_setup @@ -0,0 +1,7 @@ +PS1='%m%# ' +PS2='%_> ' +PS3='?# ' +PS4='+%N:%i> ' +unset RPS1 RPS2 RPROMPT RPROMPT2 + +prompt_opts=( cr percent sp ) diff --git a/Functions/Prompts/prompt_off_setup b/Functions/Prompts/prompt_off_setup index f604b47..e6d16bf 100644 --- a/Functions/Prompts/prompt_off_setup +++ b/Functions/Prompts/prompt_off_setup @@ -1,9 +1,10 @@ # Very simple prompt -prompt_off_setup () { - PS1="%# " - PS2="> " - prompt_opts=( cr percent ) -} +prompt_default_setup 2>/dev/null -prompt_off_setup "$@" +PS1="%# " +PS2="> " +PS3='?# ' +PS4='+> ' + +prompt_opts=( cr percent sp ) diff --git a/Functions/Prompts/prompt_restore_setup b/Functions/Prompts/prompt_restore_setup new file mode 100644 index 0000000..54c4adb --- /dev/null +++ b/Functions/Prompts/prompt_restore_setup @@ -0,0 +1,2 @@ +# Damn that was easy +zstyle -t :prompt-theme cleanup diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 5872489..e27b877 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -47,20 +47,36 @@ prompt_preview_safely() { return fi - local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 - local -a precmd_functions preexec_functions - - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _preview function that it's been autoloaded. - prompt_${1}_setup - - if typeset +f prompt_${1}_preview >&/dev/null; then - prompt_${1}_preview "$@[2,-1]" - else - prompt_preview_theme "$@" - fi + # This handles all the stuff from the default :prompt-theme cleanup + local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 + local +h PROMPT=$PROMPT RPROMPT=$RPOMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR + local -a precmd_functions preexec_functions prompt_preview_cleanup + local -aLl +h zle_highlight + + { + # Save and clear current restore-point if any + zstyle -g prompt_preview_cleanup :prompt-theme cleanup + { + zstyle -d :prompt-theme cleanup + + # The next line is a bit ugly. It (perhaps unnecessarily) + # runs the prompt theme setup function to ensure that if + # the theme has a _preview function that it's been autoloaded. + prompt_${1}_setup + + if typeset +f prompt_${1}_preview >&/dev/null; then + prompt_${1}_preview "$@[2,-1]" + else + prompt_preview_theme "$@" + fi + } always { + # Run any theme-specific cleanup, then reset restore point + zstyle -t :prompt-theme cleanup + } + } always { + (( $#prompt_preview_cleanup )) && + zstyle -e :prompt-theme cleanup "${prompt_preview_cleanup[@]}" + } } set_prompt() { @@ -84,9 +100,9 @@ Use prompt -h <theme> for help on specific themes.' setopt localtraps if [[ -z "$prompt_theme[1]" ]]; then # Not using a prompt theme; save settings - local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 - local precmd_functions preexec_functions + local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 + local +h PROMPT=$PROMPT RPROMPT=$RPOMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR + local -a precmd_functions preexec_functions else trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0 fi @@ -104,11 +120,11 @@ Use prompt -h <theme> for help on specific themes.' ;; h) if [[ -n "$2" && -n $prompt_themes[(r)$2] ]]; then if functions prompt_$2_setup >/dev/null; then - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _help function that it's been autoloaded. - prompt_$2_setup - fi + # The next line is a bit ugly. It (perhaps unnecessarily) + # runs the prompt theme setup function to ensure that if + # the theme has a _help function that it's been autoloaded. + prompt_$2_setup + fi if functions prompt_$2_help >/dev/null; then print "Help for $2 theme:\n" prompt_$2_help @@ -168,28 +184,74 @@ Use prompt -h <theme> for help on specific themes.' esac } +prompt_cleanup () { + local -a cleanup_hooks + if zstyle -g cleanup_hooks :prompt-theme cleanup + then + cleanup_hooks+=(';' "$@") + zstyle -e :prompt-theme cleanup "${cleanup_hooks[@]}" + elif (( $+prompt_preview_cleanup == 0 )) + then + print -u2 "prompt_cleanup: no prompt theme active" + return 1 + fi +} + prompt () { - local prompt_opts + local -a prompt_opts theme_active + zstyle -g theme_active :prompt-theme cleanup || { + # This is done here rather than in set_prompt so that it + # is safe and sane for set_prompt to setopt localoptions, + # which will be cleared before we arrive back here again. + # This is also why we pass around the prompt_opts array. + [[ -o promptbang ]] && prompt_opts+=(bang) + [[ -o promptcr ]] && prompt_opts+=(cr) + [[ -o promptpercent ]] && prompt_opts+=(percent) + [[ -o promptsp ]] && prompt_opts+=(sp) + [[ -o promptsubst ]] && prompt_opts+=(subst) + zstyle -e :prompt-theme cleanup \ + 'zstyle -d :prompt-theme cleanup;' \ + 'prompt_default_setup;' \ + ${PS1+PS1="${(q)PS1}"} \ + ${PS2+PS2="${(q)PS2}"} \ + ${PS3+PS3="${(q)PS3}"} \ + ${PS4+PS4="${(q)PS4}"} \ + ${RPS1+RPS1="${(q)RPS1}"} \ + ${RPS2+RPS2="${(q)RPS2}"} \ + ${RPROMPT+RPROMPT="${(q)RPROMPT}"} \ + ${RPROMPT2+RPROMPT2="${(q)RPROMPT2}"} \ + ${PSVAR+PSVAR="${(q)PSVAR}"} \ + "precmd_functions=(${(q)precmd_functions[@]})" \ + "preexec_functions=(${(q)preexec_functions[@]})" \ + "prompt_opts=( ${prompt_opts[*]} )" \ + 'reply=(yes)' + } set_prompt "$@" - (( $#prompt_opts )) && - setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}" + (( ${#prompt_opts} )) && + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" true } prompt_preview_theme () { emulate -L zsh - local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 - local precmd_functions preexec_functions prompt_opts - local -aLl +h zle_highlight + # Check for proper state handling + (( $+prompt_preview_cleanup )) || { + prompt_preview_safely "$@" + return + } + + # Minimal preview for prompts that don't supply one + local -a prompt_opts print -n "$1 theme" (( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'" print ":" prompt_${1}_setup "$@[2,-1]" + (( ${#prompt_opts} )) && + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" [[ -n ${precmd_functions[(r)prompt_${1}_precmd]} ]] && prompt_${1}_precmd [[ -o promptcr ]] && print -n $'\r'; : ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-07-28 2:53 ` Bart Schaefer @ 2017-07-31 16:24 ` Jim 2017-07-31 18:33 ` Bart Schaefer 0 siblings, 1 reply; 10+ messages in thread From: Jim @ 2017-07-31 16:24 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 970 bytes --] Hi again, On Thu, Jul 27, 2017 at 9:53 PM, Bart Schaefer <schaefer@brasslantern.com> wrote: > I went on vacation for a while immediately after this discussion, so it > got left sitting for a bit. > > [clip clip clip] Built 5.3.1-dev-1 with your changes. Upon testing, I found that the original issues of the right prompt is still there when switching between walters and either bart or adam2. The right prompt appears on the right side of second line of the prompt. But unlike previous versions of zsh where unset RPROMPT was needed to remove the unwanted prompt, you now have to type unset RPS1 ?? I know that walters was changed to replace RPROMPT with RPS1, which I though would correct this issue. Can anyone verify that they are seeing the same thing, or is it just something I'm not doing correctly. BTW, was there any reason for changing walters' appearance? It now does underlining instead of the colors as in previous versions of zsh. Thanks, Jim ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: When RPROMPT != RPS1 2017-07-31 16:24 ` Jim @ 2017-07-31 18:33 ` Bart Schaefer 0 siblings, 0 replies; 10+ messages in thread From: Bart Schaefer @ 2017-07-31 18:33 UTC (permalink / raw) To: linuxtechguy; +Cc: zsh-workers On Mon, Jul 31, 2017 at 9:24 AM, Jim <linux.tech.guy@gmail.com> wrote: > > Built 5.3.1-dev-1 with your changes. Upon testing, I found that the > original > issues of the right prompt is still there when switching between walters > and either bart or adam2. The right prompt appears on the right side of > second line of the prompt. That's intentional. It's up to each theme to determine how much of the preexisting state should be replaced; if the theme doesn't explicitly do anything with RPS1, then it remains when switching. To get the effect you are after, you should be doing three steps: prompt walters prompt restore prompt adam2 (or whatever). "prompt default" or "prompt off" would also be possible as the middle step. > But unlike previous versions of zsh where > unset RPROMPT > was needed to remove the unwanted prompt, you now have to type > unset RPS1 > ?? Yes, the intent of the change to "walters" was to make it consistent in that you can always "unset RPS1" rather than having to use one parameter name for some prompts and the other name for others. It didn't otherwise affect anything > BTW, was there any reason for changing walters' appearance? It > now does underlining instead of the colors as in previous versions > of zsh. There has been no change to "prompt walters", it has always used %U/%u in PS1 and color (default green) in RPS1. However, the interpretation of %U is specific to the termcap/terminfo definition of the current terminal, so it's possible that's affecting something you see. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-07-31 18:34 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-06-20 17:08 When RPROMPT != RPS1 Jim 2017-06-20 18:22 ` Jim 2017-06-21 17:16 ` Bart Schaefer 2017-06-22 9:17 ` Peter Stephenson 2017-06-23 20:07 ` Daniel Tameling 2017-06-24 3:37 ` Bart Schaefer 2017-06-24 20:09 ` Daniel Tameling 2017-07-28 2:53 ` Bart Schaefer 2017-07-31 16:24 ` Jim 2017-07-31 18:33 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).