From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16886 invoked by alias); 13 May 2015 22:33:19 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20210 Received: (qmail 11967 invoked from network); 13 May 2015 22:33:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU autolearn=ham version=3.3.2 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= Message-ID: <5553D128.70203@thequod.de> Date: Thu, 14 May 2015 00:33:12 +0200 From: Daniel Hahler User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: zsh-users@zsh.org Subject: Get visible length of a string (removing escape sequences) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit -----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-----