From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4633 invoked from network); 12 Mar 2004 10:59:46 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 12 Mar 2004 10:59:46 -0000 Received: (qmail 15210 invoked by alias); 12 Mar 2004 10:59:17 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7157 Received: (qmail 15189 invoked from network); 12 Mar 2004 10:59:14 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 12 Mar 2004 10:59:14 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [62.189.58.19] by sunsite.dk (MessageWall 1.0.8) with SMTP; 12 Mar 2004 10:59:13 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i2CAxDv19949 for ; Fri, 12 Mar 2004 10:59:13 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Fri, 12 Mar 2004 10:58:52 +0000 Received: from csr.com ([192.168.144.127]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 12 Mar 2004 11:01:14 +0000 To: zsh-users@sunsite.dk Subject: Re: Justifying text output In-reply-to: "Thorsten Kampe"'s message of "Fri, 12 Mar 2004 03:01:10 +0100." <1mm7og67rpkdy.dlg@thorstenkampe.de> Date: Fri, 12 Mar 2004 10:59:12 +0000 Message-ID: <2136.1079089152@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 12 Mar 2004 11:01:14.0643 (UTC) FILETIME=[56345630:01C40821] 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 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 **********************************************************************