ghc - How to reliably determine if a Handle is a terminal in Haskell? -


i using system.io.histerminaldevice determine if handle terminal , apply colorization if case. noticed when forking process using createpipe stream new process stdin , stdout, function returns true seems wrong answer: pipe should not considered terminal. have tried track down issue looking @ system.io , system.posix.io source code ends in c pipe function , lead me nowhere.

is there better way tell if handle terminal? or doing wrong?

update

here 2 programs supposed expose behaviour observed:

import           control.monad import           system.io import           system.process  main =   (in_, out, err, h) <-  createprocess $ (proc "./test2" [])                                    { std_in = createpipe                                    , std_err = createpipe                                    , std_out = createpipe }   dump out       dump h = forever $       ln <- hgetline h       putstrln ln 

then `test2 :

import           system.io  main =   print =<< histerminaldevice stderr   print =<< histerminaldevice stdout   print =<< histerminaldevice stdin 

then running first program:

$ ./test false false false 

i know what's happening: forking not program docker container! , explicitly add -t parameter allocates tty container...

do have minimal example illustrate problem? following program prints "false" twice, suggesting handles created createpipe not misidentified terminal devices:

import system.process import system.io  main = (just in_, out, err, h) <-             createprocess $ (shell "cat") { std_in = createpipe,                                             std_out = createpipe }           print =<< histerminaldevice in_           print =<< histerminaldevice out 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -