{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_HADDOCK show-extensions #-}
module Yi.Window where
import Data.Binary (Binary (..))
import Data.Default (Default (def))
import Data.Typeable (Typeable)
import Yi.Buffer.Basic (BufferRef, WindowRef)
import Yi.JumpList (JumpList)
import Yi.Region (Region, emptyRegion)
import Yi.Utils (makeLensesWithSuffix)
data Window = Window
{ Window -> Bool
isMini :: !Bool
, Window -> BufferRef
bufkey :: !BufferRef
, Window -> [BufferRef]
bufAccessList :: ![BufferRef]
, Window -> Int
height :: !Int
, Window -> Int
width :: !Int
, Window -> Region
winRegion :: !Region
, Window -> WindowRef
wkey :: !WindowRef
, Window -> Int
actualLines :: !Int
, Window -> JumpList
jumpList :: !JumpList
} deriving (Typeable)
makeLensesWithSuffix "A" ''Window
instance Binary Window where
put :: Window -> Put
put (Window Bool
mini BufferRef
bk [BufferRef]
bl Int
_w Int
_h Region
_rgn WindowRef
key Int
lns JumpList
jl) =
Bool -> Put
forall t. Binary t => t -> Put
put Bool
mini Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> BufferRef -> Put
forall t. Binary t => t -> Put
put BufferRef
bk Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [BufferRef] -> Put
forall t. Binary t => t -> Put
put [BufferRef]
bl Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> WindowRef -> Put
forall t. Binary t => t -> Put
put WindowRef
key Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
lns Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> JumpList -> Put
forall t. Binary t => t -> Put
put JumpList
jl
get :: Get Window
get = Bool
-> BufferRef
-> [BufferRef]
-> Int
-> Int
-> Region
-> WindowRef
-> Int
-> JumpList
-> Window
Window (Bool
-> BufferRef
-> [BufferRef]
-> Int
-> Int
-> Region
-> WindowRef
-> Int
-> JumpList
-> Window)
-> Get Bool
-> Get
(BufferRef
-> [BufferRef]
-> Int
-> Int
-> Region
-> WindowRef
-> Int
-> JumpList
-> Window)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Bool
forall t. Binary t => Get t
get Get
(BufferRef
-> [BufferRef]
-> Int
-> Int
-> Region
-> WindowRef
-> Int
-> JumpList
-> Window)
-> Get BufferRef
-> Get
([BufferRef]
-> Int -> Int -> Region -> WindowRef -> Int -> JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get BufferRef
forall t. Binary t => Get t
get Get
([BufferRef]
-> Int -> Int -> Region -> WindowRef -> Int -> JumpList -> Window)
-> Get [BufferRef]
-> Get
(Int -> Int -> Region -> WindowRef -> Int -> JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [BufferRef]
forall t. Binary t => Get t
get
Get
(Int -> Int -> Region -> WindowRef -> Int -> JumpList -> Window)
-> Get Int
-> Get (Int -> Region -> WindowRef -> Int -> JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Get Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0 Get (Int -> Region -> WindowRef -> Int -> JumpList -> Window)
-> Get Int
-> Get (Region -> WindowRef -> Int -> JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> Get Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
0 Get (Region -> WindowRef -> Int -> JumpList -> Window)
-> Get Region -> Get (WindowRef -> Int -> JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Region -> Get Region
forall (m :: * -> *) a. Monad m => a -> m a
return Region
emptyRegion
Get (WindowRef -> Int -> JumpList -> Window)
-> Get WindowRef -> Get (Int -> JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get WindowRef
forall t. Binary t => Get t
get Get (Int -> JumpList -> Window)
-> Get Int -> Get (JumpList -> Window)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get Get (JumpList -> Window) -> Get JumpList -> Get Window
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get JumpList
forall t. Binary t => Get t
get
winkey :: Window -> (Bool, BufferRef)
winkey :: Window -> (Bool, BufferRef)
winkey Window
w = (Window -> Bool
isMini Window
w, Window -> BufferRef
bufkey Window
w)
instance Show Window where
show :: Window -> String
show Window
w = String
"Window to " String -> ShowS
forall a. [a] -> [a] -> [a]
++ BufferRef -> String
forall a. Show a => a -> String
show (Window -> BufferRef
bufkey Window
w)
String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Window -> Int
height Window
w) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
instance Eq Window where
== :: Window -> Window -> Bool
(==) Window
w1 Window
w2 = Window -> WindowRef
wkey Window
w1 WindowRef -> WindowRef -> Bool
forall a. Eq a => a -> a -> Bool
== Window -> WindowRef
wkey Window
w2
dummyWindow :: BufferRef -> Window
dummyWindow :: BufferRef -> Window
dummyWindow BufferRef
b = Bool
-> BufferRef
-> [BufferRef]
-> Int
-> Int
-> Region
-> WindowRef
-> Int
-> JumpList
-> Window
Window Bool
False BufferRef
b [] Int
0 Int
0 Region
emptyRegion WindowRef
forall a. Default a => a
def Int
0 JumpList
forall a. Maybe a
Nothing