isatty and Pavel stream.d
Georg Wrede
georg.wrede at iki.fi
Sun May 3 09:06:18 PDT 2009
Carlos Smith wrote:
>
> "Jarrett Billingsley" <jarrett.billingsley at gmail.com> a écrit dans le
> message de >
>> extern(C) int isatty(int);
>>
>> And you should be able to use it. You shouldn't get any linking
>> errors, at least I don't think.
>
> It worked fine.no link error.
>
> isatty is sometimes used like this: isatty(fileno(fp))
> So i used fileno(), whis is declared in std.c.stdio.
> but i got a linking error:
> _fileno not found.
Assuming you only want to know if the program is used on a console, or
if input, output, or error are redirected, then this helps:
import std.stdio;
extern(C) int isatty(int);
void main()
{
writeln("input from tty is ", isatty(0)?"true":"false");
writeln("output to tty is ", isatty(1)?"true":"false");
writeln("error to tty is ", isatty(2)?"true":"false");
}
> I tried two other function in std.c.stdio to see if
> this was causes by some other factor i am not awared of.
>
> clearerr() and rewind() works just fine.
>
> So may be there is a problem with fileno() ??
>
>> You mean std.stream? That's been part of Phobos .. well, forever. At
>> least 5 years anyway.
>
> No, i mean the stream.d that comes in stream.zip from the
> Pavel's site: http://int19h.tamb.ru/files/stream.zip
> His stream library seems different. as, it have functions to
> read Unicode strings from the console. I tried to compile
> it with dmd 1.043 but there are many errors.
>
>>
>>> This library seems to allow reading utf-8 from a windows console.
>>>
>>> With dmd 1.043, it's very easy to write utf string to console. But,
>>> how do
>>> we readln from the console ?
>>
>
>>> std.stdio.readln
>
> I know that function. But it allows to read
> char[] arrays only. (if i read well the declarations).
>
> How do i read wchar[] arrays from the console with it ?
>
> As i said, it's real easy to write unicode strings
> to the console. But, it seems a lot less easier
> to read unicode from the console.
>
> Am i right ?
As posted in recent thread "How-to: input/output "Japanese Caracters",
all you have to do with Unicode is simply to use readln and writeln.
They have been Unicode-proof since a bunch of years back.
More information about the Digitalmars-d-learn
mailing list