diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Blessings.hs (renamed from src/Trammel.hs) | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/Trammel.hs b/src/Blessings.hs index d1abedb..753b560 100644 --- a/src/Trammel.hs +++ b/src/Blessings.hs @@ -1,30 +1,25 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE OverloadedLists #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE LambdaCase #-} -module Trammel where +{-# LANGUAGE RecordWildCards #-} + +module Blessings where import Control.Applicative import Data.List import Data.String -import Data.Monoid import Data.Ix (inRange) type Ps = Int type Pm = [Ps] -data Trammel a +data Blessings a = Plain a - | SGR Pm (Trammel a) - | Append (Trammel a) (Trammel a) + | SGR Pm (Blessings a) + | Append (Blessings a) (Blessings a) | Empty deriving (Eq, Show) -instance Functor Trammel where +instance Functor Blessings where fmap f = \case Append t1 t2 -> Append (fmap f t1) (fmap f t2) Plain s -> Plain (f s) @@ -32,12 +27,12 @@ instance Functor Trammel where Empty -> Empty -instance Monoid (Trammel a) where +instance Monoid (Blessings a) where mappend = Append mempty = Empty -instance IsString a => IsString (Trammel a) where +instance IsString a => IsString (Blessings a) where fromString = Plain . fromString @@ -178,7 +173,7 @@ type RenderState = [(FColor, BColor, Bold, Underline)] emptyRenderState :: RenderState emptyRenderState = [(ECMA48FColor 39, ECMA48BColor 49, NoBold, NoUnderline)] -renderString :: RenderState -> Trammel String -> String -> String +renderString :: RenderState -> Blessings String -> String -> String renderString _ (Plain s) y = s ++ y @@ -209,14 +204,14 @@ renderString r (Append t1 t2) y = renderString _ Empty y = y -len :: Trammel String -> Int +len :: Blessings String -> Int len (Plain x) = length x len (SGR _ x) = len x len (Append t1 t2) = len t1 + len t2 len Empty = 0 -pp :: Trammel String -> String +pp :: Blessings String -> String pp t = renderString emptyRenderState t "" @@ -225,31 +220,31 @@ renderSGR [] = [] renderSGR xs = ("\ESC["++) . (++"m") . intercalate ";" $ map show xs -trammelDrop :: Int -> Trammel String -> Trammel String -trammelDrop n = \case +blessingsDrop :: Int -> Blessings String -> Blessings String +blessingsDrop n = \case Append t1 t2 -> case compare n (len t1) of - LT -> Append (trammelDrop n t1) t2 + LT -> Append (blessingsDrop n t1) t2 EQ -> t2 - GT -> trammelDrop (n - len t1) t2 + GT -> blessingsDrop (n - len t1) t2 Plain s -> Plain (drop n s) SGR pm t -> - SGR pm (trammelDrop n t) + SGR pm (blessingsDrop n t) Empty -> Empty -trammelTake :: Int -> Trammel String -> Trammel String -trammelTake n = \case +blessingsTake :: Int -> Blessings String -> Blessings String +blessingsTake n = \case Append t1 t2 -> case compare n (len t1) of - LT -> trammelTake n t1 + LT -> blessingsTake n t1 EQ -> t1 - GT -> Append t1 (trammelTake (n - len t1) t2) + GT -> Append t1 (blessingsTake (n - len t1) t2) Plain s -> Plain (take n s) SGR pm t -> - SGR pm (trammelTake n t) + SGR pm (blessingsTake n t) Empty -> Empty |