{-# LANGUAGE FlexibleInstances #-}

module Options.Applicative.Help.Ann (
  Ann(..),
  CanAnnotate(..)
  ) where

import Prettyprinter (Doc, annotate)
import Options.Applicative.Help.Style

data Ann
  = AnnTrace Int String
  | AnnStyle SetStyle
  deriving (Ann -> Ann -> Bool
(Ann -> Ann -> Bool) -> (Ann -> Ann -> Bool) -> Eq Ann
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ann -> Ann -> Bool
$c/= :: Ann -> Ann -> Bool
== :: Ann -> Ann -> Bool
$c== :: Ann -> Ann -> Bool
Eq, Int -> Ann -> ShowS
[Ann] -> ShowS
Ann -> String
(Int -> Ann -> ShowS)
-> (Ann -> String) -> ([Ann] -> ShowS) -> Show Ann
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ann] -> ShowS
$cshowList :: [Ann] -> ShowS
show :: Ann -> String
$cshow :: Ann -> String
showsPrec :: Int -> Ann -> ShowS
$cshowsPrec :: Int -> Ann -> ShowS
Show)

class CanAnnotate a where
  -- | Annotate trace a value
  annTrace
    :: Int      -- ^ Trace level
    -> String   -- ^ Trace message
    -> a        -- ^ Value to be traced
    -> a        -- ^ The traced value

instance CanAnnotate (Doc Ann) where
  annTrace :: Int -> String -> Doc Ann -> Doc Ann
annTrace Int
n = Ann -> Doc Ann -> Doc Ann
forall ann. ann -> Doc ann -> Doc ann
annotate (Ann -> Doc Ann -> Doc Ann)
-> (String -> Ann) -> String -> Doc Ann -> Doc Ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> Ann
AnnTrace Int
n