1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid ((<>))
#endif
import qualified Data.Text as T
import qualified Graphics.Vty as V
import qualified Brick.Main as M
import Brick.Util (fg, on)
import qualified Brick.AttrMap as A
import Brick.Types
( Widget
)
import Brick.Widgets.Core
( (<+>)
, withAttr
, vLimit
, hLimit
, hBox
, vBox
, updateAttrMap
, withBorderStyle
, txt
, str
, padLeftRight
)
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 $
padLeftRight 2 $
txt $ styleName <> " style"
titleAttr :: A.AttrName
titleAttr = A.attrName "title"
attrs :: [(A.AttrName, V.Attr)]
attrs =
[ (B.borderAttr, V.yellow `on` V.black)
, (B.vBorderAttr, fg V.cyan)
, (B.hBorderAttr, fg V.magenta)
, (titleAttr, fg V.cyan)
]
colorDemo :: Widget ()
colorDemo =
updateAttrMap (A.applyAttrMappings attrs) $
B.borderWithLabel (withAttr titleAttr $ str "title") $
hLimit 20 $
vLimit 5 $
C.center $
str "colors!"
ui :: Widget ()
ui =
vBox [ 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
|