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

Re: non-greedy matching?



On Mar 21,  2:23pm, Adam Spiers wrote:
} Subject: non-greedy matching?
}
}   ..... | perl -pe 's/%{.*?%}//g'
} 
} They are done in order to strip control characters from a prompt so
} that its display width can be determined.

I had to do something similar in prompt_bart_setup, and ended up with
this:

	${#${(%%f)${PS1//[%]\{[^%]#%\}/}}[1]}

The (f) and [1] are because of the multi-line PS1, where it computes the
length only of the first line.  The above works as long as you don't
have other prompt escapes inside the %{ %}.  Hmm.  Perhaps this:

	${#${(%%)${prompt_line_1a//[%]\{([^%]|%[^\}])#%\}/}}}

Looking at prompt_adam2_precmd, it does exactly what prompt_bart_precmd
does: compute a padding width by subtracting from $COLUMNS.  With the
above expression you can get rid of prompt_line_1[ab]_no_color entirely:

	prompt_padding_size=$(( COLUMNS
		- ${#${(%%)${prompt_line_1a//[%]\{([^%]|%[^\}])#%\}/}}}
		- ${#${(%%)${prompt_line_1b//[%]\{([^%]|%[^\}])#%\}/}}} ))

Which also, as Sven mentioned, gets rid of $(print -P ...).

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