module Brick.Util
( clamp
, on
, fg
, bg
, clOffset
)
where
import Lens.Micro ((&), (%~))
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid ((<>))
#endif
import Graphics.Vty
import Brick.Types.Internal (Location(..), CursorLocation(..), cursorLocationL)
clamp :: (Ord a)
=> a
-> a
-> a
-> a
clamp :: a -> a -> a -> a
clamp a
mn a
mx a
val = a -> a -> a
forall a. Ord a => a -> a -> a
max a
mn (a -> a -> a
forall a. Ord a => a -> a -> a
min a
val a
mx)
on :: Color
-> Color
-> Attr
on :: Color -> Color -> Attr
on Color
f Color
b = Attr
defAttr Attr -> Color -> Attr
`withForeColor` Color
f
Attr -> Color -> Attr
`withBackColor` Color
b
fg :: Color -> Attr
fg :: Color -> Attr
fg = (Attr
defAttr Attr -> Color -> Attr
`withForeColor`)
bg :: Color -> Attr
bg :: Color -> Attr
bg = (Attr
defAttr Attr -> Color -> Attr
`withBackColor`)
clOffset :: CursorLocation n -> Location -> CursorLocation n
clOffset :: CursorLocation n -> Location -> CursorLocation n
clOffset CursorLocation n
cl Location
off = CursorLocation n
cl CursorLocation n
-> (CursorLocation n -> CursorLocation n) -> CursorLocation n
forall a b. a -> (a -> b) -> b
& (Location -> Identity Location)
-> CursorLocation n -> Identity (CursorLocation n)
forall n. Lens' (CursorLocation n) Location
cursorLocationL ((Location -> Identity Location)
-> CursorLocation n -> Identity (CursorLocation n))
-> (Location -> Location) -> CursorLocation n -> CursorLocation n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Location -> Location -> Location
forall a. Semigroup a => a -> a -> a
<> Location
off)