Thread overview | |||||
---|---|---|---|---|---|
|
June 10, 2017 std.stdio.stderr | ||||
---|---|---|---|---|
| ||||
Attachments:
| It appears that std.stdio.stderr does not wor exactly as stdio stderr
does. In particular std.stdio.stderr.writef(…) does not work as
fprintf(stderr…) does.
Some code I am porting from C++ to D makes use of ANSI escape codes to go up a line and overwrite what was there, as well as change colours. This work fine in the C++ code but fails in the D code. The codes are definitely all the same, the only difference is in the writing functions.
Is this problem to be expected or should it work?
--
Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
|
June 10, 2017 Re: std.stdio.stderr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Saturday, 10 June 2017 at 16:10:18 UTC, Russel Winder wrote:
> It appears that std.stdio.stderr does not wor exactly as stdio stderr
> does. In particular std.stdio.stderr.writef(…) does not work as
> fprintf(stderr…) does.
>
> Some code I am porting from C++ to D makes use of ANSI escape codes to go up a line and overwrite what was there, as well as change colours. This work fine in the C++ code but fails in the D code. The codes are definitely all the same, the only difference is in the writing functions.
>
> Is this problem to be expected or should it work?
Hi Russel,
It seems to work for me with a dumb example:
```
import std.stdio;
void main()
{
writefln("stdout: %s", "[7m[1mEdit source/app.d to start your project.[0m");
stderr.writefln("stderr: %s", "[7m[1mEdit source/app.d to start your project.[0m");
stderr.writefln("stderr: %s", "[0;31m[1mEdit source/app.d to start your project.[0m");
stderr.writefln("%s", "[1A[12C[K");
}
```
Before copy/paste take into account that in sequences like "[7m", etc... there's a hidden ESC char at the beginning, something like: "\033[7m", and I can't see it in the preview of my posting.
Antonio
|
June 10, 2017 Re: std.stdio.stderr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Antonio Corbi Attachments:
| On Sat, 2017-06-10 at 16:45 +0000, Antonio Corbi via Digitalmars-d- learn wrote: > […] > > It seems to work for me with a dumb example: […] Spurred on by your report of success, I discovered my error. D treats a char[1024] as 1024 characters when using the %s format specifier. I had to use fromStringz using a cast to get the %s to get the null terminated string. The problems of idiomatic C code (crap) converted to D code (good, but with hacks). Thanks for your reply, it was most helpful. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
Copyright © 1999-2021 by the D Language Foundation