You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #47 changes functions like pPrint so that they check whether the output Handle is a TTY device or not. If it is not, then outputting in color is disabled by default. (Thanks @metiulekm!)
This works well, but it would be nice to have tests to make sure that outputting in color is getting enabled/disabled when it should.
Basically, the tests should open a pseudo terminal and try outputting to it with a function like pHPrint. The tests should also try opening a normal file and outputting to it with the same function. The tests should check that when outputting to a PTY, the output is in color, but when outputting to a normal file, output is not in color.
I'm not too familiar with how PTY works on Linux. It looks like there is a function for opening a PTY:
I added a beginner-friendly label to this issue, since the Haskell code you have to write should be relatively simple. However, figuring how to to write to and read from a PTY might be a little complex.
FWIW, pPrint currently doesn't use colour when invoked from a test suite with cabal test. pPrintOpt NoCheckColorTty defaultOutputOptionsDarkBg works successfully, so it would be nice if the library detected that it's possible.
Perhaps some relevant info here, though the story seems to have improved with cabal 3.
PR #47 changes functions like
pPrint
so that they check whether the outputHandle
is a TTY device or not. If it is not, then outputting in color is disabled by default. (Thanks @metiulekm!)This works well, but it would be nice to have tests to make sure that outputting in color is getting enabled/disabled when it should.
Basically, the tests should open a pseudo terminal and try outputting to it with a function like
pHPrint
. The tests should also try opening a normal file and outputting to it with the same function. The tests should check that when outputting to a PTY, the output is in color, but when outputting to a normal file, output is not in color.I'm not too familiar with how PTY works on Linux. It looks like there is a function for opening a PTY:
http://hackage.haskell.org/package/unix-2.7.2.2/docs/System-Posix-Terminal.html#v:openPseudoTerminal
As well as a function for converting an
FD
to aHandle
:http://hackage.haskell.org/package/unix-2.7.2.2/docs/System-Posix-IO.html#v:fdToHandle
However, I'm not sure how to use the
master
andslave
PTYFD
s.This book apparently has a description of how to use PTYs in chapter 64:
https://nostarch.com/tlpi
Currently there is no test suite for unit tests in pretty-simple, so you'll have to add one. I suggest using
tasty
orhspec
.The text was updated successfully, but these errors were encountered: