[ANN] text-display 0.0.1.0: A typeclass for user-facing output

Hi everyone, I am proud to release the first version of text-display, a typeclass for user-facing output.

Display is a typeclass that doesn’t abide by the rules of Show & Read, and brings with it a nice and ergonomic way to derive instances through DerivingVia when they already have a Show instance:

{-# LANGUAGE DerivingVia #-}
data AutomaticallyDerived = AD
  -- We derive 'Show'
  deriving Show 
  -- We take advantage of the 'Show' instance to derive 'Display' from it
  deriving Display
    via (ShowInstance AutomaticallyDerived) 

But let’s say you want to redact an instance of Display? You can do it locally, through
the OpaqueInstance helper. It is most useful to hide tokens or passwords:

data UserToken = UserToken UUID                           
 deriving Display                                         
   via (OpaqueInstance "[REDACTED]" UserToken)            
                                                          
display $ UserToken "7a01d2ce-31ff-11ec-8c10-5405db82c3cd"
-- => "[REDACTED]"                                              

I hope you will have fun with this library! :rainbow:

19 Likes

Useful, usable, lovely unicode chars in the docs. Well done!

2 Likes

Thank you very much. :slight_smile:

Didn’t realize I was missing icons in haddock pages so much.

Also @Kleidukos , incidentally the other day I found a general pretty-printing library from Google GitHub - google/hs-portray which relies on DerivingVia like yours. Now we have even more standards to choose from ! \o/

1 Like

Ohh I hadn’t heard about that one! :slight_smile: Thank you @ocramz

The redaction capability is really nice!

@Kleidukos, putStrLn has issues, is this implementation also thread-safe, or how does it hold up to Haskell’s concurrency?

Yes it is very thread-safe. Especially due to the fact that it doesn’t do any IO. :slight_smile:

If you want thread-safe putStrLn, you should use the one in Data.ByteString.Char8.

1 Like