Subj : printf and color codes
To : Nightfox
From : Digital Man
Date : Mon Jan 21 2013 11:48 pm
Re: printf and color codes
By: Nightfox to Digital Man on Sun Jan 20 2013 06:14 pm
> Hi DM -
>
> I'm not sure if this is a bug or is intentional, but the JavaScript printf
> function doesn't seem to account for color codes (or perhaps non-printable
> characters in general) when printing strings with a specific field length.
> For instance:
>
> var name = "Bob Smith";
> printf("%-25s", name);
>
> That prints "Bob Smith" in a field with 25 characters as you'd expect, but
> if the string has any non-printable characters in it, each non-printable
> character subtracts 1 from the field length when the string is printed out.
> CTRL-A color codes have this effect when used with printf.
Being a C programmer, that's the behavior I would expect. There's no special
Ctrl-A code handling in the format/printf functions. You can use
console.strlen() to calculate the number of *printable* characters in a string
(excluding Ctrl-A codes) and use that to pad your console output with spaces if
you wish.
digital man
Synchronet "Real Fact" #48:
Synchronet program was named 'sbbs' instead of 'sync' to avoid conflict w/Unix.
Norco, CA WX: 65.6�F, 8.0% humidity, 11 mph E wind, 0.00 inches rain/24hrs
---
� Synchronet � Vertrauen � Home of Synchronet � telnet://vert.synchro.net