module Brick.Types
( Location(..)
, locL
, TerminalLocation(..)
, CursorLocation(..)
, cursorLocationL
, cursorLocationNameL
, HandleEvent(..)
, Name(..)
, suffixLenses
)
where
import Control.Lens
import Data.String
import Data.Monoid (Monoid(..))
import Graphics.Vty (Event)
import Brick.Types.TH
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
newtype Name = Name String
deriving (Eq, Show, Ord)
instance IsString Name where
fromString = Name
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
suffixLenses ''CursorLocation
instance TerminalLocation CursorLocation where
columnL = cursorLocationL._1
column = column . cursorLocation
rowL = cursorLocationL._2
row = row . cursorLocation
class HandleEvent a where
handleEvent :: Event -> a -> a