Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Get visible length of a string (removing escape sequences)
- X-seq: zsh-users 20210
- From: Daniel Hahler <genml+zsh-workers@xxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Get visible length of a string (removing escape sequences)
- Date: Thu, 14 May 2015 00:33:12 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thequod.de; h= content-transfer-encoding:content-type:content-type:subject :subject:mime-version:user-agent:from:from:date:date:message-id :received:received; s=postfix2; t=1431556392; bh=XvAu46b8v+4q8Sx zU0m17rBnVeginlOTA/oDYoBlA8Q=; b=ShXV19xPdKG48ou3prBkhCXByt10EEe 257OoQHyntVer+FyO3VFWJxBMMX6NRqRcsOwDi5XYX8jV7x2Mmq4/7zjJOdf4ZEe 3E/NNRLl5fIOdo+RVte4enVktAfbprJc+qwI4kLaFheHH6WdJbiJ3aFhVGPpzMi0 uM3IK411tYQY=
- 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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I am looking for a function to get the visible length of a string, which would
remove any escape codes for colors etc.
I've found the following via http://stackoverflow.com/a/10564427/15690, but it
throws an error for '`foo`': zsh: command not found: foo
I could escape these probably, but then '$(foo)' would be next etc.
I've tried to throw in "setopt localoptions nopromptsubst", but that appears to not
expand the ANSI color codes anymore.
Hopefully there's a better way?
Maybe there could be some extension to "$#" to make this simpler?
get_visible_length() {
local zero='%([BSUbfksu]|([FB]|){*})'
print ${#${(S%%)1//$~zero}}
}
Regards,
Daniel.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iD8DBQFVU9EofAK/hT/mPgARArR2AJ99+HEnfnwTvWJrYrly4PPTJj01pACgzwtn
CSlCs3R+9xdGVw1KygyFvoc=
=2I9V
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author