zsh-users
 help / color / mirror / code / Atom feed
From: Joke de Buhr <joke@seiken.de>
To: zsh-users@zsh.org
Subject: Re: Count only visible characters?
Date: Fri, 9 Apr 2010 11:02:55 +0200	[thread overview]
Message-ID: <201004091102.55291.joke@seiken.de> (raw)
In-Reply-To: <loom.20100409T002951-342@post.gmane.org>

Since you are using prompt expansion you should always escape the color codes 
with "%{...%}". That's the only way zsh can calculate the length of the prompt 
line correctly. Otherwise the cursor will not be positioned at the end of the 
visual end.

testing="%{%F{green}%}hello"


If you need to do manual counting you can use this 

${(S%%)#testing//\%\{*\%\}}

The command replaces every escape %{...%} sequence prior to calculating the 
length.


$ testing="%{%F{green}%}hello"
$ echo ${(S%%)#testing//\%\{*\%\}}
5


On Friday, 9. April 2010 00:38:05 Seth House wrote:
> Is there any way to count only visible characters?
> 
>     testing="%F{green}hello"
>     echo ${(%)#testing}
> 
> The number I'm interested in is 5 not 14.
> 
> After an awful lot of Googling, I'm under the impression this isn't a
>  trivial problem. If that is true, I would certainly enjoy a little
>  exposition if someone has time.
> 
> Thanks.
> - Seth
> 


  reply	other threads:[~2010-04-09  9:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-08 22:38 Seth House
2010-04-09  9:02 ` Joke de Buhr [this message]
2010-04-09  9:13   ` Frank Terbeck
2010-04-09  9:49     ` Joke de Buhr
2010-04-09 19:22       ` Seth House
2010-04-09 10:44     ` Sebastian Stark
2010-04-09 10:56       ` Sebastian Stark
2010-04-09 12:08         ` Peter Stephenson
2010-04-09 12:27           ` Sebastian Stark
2010-04-09 19:50 ` Peter Stephenson
2010-04-10  4:02   ` Bart Schaefer

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=201004091102.55291.joke@seiken.de \
    --to=joke@seiken.de \
    --cc=zsh-users@zsh.org \
    /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).