module Summoner.Tui.Widget
( label
, borderLabel
, borderName
, hArrange
, listInBorder
) where
import Brick.Types (Padding (Pad), Widget)
import Brick.Widgets.Border (borderWithLabel)
import Brick.Widgets.Center (center)
import Brick.Widgets.Core (hBox, hLimit, padLeftRight, padRight, str, txtWrap, vBox, vLimit,
withAttr, (<+>))
label :: String -> Widget n -> Widget n
label l = (<+>) (str l)
borderLabel :: String -> Widget n -> Widget n
borderLabel l = borderWithLabel (borderName l)
borderName :: String -> Widget n
borderName l = str "╼" <+> padLeftRight 1 (str l) <+> str "╾"
hArrange :: [Widget n] -> Widget n
hArrange = hBox . updateHead (padRight (Pad 2))
where
updateHead :: (a -> a) -> [a] -> [a]
updateHead _ [] = []
updateHead f (a : as) = f a : as
listInBorder
:: String
-> Int
-> Int
-> [Text]
-> Widget n
listInBorder name limitH extraLimitV list = center
$ hLimit limitH
$ vLimit (length list + 4 + extraLimitV)
$ borderLabel name
$ center
$ vBox
$ map (withAttr "blue-fg" . txtWrap . ("➤ " <>)) list