zsh-users
 help / color / mirror / code / Atom feed
* Get visible length of a string (removing escape sequences)
@ 2015-05-13 22:33 Daniel Hahler
  2015-05-14  3:46 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Hahler @ 2015-05-13 22:33 UTC (permalink / raw)
  To: zsh-users

-----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-----


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-14  3:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-13 22:33 Get visible length of a string (removing escape sequences) Daniel Hahler
2015-05-14  3:46 ` Bart Schaefer

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).