mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-29 08:55:13 +03:00
Add demonstration program for borders
This commit is contained in:
parent
4b679d1fad
commit
ffbf2d89c6
12
brick.cabal
12
brick.cabal
@ -82,6 +82,18 @@ executable brick-minimal
|
||||
text,
|
||||
lens
|
||||
|
||||
executable brick-border-demo
|
||||
hs-source-dirs: programs
|
||||
ghc-options: -threaded -Wall -fno-warn-unused-do-bind
|
||||
default-language: Haskell2010
|
||||
main-is: BorderDemo.hs
|
||||
build-depends: base,
|
||||
brick,
|
||||
vty >= 5.2.9,
|
||||
data-default,
|
||||
text,
|
||||
lens
|
||||
|
||||
executable brick-rogue
|
||||
hs-source-dirs: programs
|
||||
ghc-options: -threaded -Wall -fno-warn-unused-do-bind
|
||||
|
61
programs/BorderDemo.hs
Normal file
61
programs/BorderDemo.hs
Normal file
@ -0,0 +1,61 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main where
|
||||
|
||||
import Control.Applicative ((<$>))
|
||||
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)
|
||||
]
|
||||
|
||||
borderDemos :: [Widget]
|
||||
borderDemos = mkBorderDemo <$> styles
|
||||
|
||||
mkBorderDemo :: (T.Text, BorderStyle) -> Widget
|
||||
mkBorderDemo (styleName, sty) =
|
||||
withBorderStyle sty $
|
||||
border $
|
||||
hLimit 20 $
|
||||
vLimit 5 $
|
||||
center $
|
||||
txt styleName
|
||||
|
||||
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 =
|
||||
withAttrMappings borderMappings $
|
||||
borderWithLabel "title" $
|
||||
hLimit 20 $
|
||||
vLimit 5 $
|
||||
center $
|
||||
"body"
|
||||
|
||||
ui :: [Widget]
|
||||
ui = [hBox borderDemos <=> colorDemo]
|
||||
|
||||
main :: IO ()
|
||||
main = simpleMain [] ui
|
Loading…
Reference in New Issue
Block a user