-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] make running without colour possible
- Loading branch information
Showing
4 changed files
with
112 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Effectful.Pretty (Pretty (..), pwetty, uwu, owo, runPrettyColoured, runPrettyBland) where | ||
|
||
import Data.Kind (Type) | ||
import Data.Text (Text) | ||
import Data.Text.IO qualified as T | ||
import Data.Vector (Vector) | ||
import Effectful | ||
import Effectful.Dispatch.Dynamic (interpret, send) | ||
import System.IO (Handle, stderr, stdout) | ||
|
||
pwetty :: Pretty spec :> es => Handle -> Vector (spec, Text) -> Eff es () | ||
pwetty hdl line = send $ PrettyLine hdl line | ||
|
||
owo :: Pretty spec :> es => Vector (spec, Text) -> Eff es () | ||
owo = pwetty stderr | ||
|
||
uwu :: Pretty spec :> es => Vector (spec, Text) -> Eff es () | ||
uwu = pwetty stdout | ||
|
||
type Pretty :: Type -> Effect | ||
data Pretty spec m r where | ||
PrettyLine :: Handle -> Vector (spec, Text) -> Pretty spec m () | ||
|
||
type instance DispatchOf (Pretty spec) = Dynamic | ||
|
||
runPrettyColoured :: IOE :> es => (spec -> Text -> Text) -> Eff (Pretty spec : es) a -> Eff es a | ||
runPrettyColoured colour = interpret \_ -> \case | ||
PrettyLine hdl txt -> liftIO $ T.hPutStrLn hdl $ uncurry colour `foldMap` txt | ||
|
||
runPrettyBland :: IOE :> es => Eff (Pretty spec : es) a -> Eff es a | ||
runPrettyBland = interpret \_ -> \case | ||
PrettyLine hdl txt -> liftIO $ T.hPutStrLn hdl $ foldMap snd txt |