module Text.Layout.Table.Spec.AlignSpec
    ( AlignSpec(..)
    , noAlign
    , occSpecAlign
    , predAlign
    , charAlign
    ) where

import Data.Default.Class

import Text.Layout.Table.Spec.OccSpec

-- | Determines whether a column will align at a specific letter.
data AlignSpec
    = AlignOcc OccSpec
    | NoAlign

-- | No alignment is the default.
instance Default AlignSpec where
    def :: AlignSpec
def = AlignSpec
noAlign

-- | Do not align text.
noAlign :: AlignSpec
noAlign :: AlignSpec
noAlign = AlignSpec
NoAlign

-- | Construct an 'AlignSpec' by giving an occurence specification.
occSpecAlign :: OccSpec -> AlignSpec
occSpecAlign :: OccSpec -> AlignSpec
occSpecAlign = OccSpec -> AlignSpec
AlignOcc

-- | Align text at the first match of a predicate.
predAlign :: (Char -> Bool) -> AlignSpec
predAlign :: (Char -> Bool) -> AlignSpec
predAlign = OccSpec -> AlignSpec
occSpecAlign (OccSpec -> AlignSpec)
-> ((Char -> Bool) -> OccSpec) -> (Char -> Bool) -> AlignSpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> OccSpec
predOccSpec

-- | Align text at the first occurence of a given 'Char'.
charAlign :: Char -> AlignSpec
charAlign :: Char -> AlignSpec
charAlign = (Char -> Bool) -> AlignSpec
predAlign ((Char -> Bool) -> AlignSpec)
-> (Char -> Char -> Bool) -> Char -> AlignSpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
(==)