File: README.md

package info (click to toggle)
haskell-silently 1.2.5.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 76 kB
  • sloc: haskell: 125; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[![Hackage version](https://img.shields.io/hackage/v/silently.svg?label=Hackage&color=informational)](http://hackage.haskell.org/package/silently)
[![silently on Stackage Nightly](https://stackage.org/package/silently/badge/nightly)](https://stackage.org/nightly/package/silently)
[![Stackage LTS version](https://www.stackage.org/package/silently/badge/lts?label=Stackage)](https://www.stackage.org/package/silently)
[![Cabal build](https://github.com/hspec/silently/workflows/Haskell-CI/badge.svg)](https://github.com/hspec/silently/actions)

# silently

Silently is a package that allows you to run an `IO` action and
prevent it from writing to `stdout`, or any other handle, by using
`silence`. Or you can capture the output for yourself using `capture`.

For example, the program
```haskell
 import System.IO.Silently

 main = do
   putStr "putStrLn: " >> putStrLn "puppies!"
   putStr "silenced: " >> silence (putStrLn "kittens!")
   putStrLn ""
   (captured, result) <- capture (putStr "wookies!" >> return 123)
   putStr "captured: " >> putStrLn captured
   putStr "returned: " >> putStrLn (show result)
```
will print:
```
 putStrLn: puppies!
 silenced:
 captured: wookies!
 returned: 123
```

## Limitations

Capturing/silencing might not work as expected if the action uses the FFI
or conceals output under `unsafePerformIO` or similar unsafe operations.

Examples:
- FFI: https://github.com/hspec/silently/issues/3
- `unsafePerformIO`: https://github.com/bos/filemanip/issues/22