I had run across that exact discussion (GetConsoleMode and
GetConsoleScreenBufferInfo) and compiled a quick test. It always returns
"not console" when running under either of tcc|cmd|mintty
> See what this returns, though I'm wondering if it will need a catch around it. I don't have twapi installed anywhere right now, so can't test it. I don't know which of the options to pass would be best.
>
> puts "[get_console_screen_buffer_info [get_standard_handle stdout] -all]"
>
tcc/cmd give the following:
C:\Users\imdave>tclsh isatty.tcl
Q:-size {80 300} -cursorpos {0 24} -maxwindowsize {80 85}
-windowlocation {0 0 7
9 24} -windowpos {0 0} -windowsize {80 25} -textattr {-fggray 1}
pipe/file: 15 HANDLE ne 11 HANDLE
mintty (msys2) throws an error:
$ /c/Program\ Files/Tcl/bin/tclsh isatty.tcl
The handle is invalid.
while executing
"GetConsoleScreenBufferInfo $conh"
(procedure "twapi::_get_console_screen_buffer_info" line 13)
invoked from within
"twapi::_get_console_screen_buffer_info {528 HANDLE} -all"
("uplevel" body line 1)
invoked from within
"uplevel 1 [list $proc] $args"
-----
This is starting to become a windows API question...
I cobbled together (using win/tclWinFile.c as an example):
hnd = GetStdHandle ( STD_OUTPUT_HANDLE );
type = GetFileType( hnd );
switch( type ) {
case FILE_TYPE_CHAR:
fprintf( stderr, "FILE_TYPE_CHAR\n" );
:
That >does< work for tcc/cmd but fails for mintty (which always returns
FILE_TYPE_PIPE
I did run across bug reports/discussions from late 2016 that were
talking about problems with _istty() in mingw/msys/cygwin(maybe). The
discussions got too deep and/or detailed for me to extract a correct method.
I also think I read that mintty uses pipes for console output -- which
is exactly what the above code reports.
So this boils down to the internals of the "terminal" program which I
doubt tcl/twapi/etc. will be able to really distinguish.
Interestingly, msys2's bash's test -t >does< work properly with
mintty|cmd|tcc. I guess I'll have to try to find the source for either
bash or test to see how it's done.