packages feed

irc-fun-color 0.2.0.0 → 0.2.1.0

raw patch · 6 files changed

+65/−24 lines, 6 files

Files

NEWS.md view
@@ -3,7 +3,31 @@   -irc-fun-color 0.2.0.0 -- unreleased+irc-fun-color 0.2.1.0 -- 2016-03-15+===================================++General, build and documentation changes:++* (None)++New APIs, features and enhancements:++* (None)++Bug fixes:++* Weird, `formatMsg` isn't exported in the Hackage release. Maybe I made some+  mistake while releasing. Anyway, this release should fix it.++Dependency changes:++* (None)++++++irc-fun-color 0.2.0.0 -- 2016-01-27 ===================================  General, build and documentation changes:
irc-fun-color.cabal view
@@ -1,5 +1,5 @@ name:                irc-fun-color-version:             0.2.0.0+version:             0.2.1.0 synopsis:            Add color and style decorations to IRC messages. description:   An extension to IRC allows text formatting to be encoded into a message.
src/Network/IRC/Fun/Color/Format.hs view
@@ -13,35 +13,44 @@  - <http://creativecommons.org/publicdomain/zero/1.0/>.  -} +-- | This module provides functions which insert values into format templates,+-- much like @printf@. They are simply the same ones found in "Formatting", but+-- with slightly different names which are more convenient when strict Text is+-- a package's default (e.g. in IRC related packages where strings are likely+-- short). Suggested usage:+--+-- > import Network.IRC.Fun.Color.Format+-- > import Formatting hiding (format, sformat)+--+-- You may wish to use some formatters as well:+--+-- > import Network.IRC.Fun.Color.Format+-- > import Network.IRC.Fun.Color.Format.Long+-- > import Formatting hiding (format, sformat, text, stext) module Network.IRC.Fun.Color.Format     ( format     , lformat+    , formatMsg     ) where -{--components:--- Format type-- format, lformat-- text, ltext-- printing into stdout or handle or connection? perhaps the latter should be-  in irc-fun-client, will also save the annoying MsgContent ctor everywhere,-  maybe also make MsgContent a Monoid instance?-- long formatters-- short formatters-- irc specific long formatters-- irc specific short formatters--}+import Formatting.Internal (Format (..))+import Network.IRC.Fun.Types.Base (MsgContent (..))  import qualified Data.Text as T (Text)-import qualified Data.Text.Lazy as TL (Text)+import qualified Data.Text.Lazy as TL (Text, toStrict)+import qualified Data.Text.Lazy.Builder as TLB (toLazyText) import qualified Formatting as F  -- | Run the formatter and return a strict 'T.Text' value. format :: F.Format T.Text a -> a format = F.sformat --- | Run the formatter and return a lazy 'LT.Text' value.+-- | Run the formatter and return a lazy 'TL.Text' value. lformat :: F.Format TL.Text a -> a lformat = F.format++-- | Run the formatter and return 'MsgContent', which is simply a wrapper of+-- strict 'T.Text'. This is s shortcut for @MsgContent . format@.+formatMsg :: F.Format MsgContent a -> a+formatMsg f = runFormat f $ MsgContent . TL.toStrict . TLB.toLazyText
src/Network/IRC/Fun/Color/Format/Long.hs view
@@ -13,6 +13,12 @@  - <http://creativecommons.org/publicdomain/zero/1.0/>.  -} +-- | This module provides formatters for use with "Formatting". Suggested+-- usage:+--+-- > import Network.IRC.Fun.Color.Format+-- > import Network.IRC.Fun.Color.Format.Long+-- > import Formatting hiding (format, sformat, text, stext) module Network.IRC.Fun.Color.Format.Long     ( text     , ltext
src/Network/IRC/Fun/Color/Format/Short.hs view
@@ -13,6 +13,8 @@  - <http://creativecommons.org/publicdomain/zero/1.0/>.  -} +-- | This module provides the same formatters as+-- "Network.IRC.Fun.Color.Format.Long", but with shorter names. module Network.IRC.Fun.Color.Format.Short     ( t     , lt
src/Network/IRC/Fun/Color/Style.hs view
@@ -103,7 +103,7 @@  import Data.Char (isDigit) import Data.Foldable (foldr)-import Data.List (intercalate, nub, sort)+import Data.List (nub) import Data.Monoid import Data.String (IsString (..)) import Formatting.Internal (Format (..))@@ -320,10 +320,10 @@  -- Apply decoration to a flat styled string applyDeco :: Decoration -> D.DList StyledChunk -> D.DList StyledChunk-applyDeco d = fmap h+applyDeco dec = fmap h     where     g ds d = if {-Plain `elem` ds ||-} d `elem` ds then ds else d : ds-    h (StyledChunk c ds s) = StyledChunk c (g ds d) s+    h (StyledChunk c ds s) = StyledChunk c (g ds dec) s  -- Tag the actual strings with all the hierarchically attached styles flatten :: StyledText -> D.DList StyledChunk@@ -338,7 +338,7 @@ protect t =     case T.uncons t of         Nothing     -> T.empty-        Just (d, r) ->+        Just (d, _) ->             if isDigit d                 then decoCode Bold `T.cons` decoCode Bold `T.cons` t                 else t@@ -354,9 +354,9 @@  -- | Convert a styled string value into an IRC style-coded text message. encode :: StyledText -> T.Text-encode = foldr (\ sc t -> f sc <> t) T.empty . flatten+encode = foldr (\ sc t -> g sc <> t) T.empty . flatten     where-    f (StyledChunk (FgBg f b) ds s) = encodeDeco ds $ encodeColor f b s+    g (StyledChunk (FgBg f b) ds s) = encodeDeco ds $ encodeColor f b s  -- | Remove style from a string, returning just the content. strip :: StyledText -> T.Text