On 11/04/17 10:30, Mark Morgan Lloyd via Lazarus wrote:
On 11/04/17 10:00, Henry Vermaak via Lazarus wrote:> On Tue, Apr 11,
2017 at 09:15:16AM +0000, Mark Morgan Lloyd via Lazarus wrote:>
Apologies if this is an FAQ.> > Is there an orthodox way that a Lazarus
program can very early on look at> how it's been started and decide
whether it can usefully fall back to a text> mode, e.g. to display help
info on stdout rather than a messagebox?> isatty() is traditionally used
for this on POSIX operating systems.It's in unit termio.
Thanks Henry, I'll check. I know I've used it in the past when deciding
whether a program was actually being fed piped input etc.
Something like this does appear to work, tested on Linux only.
function notGui(): boolean;
var i: integer;
begin
i := IsaTty(Input);
{$ifdef ISGUI }
exit false;
{$endif ISGUI }
{$ifdef NOGUI }
exit true;
{$endif NOGUI }
result := i <> 0
end { notGui } ;
The explicit overrides might be needed during debugging, since the
involvement of gdb forces the program to think it's being run from a
shell session.
Looking back through older sources, I've had to jump through hoops-
reopening the input and using GetFileType() under Windows- to find out
whether stdin was piped. Fortunately I don't need that here.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus-ide.org/listinfo/lazarus