cdepillabout / cdepillabout/pretty-simple

add tests to make sure tty detection works

Open
#48 2 comments 0 reactions 0 assignees View on GitHub
beginner-friendly enhancement help wanted
Dominant language
Haskell
Stars
260
Forks
30
PR merge metrics
No merged PRs in 30d

Description

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:

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 a `Handle`:

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` and `slave` PTY `FD`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` or `hspec`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.