Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 19, 2003 String formatting stuff | ||||
---|---|---|---|---|
| ||||
Attachments: | I got this idea from boost. Seems to work pretty nicely. Comments/etc welcome. Console.io.write(format("String: '{%}' {%} + {%} = {%}") % "A string!" % 5 % 3 % (5+3)); |
March 20, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | "Andy Friesen" <andy@ikagames.com> escribió en el mensaje news:b58o2e$1rbj$1@digitaldaemon.com... | I got this idea from boost. Seems to work pretty nicely. Comments/etc | welcome. | | Console.io.write(format("String: '{%}' {%} + {%} = {%}") % "A string!" % | 5 % 3 % (5+3)); | I liked it a lot. I created console.lib merging your file with some routines I created a while ago for handling a text console (color, clrscr, etc... incomplete, though). I also added a write (char[] str) function for ConsoleStream. Anyway, I think there's some sort of mistake with the writeString(char[]) function, because if I do this: Console.io.write("Hello, "); Console.io.write("world"); I get two lines instead of just one. Since writeString is from stream (I assume), I think it's not your mistake. Well, I just thought I should let you all guys know this. ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17 |
March 20, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Carlos Santander B. wrote:
> "Andy Friesen" <andy@ikagames.com> escribió en el mensaje
> news:b58o2e$1rbj$1@digitaldaemon.com...
> | I got this idea from boost. Seems to work pretty nicely. Comments/etc
> | welcome.
> |
> | Console.io.write(format("String: '{%}' {%} + {%} = {%}") % "A string!" %
> | 5 % 3 % (5+3));
> |
>
> I liked it a lot. I created console.lib merging your file with some routines
> I created a while ago for handling a text console (color, clrscr, etc...
> incomplete, though). I also added a write (char[] str) function for
> ConsoleStream.
> Anyway, I think there's some sort of mistake with the writeString(char[])
> function, because if I do this:
> Console.io.write("Hello, "); Console.io.write("world");
> I get two lines instead of just one. Since writeString is from stream (I
> assume), I think it's not your mistake.
> Well, I just thought I should let you all guys know this.
>
> -------------------------
> Carlos Santander
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17
>
>
Nope. My mistake. Change the writeBlock method to read:
override uint writeBlock(void* buffer, uint size)
{
return c.stdio.fwrite(buffer, 1, size, c.stdio.stdout);
}
All will be well.
|
March 20, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | | Nope. My mistake. Change the writeBlock method to read: | | override uint writeBlock(void* buffer, uint size) | { | return c.stdio.fwrite(buffer, 1, size, c.stdio.stdout); | } | | All will be well. | Thanks ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17 |
March 21, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | This might be to Walter, but is related to your console utility. I've added this to Console: import console2; static void clear() { clrscr(); } static void gotoxy(int x,int y) { console2.gotoxy(x,y); } static void where (out int x,out int y) { x=wherex(); y=wherey(); } In console2 I have: void clrscr() { COORD coord; DWORD written; CONSOLE_SCREEN_BUFFER_INFO info; coord.X = 0; coord.Y = 0; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); FillConsoleOutputCharacterW (GetStdHandle(STD_OUTPUT_HANDLE), ' ', info.dwSize.X * info.dwSize.Y, coord, &written); gotoxy (1, 1); } void gotoxy(int x, int y) { COORD c; c.X = x - 1; c.Y = y - 1; SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); } int wherex() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return info.dwCursorPosition.X; } int wherey() { CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); return info.dwCursorPosition.Y - 2; } That's the intro. Now the problem. I have this: import console; void main() { Console.io.write('hello'); Console.gotoxy(2,2); Console.io.write('world'\n); } But for some odd reason, DMD first processes the gotoxy function and then both write's. I mean, it first goes to (2,2) and then prints helloworld. What's wrong? I know that sometimes C stdout/in/err behaves weird (at least it has happened to me on Linux), so that might be the reason. If that's so, is it a good enough reason to get D own's stdout/in/err? ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17 |
March 21, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Carlos Santander B. wrote:
> This might be to Walter, but is related to your console utility. I've added
> this to Console:
>
> import console2;
> static void clear() { clrscr(); }
> static void gotoxy(int x,int y) { console2.gotoxy(x,y); }
> static void where (out int x,out int y) { x=wherex(); y=wherey(); }
>
> In console2 I have:
>
> void clrscr() {
> COORD coord;
> DWORD written;
> CONSOLE_SCREEN_BUFFER_INFO info;
> coord.X = 0;
> coord.Y = 0;
> GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
> FillConsoleOutputCharacterW (GetStdHandle(STD_OUTPUT_HANDLE), ' ',
> info.dwSize.X * info.dwSize.Y, coord, &written);
> gotoxy (1, 1);
> }
>
> void gotoxy(int x, int y) {
> COORD c;
> c.X = x - 1;
> c.Y = y - 1;
> SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
> }
>
> int wherex() {
> CONSOLE_SCREEN_BUFFER_INFO info;
> GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
> return info.dwCursorPosition.X;
> }
>
> int wherey() {
> CONSOLE_SCREEN_BUFFER_INFO info;
> GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
> return info.dwCursorPosition.Y - 2;
> }
>
> That's the intro. Now the problem. I have this:
>
> import console;
> void main() {
> Console.io.write('hello');
> Console.gotoxy(2,2);
> Console.io.write('world'\n);
> }
>
> But for some odd reason, DMD first processes the gotoxy function and then
> both write's. I mean, it first goes to (2,2) and then prints helloworld.
> What's wrong? I know that sometimes C stdout/in/err behaves weird (at least
> it has happened to me on Linux), so that might be the reason. If that's so,
> is it a good enough reason to get D own's stdout/in/err?
>
> -------------------------
> Carlos Santander
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17
>
>
It's probably buffering things. Replace the fwrite call in ConsoleStream.write with a WriteConsole call. Either that or just fflush(c.stdio.stdout) after the fwrite. Both should work.
|
March 21, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Does the console module have a buffer that it only prints out on deconstruction or when it gets to be a certain size? You should probably have gotoxy flush that buffer, if that's the case. In article <b5dl9s$2bgt$1@digitaldaemon.com>, Carlos Santander B. says... > >This might be to Walter, but is related to your console utility. I've added >this to Console: > >import console2; >static void clear() { clrscr(); } >static void gotoxy(int x,int y) { console2.gotoxy(x,y); } >static void where (out int x,out int y) { x=wherex(); y=wherey(); } > >In console2 I have: > >void clrscr() { > COORD coord; > DWORD written; > CONSOLE_SCREEN_BUFFER_INFO info; > coord.X = 0; > coord.Y = 0; > GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); > FillConsoleOutputCharacterW (GetStdHandle(STD_OUTPUT_HANDLE), ' ', > info.dwSize.X * info.dwSize.Y, coord, &written); > gotoxy (1, 1); >} > >void gotoxy(int x, int y) { > COORD c; > c.X = x - 1; > c.Y = y - 1; > SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); >} > >int wherex() { > CONSOLE_SCREEN_BUFFER_INFO info; > GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); > return info.dwCursorPosition.X; >} > >int wherey() { > CONSOLE_SCREEN_BUFFER_INFO info; > GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info); > return info.dwCursorPosition.Y - 2; >} > >That's the intro. Now the problem. I have this: > >import console; >void main() { > Console.io.write('hello'); > Console.gotoxy(2,2); > Console.io.write('world'\n); >} > >But for some odd reason, DMD first processes the gotoxy function and then >both write's. I mean, it first goes to (2,2) and then prints helloworld. >What's wrong? I know that sometimes C stdout/in/err behaves weird (at least >it has happened to me on Linux), so that might be the reason. If that's so, >is it a good enough reason to get D own's stdout/in/err? > >------------------------- >Carlos Santander > > >--- >Outgoing mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17 > > |
March 21, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | "Andy Friesen" <andy@ikagames.com> escribió en el mensaje news:b5dmaf$2c5d$1@digitaldaemon.com... | It's probably buffering things. Replace the fwrite call in | ConsoleStream.write with a WriteConsole call. Either that or just | fflush(c.stdio.stdout) after the fwrite. Both should work. | Thanks! fflush worked. ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17 |
March 21, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to eluusive | Incredible Idea ! But there are two not solved problems: 1) %5.0f -> How can I format the same type in diferent ways? - This could be easy added. 2) char[] s = 'This is not a number.'; format("I am printing a number here {%}") % s; Here appear not to be a error. But if you have many parameters, you could easily change the order, use a wrong var and another problems. The final problem is the formatting is not type safe at compile time. E.g: printf("This is a number %s", s); Some solution for this ? |
March 21, 2003 Re: String formatting stuff | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juarez Rudsatz | This is why putting the printed values after the format string isn't a good idea. It should be: int n=5; char[] s = "wow"; char c = '.'; char[] fmt = format("I am printing a number here ", n, " and then a string ", s, " and finally a period", c); But apparently printf rules, so why try anything else? Sean "Juarez Rudsatz" <Juarez_member@pathlink.com> wrote in message news:b5fdv1$nh2$1@digitaldaemon.com... > Incredible Idea ! > > But there are two not solved problems: > > 1) %5.0f -> How can I format the same type in diferent ways? - This could be easy added. > > 2) > char[] s = 'This is not a number.'; > format("I am printing a number here {%}") % s; > > Here appear not to be a error. But if you have many parameters, you could easily > change the order, use a wrong var and another problems. The final problem is the > formatting is not type safe at compile time. > E.g: printf("This is a number %s", s); > > Some solution for this ? |
Copyright © 1999-2021 by the D Language Foundation