module Brick.Types.Internal
( ScrollRequest(..)
, VisibilityRequest(..)
, vrPositionL
, vrSizeL
, Name(..)
, Location(..)
, locL
, origin
, TerminalLocation(..)
, Viewport(..)
, ViewportType(..)
, RenderState(..)
, Direction(..)
, CursorLocation(..)
, cursorLocationL
, cursorLocationNameL
, Context(..)
, EventState
, Next(..)
, scrollRequestsL
, viewportMapL
, vpSize
, vpLeft
, vpTop
)
where
import Control.Lens (Field1, Field2, _1, _2, Lens', makeLenses)
import Data.String
import Data.Monoid
import qualified Data.Map as M
import Graphics.Vty (DisplayRegion)
import Brick.Types.TH
import Brick.AttrMap (AttrName, AttrMap)
import Brick.Widgets.Border.Style (BorderStyle)
newtype Name = Name String
deriving (Eq, Show, Ord)
instance IsString Name where
fromString = Name
data RenderState =
RS { viewportMap :: M.Map Name Viewport
, scrollRequests :: [(Name, ScrollRequest)]
}
data ScrollRequest = HScrollBy Int
| HScrollPage Direction
| HScrollToBeginning
| HScrollToEnd
| VScrollBy Int
| VScrollPage Direction
| VScrollToBeginning
| VScrollToEnd
data VisibilityRequest =
VR { vrPosition :: Location
, vrSize :: DisplayRegion
}
deriving Show
data Viewport =
VP { _vpLeft :: Int
, _vpTop :: Int
, _vpSize :: DisplayRegion
}
deriving Show
data ViewportType = Vertical
| Horizontal
| Both
deriving Show
type EventState = [(Name, ScrollRequest)]
data Next a = Continue a
| SuspendAndResume (IO a)
| Halt a
data Direction = Up
| Down
data Location = Location { loc :: (Int, Int)
}
deriving Show
suffixLenses ''Location
instance Field1 Location Location Int Int where
_1 = locL._1
instance Field2 Location Location Int Int where
_2 = locL._2
class TerminalLocation a where
columnL :: Lens' a Int
column :: a -> Int
rowL :: Lens' a Int
row :: a -> Int
instance TerminalLocation Location where
columnL = _1
column (Location t) = fst t
rowL = _2
row (Location t) = snd t
origin :: Location
origin = Location (0, 0)
instance Monoid Location where
mempty = origin
mappend (Location (w1, h1)) (Location (w2, h2)) = Location (w1+w2, h1+h2)
data CursorLocation =
CursorLocation { cursorLocation :: !Location
, cursorLocationName :: !(Maybe Name)
}
deriving Show
data Context =
Context { ctxAttrName :: AttrName
, availWidth :: Int
, availHeight :: Int
, ctxBorderStyle :: BorderStyle
, ctxAttrMap :: AttrMap
}
suffixLenses ''RenderState
suffixLenses ''VisibilityRequest
suffixLenses ''CursorLocation
makeLenses ''Viewport