www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.stdio.stderr

reply Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
It appears that std.stdio.stderr does not wor exactly as stdio stderr
does. In particular std.stdio.stderr.writef(=E2=80=A6) does not work as
fprintf(stderr=E2=80=A6) 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?

--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder ekiga.n=
et
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
Jun 10 2017
parent reply Antonio Corbi <acorbi ggmail.xml> writes:
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", "Edit source/app.d to start your project."); stderr.writefln("stderr: %s", "Edit source/app.d to start your project."); stderr.writefln("stderr: %s", "Edit source/app.d to start your project."); stderr.writefln("%s", ""); } ``` 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
Jun 10 2017
parent Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Sat, 2017-06-10 at 16:45 +0000, Antonio Corbi via Digitalmars-d-
learn wrote:
 [=E2=80=A6]
=20
 It seems to work for me with a dumb example:
[=E2=80=A6] 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. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 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
Jun 10 2017