{-# LANGUAGE DeriveFunctor #-}
module Text.Layout.Table.Cell.Formatted
( Formatted
, formatted
, plain
) where
import Data.String
import Text.Layout.Table.Cell
import Text.Layout.Table.StringBuilder
data Formatted a
= Formatted
{ prefix :: String
, content :: a
, suffix :: String
} deriving Functor
plain :: a -> Formatted a
plain x = Formatted "" x ""
formatted
:: String
-> a
-> String
-> Formatted a
formatted = Formatted
instance IsString a => IsString (Formatted a) where
fromString = plain . fromString
instance Cell a => Cell (Formatted a) where
dropLeft i = fmap $ dropLeft i
dropRight i = fmap $ dropRight i
dropBoth l r = fmap $ dropBoth l r
visibleLength = visibleLength . content
measureAlignment p = measureAlignment p . content
buildCell h = stringB (prefix h) <> buildCell (content h) <> stringB (suffix h)