brick/programs/BorderDemo.hs
Jonathan Daugherty 35aa2ad8a4 Monster patch: move most data types to Brick.Types, remove IsString
instance for Widget

- This makes the module layout more predictable since Brick.Widgets.Core
  now (mostly) only contains widgets and widget transformations
- Utility functions closely related to types are now in Brick.Types
- Brick.Types.Internal contains types used internal by the renderer,
  some are re-exported by Brick.Types
2015-08-19 19:40:06 -07:00

99 lines
2.5 KiB
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative ((<$>))
import Data.Monoid
import qualified Data.Text as T
import qualified Graphics.Vty as V
import qualified Brick.Main as M
import Brick.Util (fg, bg, on)
import qualified Brick.AttrMap as A
import Brick.Types
( Widget
)
import Brick.Widgets.Core
( (<=>)
, (<+>)
, vLimit
, hLimit
, hBox
, updateAttrMap
, withBorderStyle
, txt
, str
)
import qualified Brick.Widgets.Center as C
import qualified Brick.Widgets.Border as B
import qualified Brick.Widgets.Border.Style as BS
styles :: [(T.Text, BS.BorderStyle)]
styles =
[ ("ascii", BS.ascii)
, ("unicode", BS.unicode)
, ("unicode bold", BS.unicodeBold)
, ("unicode rounded", BS.unicodeRounded)
, ("custom", custom)
, ("from 'x'", BS.borderStyleFromChar 'x')
]
custom :: BS.BorderStyle
custom =
BS.BorderStyle { BS.bsCornerTL = '/'
, BS.bsCornerTR = '\\'
, BS.bsCornerBR = '/'
, BS.bsCornerBL = '\\'
, BS.bsIntersectFull = '.'
, BS.bsIntersectL = '.'
, BS.bsIntersectR = '.'
, BS.bsIntersectT = '.'
, BS.bsIntersectB = '.'
, BS.bsHorizontal = '*'
, BS.bsVertical = '!'
}
borderDemos :: [Widget]
borderDemos = mkBorderDemo <$> styles
mkBorderDemo :: (T.Text, BS.BorderStyle) -> Widget
mkBorderDemo (styleName, sty) =
withBorderStyle sty $
B.borderWithLabel (str "label") $
vLimit 5 $
C.vCenter $
txt $ " " <> styleName <> " style "
borderMappings :: [(A.AttrName, V.Attr)]
borderMappings =
[ (B.borderAttr, V.yellow `on` V.black)
, (B.vBorderAttr, V.green `on` V.red)
, (B.hBorderAttr, V.white `on` V.green)
, (B.hBorderLabelAttr, fg V.blue)
, (B.tlCornerAttr, bg V.red)
, (B.trCornerAttr, bg V.blue)
, (B.blCornerAttr, bg V.yellow)
, (B.brCornerAttr, bg V.green)
]
colorDemo :: Widget
colorDemo =
updateAttrMap (A.applyAttrMappings borderMappings) $
B.borderWithLabel (str "title") $
hLimit 20 $
vLimit 5 $
C.center $
str "colors!"
ui :: Widget
ui =
hBox borderDemos
<=> B.hBorder
<=> colorDemo
<=> B.hBorderWithLabel (str "horizontal border label")
<=> (C.center (str "Left of vertical border")
<+> B.vBorder
<+> C.center (str "Right of vertical border"))
main :: IO ()
main = M.simpleMain ui