From: Daniel Hahler <genml+zsh-workers@thequod.de>
To: zsh-users@zsh.org
Subject: Get visible length of a string (removing escape sequences)
Date: Thu, 14 May 2015 00:33:12 +0200 [thread overview]
Message-ID: <5553D128.70203@thequod.de> (raw)
-----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-----
next reply other threads:[~2015-05-13 22:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 22:33 Daniel Hahler [this message]
2015-05-14 3:46 ` 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=5553D128.70203@thequod.de \
--to=genml+zsh-workers@thequod.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).