diff options
author | tv <tv@shackspace.de> | 2015-10-17 00:49:51 +0200 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-10-17 01:50:27 +0200 |
commit | 5e9e4888aaf6380383dd07dc9a8d348dc5b875d0 (patch) | |
tree | c75152edb798d4c2a68bf005c8b0a784ecb6ca50 /src | |
parent | b649c9a6c2d83b291d836623ebf96136a79f9601 (diff) |
rename Trammel to Blessings
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 |