rasa-ext-style (empty) → 0.1.0.0
raw patch · 4 files changed
+143/−0 lines, 4 filesdep +basedep +data-defaultdep +lenssetup-changed
Dependencies added: base, data-default, lens, rasa
Files
- LICENSE +21/−0
- Setup.hs +2/−0
- rasa-ext-style.cabal +30/−0
- src/Rasa/Ext/Style.hs +90/−0
+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License++Copyright (c) 2016 Chris Penner++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ rasa-ext-style.cabal view
@@ -0,0 +1,30 @@+name: rasa-ext-style+version: 0.1.0.0+synopsis: Rasa Ext managing rendering styles+description: Rasa Ext managing rendering styles+homepage: https://github.com/ChrisPenner/rasa/+license: MIT+license-file: LICENSE+author: Chris Penner+maintainer: christopher.penner@gmail.com+copyright: 2016 Chris Penner+category: Extension+build-type: Simple+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Rasa.Ext.Style+ build-depends: base >= 4.7 && < 5+ , rasa+ , lens+ , data-default+ default-language: Haskell2010++ default-extensions:++ ghc-options: -Wall++source-repository head+ type: git+ location: https://github.com/ChrisPenner/rasa
+ src/Rasa/Ext/Style.hs view
@@ -0,0 +1,90 @@+{-# language TemplateHaskell #-}+module Rasa.Ext.Style (style, styles, addStyle, fg, bg, flair, Color(..), Flair(..), Style(..)) where++import Rasa.Ext+import Control.Lens++import Data.Default+import Control.Applicative++-- | These represent the possible colors for 'fg' or 'bg'.+-- 'DefColor' represents the terminal's default color.+data Color =+ Black+ | Red+ | Green+ | Yellow+ | Blue+ | Magenta+ | Cyan+ | White+ | DefColor+ deriving (Show, Eq)++-- | These represent the possible extra attributes which may be applied.+-- 'DefFlair' represents the terminal's default text attributes.+data Flair =+ Standout+ | Underline+ | ReverseVideo+ | Blink+ | Dim+ | Bold+ | DefFlair+ deriving (Show, Eq)++-- | A container which holds a foreground color, background color, and a flair.+-- a 'Nothing' represents that we should not change that attribute.+newtype Style = Style (Maybe Color, Maybe Color, Maybe Flair)+ deriving (Show, Eq)++instance Default Style where+ def = Style (Just DefColor, Just DefColor, Just DefFlair)++-- | The monoid instance replaces any attributes which have a 'Just' in the new 'Style'+-- and persists any that are 'Nothing' in the new style (using 'Data.Alternative' for 'Data.Maybe')+instance Monoid Style where+ Style (a, b, c) `mappend` Style (a', b', c') = Style (a' <|> a, b' <|> b, c' <|> c)++ mempty = Style (Nothing, Nothing, Nothing)++newtype Styles =+ Styles {+ -- This list must always stay sorted by the index of the styles+ _styles' :: [Span Style]+ } deriving (Show, Eq)++makeLenses ''Styles++-- | A lens over the styles stored in the current buffer.+styles :: Lens' Buffer [Span Style]+styles = bufExt.styles'++instance Default Styles where+ def = Styles []++-- | Create a new 'Style' with the given 'Color' as the foreground.+fg :: Color -> Style+fg a = Style (Just a, Nothing, Nothing)++-- | Create a new 'Style' with the given 'Color' as the background.+bg :: Color -> Style+bg a = Style (Nothing, Just a, Nothing)++-- Create a new 'Style' with the given 'Flair' as its flair.+flair :: Flair -> Style+flair a = Style (Nothing, Nothing, Just a)++-- | Applies a style over a given range in the buffer's style list.+addStyle :: Range -> Style -> BufAction ()+addStyle r st = styles %= (Span r st:)++-- | The main export for the style extension. Add this to your user config.+--+-- e.g.+--+-- > rasa [...] $ do+-- > style+-- > ...+style :: Scheduler ()+style = afterRender $ bufDo $ styles .= []