brick/programs/BorderDemo.hs

86 lines
2.1 KiB
Haskell

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