zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: Justifying text output
Date: Fri, 12 Mar 2004 10:59:12 +0000	[thread overview]
Message-ID: <2136.1079089152@csr.com> (raw)
In-Reply-To: "Thorsten Kampe"'s message of "Fri, 12 Mar 2004 03:01:10 +0100." <1mm7og67rpkdy.dlg@thorstenkampe.de>

Thorsten Kampe wrote:
> I wrote a little script[1] that compiles the main zsh config files. Is
> there any way to make the "[ ok ]"/"[ failed ]" messages on the right
> justified?

There are various ways; most involve assigning the variable-length part
of the message to a string.  You should probably not put any escape
characters in there so it doesn't include them in the length
calculation (though if the escape sequences are all the same you would
get away with it).

The standard ksh way is (using a simplified example) to specify left
justification for a parameter:

 typeset -L 40 msg
 for msg in "message one" "a longer message here" "short"; do
 print ${msg} "[ WOW ]"
 done

giving:

 message one                              [ WOW ]
 a longer message here                    [ WOW ]
 short                                    [ WOW ]

You can avoid using the `-L 40' if you change ${msg} to ${(r.40.)msg}.
That's a zsh extension which pads to the given width with spaces.  The
`r' appears instead of `l' because it indicates where the padding goes,
not where the justification is.

However, you can actually get away without assigning the message to a
parameter:

 print ${(r.40.):-"message one"} "WOW"
 print ${(r.40.):-"a longer message here"} "WOW"
 print ${(r.40.):-"short"} "WOW"

giving

 message one                              WOW
 a longer message here                    WOW
 short                                    WOW

That works because zsh treats the absence of a parameter name as an
unset parameter, so it uses the normal logic for :-.  In other words,
`if the length of the parameter is zero, substitute the following string
instead'.   The (r.40.) padding flag works just the same.  You can
include further substitutions in the text, so this would still work in
your case.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  parent reply	other threads:[~2004-03-12 10:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-12  2:01 Thorsten Kampe
2004-03-12 10:55 ` Bart Schaefer
2004-03-12 23:24   ` Thorsten Kampe
2004-03-13  6:24     ` Bart Schaefer
2004-03-13 17:48       ` Thorsten Kampe
2004-03-13 18:58         ` Oliver Kiddle
2004-03-12 10:59 ` Peter Stephenson [this message]
2004-03-12 22:33   ` Thorsten Kampe
2004-03-13  3:29   ` Thorsten Kampe
2004-03-12 11:28 ` Oliver Kiddle
2004-03-12 22:33   ` Thorsten Kampe
2004-03-12 23:03     ` Pavol Juhas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2136.1079089152@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).