about summary refs log tree commit diff
path: root/Doc/Zsh/mod_zutil.yo
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-06-19 19:43:00 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-06-19 19:43:00 +0000
commit7b60aae9f314a2674d8512b3d85f83020148da73 (patch)
treecb0f01a3a7e5f484f8f40deff1ef89f067107edb /Doc/Zsh/mod_zutil.yo
parent543a83f63ebcebbf6d3f189f27adc7a620d67f82 (diff)
downloadzsh-7b60aae9f314a2674d8512b3d85f83020148da73.tar.gz
zsh-7b60aae9f314a2674d8512b3d85f83020148da73.tar.xz
zsh-7b60aae9f314a2674d8512b3d85f83020148da73.zip
18616: Add ternary expression handling to zformat
Diffstat (limited to 'Doc/Zsh/mod_zutil.yo')
-rw-r--r--Doc/Zsh/mod_zutil.yo25
1 files changed, 25 insertions, 0 deletions
diff --git a/Doc/Zsh/mod_zutil.yo b/Doc/Zsh/mod_zutil.yo
index e22197ea2..3dc4b25a6 100644
--- a/Doc/Zsh/mod_zutil.yo
+++ b/Doc/Zsh/mod_zutil.yo
@@ -124,6 +124,31 @@ many characters.  After all `tt(%)' sequences for the given var(specs)
 have been processed, the resulting string is stored in the parameter
 var(param).
 
+The tt(%)-escapes also understand ternary expressions in the form used by
+prompts.  The tt(%) is followed by a `tt(LPAR())' and then an ordinary
+format specifier character as described above.  There may be a set of
+digits either before or after the `tt(LPAR())'; these specify a test
+number, which defaults to zero.  Negative numbers are also allowed.  An
+arbitrary delimiter character follows the format specifier, which is
+followed by a piece of `true' text, the delimiter character again, a piece
+of `false' text, and a closing parenthesis.  The complete expression
+(without the digits) thus looks like
+`tt(%LPAR())var(X)tt(.)var(text1)tt(.)var(text2)tt(RPAR())', except that
+the `tt(.)' character is arbitrary.  The value given for the format
+specifier in the var(char)tt(:)var(string) expressions is evaluated as a
+mathematical expression, and compared with the test number.  If they are
+the same, var(text1) is output, else var(text2) is output.  A parenthesis
+may be escaped in var(text2) as tt(%RPAR()).  Either of var(text1) or
+var(text2) may contain nested tt(%)-escapes.
+
+For example:
+
+example(zformat -f REPLY "The answer is '%3(c.yes.no)'." c:3)
+
+outputs "The answer is 'yes'." to tt(REPLY) since the value for the format
+specifier tt(c) is 3, agreeing with the digit argument to the ternary
+expression.
+
 The second form, using the tt(-a) option, can be used for aligning
 strings.  Here, the var(specs) are of the form
 `var(left)tt(:)var(right)' where `var(left)' and `var(right)' are