Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: custom widget / redraw prompt



On Mar 24,  1:57pm, Simon Dassow wrote:
}
} i'm currently on a custom widget, which will dis/enable the RPROMPT on
} keypress (^P), so i can copy the commandline without the RPROMPT.

You can't do this in the obvious way.  The prompts (both left and right)
are computed just after the `precmd' function runs, and then subsequent
ZLE refreshes only repaint them; so changes to PROMPT, RPROMPT, et al.,
during widget execution have no effect.

Here are some possible alternatives; the first one both changes and
covers up the RPROMPT, the second one merely moves the command onto a
line by itself and leaves the prompts alone.

    switch-rprompt() {
      if [[ -z "$RPROMPT" ]]; then
        setopt localoptions extendedglob
	export RPROMPT="$MYRPROMPT"
	RBUFFER="${RBUFFER%% #}"
      else
	export RPROMPT=""
	RBUFFER="$RBUFFER${(l:COLUMNS:: :):-}"
      fi
    }

    switch-rprompt() {
      setopt localoptions noksharrays
      if [[ "$BUFFER" == $'\\\n'* ]]; then
	((CURSOR -= 2))
	BUFFER="$BUFFER[3,-1]"
      else
	LBUFFER=$'\\\n'"$LBUFFER"
      fi
    }

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author