-
printf and color codes
From
Nightfox@VERT/DIGDIST to
Digital Man on Sun Jan 20 18:14:56 2013
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.ããNightfoxããã---ã þ Synchronet þ Digital Distortion BBS - digitaldistortionbbs.comã
-
From
Mro@VERT/BBSESINF to
Nightfox on Sun Jan 20 21:43:04 2013
Re: printf and color codesã By: Nightfox to Digital Man on Sun Jan 20 2013 06:14 pmãã > 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.ãããi'm pretty sure that's intentional and certainly seems like it should be.ãwho's name or other variable would have color codes in it, though?ã---ã þ Synchronet þ ::: BBSES.info - free BBS services :::ã
-
From
Nightfox@VERT/DIGDIST to
Mro on Sun Jan 20 21:50:02 2013
Re: printf and color codesã By: Mro to Nightfox on Sun Jan 20 2013 21:43:04ãã >> 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.ãã Mr> i'm pretty sure that's intentional and certainly seems like it should be.ããIt's not what I would expect. If you specify a field length for printf(), itãshould fill that entire field up to that length. Otherwise, the results can beãunexpected and ugly. The main uses for specifying a field length are to alignãtext and filling a space when overwriting existing text on the screen. I wouldãexpect printf() to only count visible/printable characters in the length of aãstring you give it.ãã Mr> who's name or other variable would have color codes in it, though?ããAnything where color is desired.. :PããNightfoxããã---ã þ Synchronet þ Digital Distortion BBS - digitaldistortionbbs.comã
-
From
MCMLXXIX@VERT/MDJ to
Nightfox on Mon Jan 21 11:29:24 2013
Re: printf and color codesã By: Nightfox to Mro on Sun Jan 20 2013 21:50:02ãã > Re: printf and color codesã > By: Mro to Nightfox on Sun Jan 20 2013 21:43:04ã > ã > >> 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.ã > ã > Mr> i'm pretty sure that's intentional and certainly seems like it should bã > ã > It's not what I would expect. If you specify a field length for printf(), iã > should fill that entire field up to that length. Otherwise, the results canã > unexpected and ugly. The main uses for specifying a field length are to aliã > text and filling a space when overwriting existing text on the screen. I woã > expect printf() to only count visible/printable characters in the length of ã > string you give it.ã > ã > Mr> who's name or other variable would have color codes in it, though?ã > ã > Anything where color is desired.. :Pã > ããI think you're right about this.. if printf is able to handle ctrl-A codes itãlikely should be able to format them correctly.. you can work around it though.ããvar diff = str.length - console.strlen(str);ãprintf("%-*s",25+diff,str);ãããã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã
-
From
Nightfox@VERT/DIGDIST to
MCMLXXIX on Mon Jan 21 12:36:54 2013
I think you're right about this.. if printf is able to handle ctrl-A codesã > it likely should be able to format them correctly.. you can work around itã > though.ã > ã > var diff = str.length - console.strlen(str);ã > printf("%-*s",25+diff,str);ããThat's true. Workarounds are always possible, and I've found otherãworkarounds for my needs as well. Just thought I'd point it out thoughãbecause it seemed odd.ããNightfoxãã---ã þ Synchronet þ Digital Distortion BBS - digitaldistortionbbs.comã
-
From
Digital Man@VERT to
Nightfox on Mon Jan 21 23:48:01 2013
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 þ [vert/cvs/bbs].synchro.netã
-
From
Digital Man@VERT to
Nightfox on Mon Jan 21 23:56:55 2013
Re: printf and color codesã By: Nightfox to Mro on Sun Jan 20 2013 09:50 pmãã > Re: printf and color codesã > By: Mro to Nightfox on Sun Jan 20 2013 21:43:04ã >ã > >> 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.ã >ã > Mr> i'm pretty sure that's intentional and certainly seems like it shouldã > Mr> be.ã >ã > It's not what I would expect. If you specify a field length for printf(),ã > it should fill that entire field up to that length. Otherwise, the resultsã > can be unexpected and ugly. The main uses for specifying a field lengthã > are to align text and filling a space when overwriting existing text on theã > screen. I would expect printf() to only count visible/printable charactersã > in the length of a string you give it.ããThat's not how printf (and the related formatting functions) in C work however. ãThe width modifier to the %s specifier does not specify the number of ã"printable" characters, just the number of characters, period (which includes ãnon-printable characters, like \a, \b, and so on).ãã digital manããSynchronet "Real Fact" #76:ãRob Swindell still has dozens of BBS-related magazines in his possession.ãNorco, CA WX: 65.4øF, 8.0% humidity, 7 mph E wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
Nightfox@VERT/DIGDIST to
Digital Man on Tue Jan 22 07:46:06 2013
Re: printf and color codesã By: Digital Man to Nightfox on Mon Jan 21 2013 23:56:55ãã DM> That's not how printf (and the related formatting functions) in C workã DM> however. The width modifier to the %s specifier does not specify theã DM> number of "printable" characters, just the number of characters, periodã DM> (which includes non-printable characters, like \a, \b, and so on).ããComing from a C/C++ background, I suspected that was so. Even then, it seemsãsomewhat odd.. But oh well, we deal with it. :)ããNightfoxããã---ã þ Synchronet þ Digital Distortion BBS - digitaldistortionbbs.comã
-
From
MCMLXXIX@VERT/MDJ to
Nightfox on Tue Jan 22 12:03:16 2013
Re: printf and color codesã By: Nightfox to Digital Man on Tue Jan 22 2013 07:46:06ãã > Re: printf and color codesã > By: Digital Man to Nightfox on Mon Jan 21 2013 23:56:55ã > ã > DM> That's not how printf (and the related formatting functions) in C workã > DM> however. The width modifier to the %s specifier does not specify theã > DM> number of "printable" characters, just the number of characters, periodã > DM> (which includes non-printable characters, like \a, \b, and so on).ã > ã > Coming from a C/C++ background, I suspected that was so. Even then, it seemã > somewhat odd.. But oh well, we deal with it. :)ã > ããI still think that if the function is going to handle the non-printableãcharacters, it should account for them. If it's not going to account for them,ãprintf() shouldn't be able to handle them (like console.write)ãããã---ã þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)ã