Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Count only visible characters?
- X-seq: zsh-users 14988
- From: Joke de Buhr <joke@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Count only visible characters?
- Date: Fri, 9 Apr 2010 11:02:55 +0200
- In-reply-to: <loom.20100409T002951-342@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <loom.20100409T002951-342@xxxxxxxxxxxxxx>
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
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author