module UVMHS.Lib.Window where
import UVMHS.Core
import UVMHS.Lib.Pretty
data WindowL i a =
ZerWindowL a
| OneWindowL 𝔹 a i a
deriving (WindowL i a -> WindowL i a -> Bool
(WindowL i a -> WindowL i a -> Bool)
-> (WindowL i a -> WindowL i a -> Bool) -> Eq (WindowL i a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall i a. (Eq i, Eq a) => WindowL i a -> WindowL i a -> Bool
$c== :: forall i a. (Eq i, Eq a) => WindowL i a -> WindowL i a -> Bool
== :: WindowL i a -> WindowL i a -> Bool
$c/= :: forall i a. (Eq i, Eq a) => WindowL i a -> WindowL i a -> Bool
/= :: WindowL i a -> WindowL i a -> Bool
Eq,Eq (WindowL i a)
Eq (WindowL i a) =>
(WindowL i a -> WindowL i a -> Ordering)
-> (WindowL i a -> WindowL i a -> Bool)
-> (WindowL i a -> WindowL i a -> Bool)
-> (WindowL i a -> WindowL i a -> Bool)
-> (WindowL i a -> WindowL i a -> Bool)
-> (WindowL i a -> WindowL i a -> WindowL i a)
-> (WindowL i a -> WindowL i a -> WindowL i a)
-> Ord (WindowL i a)
WindowL i a -> WindowL i a -> Bool
WindowL i a -> WindowL i a -> Ordering
WindowL i a -> WindowL i a -> WindowL i a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall i a. (Ord i, Ord a) => Eq (WindowL i a)
forall i a. (Ord i, Ord a) => WindowL i a -> WindowL i a -> Bool
forall i a.
(Ord i, Ord a) =>
WindowL i a -> WindowL i a -> Ordering
forall i a.
(Ord i, Ord a) =>
WindowL i a -> WindowL i a -> WindowL i a
$ccompare :: forall i a.
(Ord i, Ord a) =>
WindowL i a -> WindowL i a -> Ordering
compare :: WindowL i a -> WindowL i a -> Ordering
$c< :: forall i a. (Ord i, Ord a) => WindowL i a -> WindowL i a -> Bool
< :: WindowL i a -> WindowL i a -> Bool
$c<= :: forall i a. (Ord i, Ord a) => WindowL i a -> WindowL i a -> Bool
<= :: WindowL i a -> WindowL i a -> Bool
$c> :: forall i a. (Ord i, Ord a) => WindowL i a -> WindowL i a -> Bool
> :: WindowL i a -> WindowL i a -> Bool
$c>= :: forall i a. (Ord i, Ord a) => WindowL i a -> WindowL i a -> Bool
>= :: WindowL i a -> WindowL i a -> Bool
$cmax :: forall i a.
(Ord i, Ord a) =>
WindowL i a -> WindowL i a -> WindowL i a
max :: WindowL i a -> WindowL i a -> WindowL i a
$cmin :: forall i a.
(Ord i, Ord a) =>
WindowL i a -> WindowL i a -> WindowL i a
min :: WindowL i a -> WindowL i a -> WindowL i a
Ord,Int -> WindowL i a -> ShowS
[WindowL i a] -> ShowS
WindowL i a -> String
(Int -> WindowL i a -> ShowS)
-> (WindowL i a -> String)
-> ([WindowL i a] -> ShowS)
-> Show (WindowL i a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall i a. (Show i, Show a) => Int -> WindowL i a -> ShowS
forall i a. (Show i, Show a) => [WindowL i a] -> ShowS
forall i a. (Show i, Show a) => WindowL i a -> String
$cshowsPrec :: forall i a. (Show i, Show a) => Int -> WindowL i a -> ShowS
showsPrec :: Int -> WindowL i a -> ShowS
$cshow :: forall i a. (Show i, Show a) => WindowL i a -> String
show :: WindowL i a -> String
$cshowList :: forall i a. (Show i, Show a) => [WindowL i a] -> ShowS
showList :: [WindowL i a] -> ShowS
Show)
eWindowL ∷ a → WindowL i a
eWindowL :: forall a i. a -> WindowL i a
eWindowL = a -> WindowL i a
forall i a. a -> WindowL i a
ZerWindowL
iWindowL ∷ (Null a) ⇒ i → WindowL i a
iWindowL :: forall a i. Null a => i -> WindowL i a
iWindowL i
i = Bool -> a -> i -> a -> WindowL i a
forall i a. Bool -> a -> i -> a -> WindowL i a
OneWindowL Bool
False a
forall a. Null a => a
null i
i a
forall a. Null a => a
null
overflowL ∷ WindowL i a → 𝔹
overflowL :: forall i a. WindowL i a -> Bool
overflowL (ZerWindowL a
_) = Bool
False
overflowL (OneWindowL Bool
o a
_ i
_ a
_) = Bool
o
instance (Null a) ⇒ Null (WindowL i a) where
null :: WindowL i a
null = a -> WindowL i a
forall i a. a -> WindowL i a
ZerWindowL a
forall a. Null a => a
null
instance (Append a) ⇒ Append (WindowL i a) where
ZerWindowL a
x ⧺ :: WindowL i a -> WindowL i a -> WindowL i a
⧺ ZerWindowL a
y = a -> WindowL i a
forall i a. a -> WindowL i a
ZerWindowL (a -> WindowL i a) -> a -> WindowL i a
forall a b. (a -> b) -> a -> b
$ a
x a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
y
ZerWindowL a
x ⧺ OneWindowL Bool
o a
y i
i a
z = Bool -> a -> i -> a -> WindowL i a
forall i a. Bool -> a -> i -> a -> WindowL i a
OneWindowL Bool
o (a
x a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
y) i
i a
z
OneWindowL Bool
True a
x i
i a
y ⧺ WindowL i a
_ = Bool -> a -> i -> a -> WindowL i a
forall i a. Bool -> a -> i -> a -> WindowL i a
OneWindowL Bool
True a
x i
i a
y
OneWindowL Bool
False a
x i
i a
y ⧺ ZerWindowL a
z = Bool -> a -> i -> a -> WindowL i a
forall i a. Bool -> a -> i -> a -> WindowL i a
OneWindowL Bool
False a
x i
i (a -> WindowL i a) -> a -> WindowL i a
forall a b. (a -> b) -> a -> b
$ a
y a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
z
OneWindowL Bool
False a
x i
i a
y ⧺ OneWindowL Bool
_ a
z i
_ a
_ = Bool -> a -> i -> a -> WindowL i a
forall i a. Bool -> a -> i -> a -> WindowL i a
OneWindowL Bool
True a
x i
i (a -> WindowL i a) -> a -> WindowL i a
forall a b. (a -> b) -> a -> b
$ a
y a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
z
instance (Monoid a) ⇒ Monoid (WindowL i a)
instance ToIter a (WindowL a a) where
iter :: WindowL a a -> 𝐼 a
iter (ZerWindowL a
x) = a -> 𝐼 a
forall a t. Single a t => a -> t
single a
x
iter (OneWindowL Bool
_ a
x a
i a
y) = [a] -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter [a
x,a
i,a
y]
mapWindowL ∷ (i → j) → (a → b) → WindowL i a → WindowL j b
mapWindowL :: forall i j a b. (i -> j) -> (a -> b) -> WindowL i a -> WindowL j b
mapWindowL i -> j
_ a -> b
f (ZerWindowL a
x) = b -> WindowL j b
forall i a. a -> WindowL i a
ZerWindowL (b -> WindowL j b) -> b -> WindowL j b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
x
mapWindowL i -> j
g a -> b
f (OneWindowL Bool
o a
x i
i a
y) = Bool -> b -> j -> b -> WindowL j b
forall i a. Bool -> a -> i -> a -> WindowL i a
OneWindowL Bool
o (a -> b
f a
x) (i -> j
g i
i) (b -> WindowL j b) -> b -> WindowL j b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
y
data WindowR i a =
ZerWindowR a
| OneWindowR 𝔹 a i a
deriving (WindowR i a -> WindowR i a -> Bool
(WindowR i a -> WindowR i a -> Bool)
-> (WindowR i a -> WindowR i a -> Bool) -> Eq (WindowR i a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall i a. (Eq i, Eq a) => WindowR i a -> WindowR i a -> Bool
$c== :: forall i a. (Eq i, Eq a) => WindowR i a -> WindowR i a -> Bool
== :: WindowR i a -> WindowR i a -> Bool
$c/= :: forall i a. (Eq i, Eq a) => WindowR i a -> WindowR i a -> Bool
/= :: WindowR i a -> WindowR i a -> Bool
Eq,Eq (WindowR i a)
Eq (WindowR i a) =>
(WindowR i a -> WindowR i a -> Ordering)
-> (WindowR i a -> WindowR i a -> Bool)
-> (WindowR i a -> WindowR i a -> Bool)
-> (WindowR i a -> WindowR i a -> Bool)
-> (WindowR i a -> WindowR i a -> Bool)
-> (WindowR i a -> WindowR i a -> WindowR i a)
-> (WindowR i a -> WindowR i a -> WindowR i a)
-> Ord (WindowR i a)
WindowR i a -> WindowR i a -> Bool
WindowR i a -> WindowR i a -> Ordering
WindowR i a -> WindowR i a -> WindowR i a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall i a. (Ord i, Ord a) => Eq (WindowR i a)
forall i a. (Ord i, Ord a) => WindowR i a -> WindowR i a -> Bool
forall i a.
(Ord i, Ord a) =>
WindowR i a -> WindowR i a -> Ordering
forall i a.
(Ord i, Ord a) =>
WindowR i a -> WindowR i a -> WindowR i a
$ccompare :: forall i a.
(Ord i, Ord a) =>
WindowR i a -> WindowR i a -> Ordering
compare :: WindowR i a -> WindowR i a -> Ordering
$c< :: forall i a. (Ord i, Ord a) => WindowR i a -> WindowR i a -> Bool
< :: WindowR i a -> WindowR i a -> Bool
$c<= :: forall i a. (Ord i, Ord a) => WindowR i a -> WindowR i a -> Bool
<= :: WindowR i a -> WindowR i a -> Bool
$c> :: forall i a. (Ord i, Ord a) => WindowR i a -> WindowR i a -> Bool
> :: WindowR i a -> WindowR i a -> Bool
$c>= :: forall i a. (Ord i, Ord a) => WindowR i a -> WindowR i a -> Bool
>= :: WindowR i a -> WindowR i a -> Bool
$cmax :: forall i a.
(Ord i, Ord a) =>
WindowR i a -> WindowR i a -> WindowR i a
max :: WindowR i a -> WindowR i a -> WindowR i a
$cmin :: forall i a.
(Ord i, Ord a) =>
WindowR i a -> WindowR i a -> WindowR i a
min :: WindowR i a -> WindowR i a -> WindowR i a
Ord,Int -> WindowR i a -> ShowS
[WindowR i a] -> ShowS
WindowR i a -> String
(Int -> WindowR i a -> ShowS)
-> (WindowR i a -> String)
-> ([WindowR i a] -> ShowS)
-> Show (WindowR i a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall i a. (Show i, Show a) => Int -> WindowR i a -> ShowS
forall i a. (Show i, Show a) => [WindowR i a] -> ShowS
forall i a. (Show i, Show a) => WindowR i a -> String
$cshowsPrec :: forall i a. (Show i, Show a) => Int -> WindowR i a -> ShowS
showsPrec :: Int -> WindowR i a -> ShowS
$cshow :: forall i a. (Show i, Show a) => WindowR i a -> String
show :: WindowR i a -> String
$cshowList :: forall i a. (Show i, Show a) => [WindowR i a] -> ShowS
showList :: [WindowR i a] -> ShowS
Show)
eWindowR ∷ a → WindowR i a
eWindowR :: forall a i. a -> WindowR i a
eWindowR = a -> WindowR i a
forall i a. a -> WindowR i a
ZerWindowR
iWindowR ∷ (Null a) ⇒ i → WindowR i a
iWindowR :: forall a i. Null a => i -> WindowR i a
iWindowR i
i = Bool -> a -> i -> a -> WindowR i a
forall i a. Bool -> a -> i -> a -> WindowR i a
OneWindowR Bool
False a
forall a. Null a => a
null i
i a
forall a. Null a => a
null
overflowR ∷ WindowR i a → 𝔹
overflowR :: forall i a. WindowR i a -> Bool
overflowR (ZerWindowR a
_) = Bool
False
overflowR (OneWindowR Bool
o a
_ i
_ a
_) = Bool
o
instance (Null a) ⇒ Null (WindowR i a) where
null :: WindowR i a
null = a -> WindowR i a
forall i a. a -> WindowR i a
ZerWindowR a
forall a. Null a => a
null
instance (Append a) ⇒ Append (WindowR i a) where
ZerWindowR a
x ⧺ :: WindowR i a -> WindowR i a -> WindowR i a
⧺ ZerWindowR a
y = a -> WindowR i a
forall i a. a -> WindowR i a
ZerWindowR (a -> WindowR i a) -> a -> WindowR i a
forall a b. (a -> b) -> a -> b
$ a
x a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
y
OneWindowR Bool
o a
x i
i a
y ⧺ ZerWindowR a
z = Bool -> a -> i -> a -> WindowR i a
forall i a. Bool -> a -> i -> a -> WindowR i a
OneWindowR Bool
o a
x i
i (a -> WindowR i a) -> a -> WindowR i a
forall a b. (a -> b) -> a -> b
$ a
y a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
z
WindowR i a
_ ⧺ OneWindowR Bool
True a
x i
i a
y = Bool -> a -> i -> a -> WindowR i a
forall i a. Bool -> a -> i -> a -> WindowR i a
OneWindowR Bool
True a
x i
i a
y
ZerWindowR a
x ⧺ OneWindowR Bool
False a
y i
i a
z = Bool -> a -> i -> a -> WindowR i a
forall i a. Bool -> a -> i -> a -> WindowR i a
OneWindowR Bool
False (a
x a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
y) i
i a
z
OneWindowR Bool
_ a
_ i
_ a
x ⧺ OneWindowR Bool
False a
y i
i a
z = Bool -> a -> i -> a -> WindowR i a
forall i a. Bool -> a -> i -> a -> WindowR i a
OneWindowR Bool
True (a
x a -> a -> a
forall a. Append a => a -> a -> a
⧺ a
y) i
i a
z
instance (Monoid a) ⇒ Monoid (WindowR i a)
instance ToIter a (WindowR a a) where
iter :: WindowR a a -> 𝐼 a
iter (ZerWindowR a
x) = a -> 𝐼 a
forall a t. Single a t => a -> t
single a
x
iter (OneWindowR Bool
_ a
x a
i a
y) = [a] -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter [a
x,a
i,a
y]
mapWindowR ∷ (i → j) → (a → b) → WindowR i a → WindowR j b
mapWindowR :: forall i j a b. (i -> j) -> (a -> b) -> WindowR i a -> WindowR j b
mapWindowR i -> j
_ a -> b
f (ZerWindowR a
x) = b -> WindowR j b
forall i a. a -> WindowR i a
ZerWindowR (b -> WindowR j b) -> b -> WindowR j b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
x
mapWindowR i -> j
g a -> b
f (OneWindowR Bool
o a
x i
i a
y) = Bool -> b -> j -> b -> WindowR j b
forall i a. Bool -> a -> i -> a -> WindowR i a
OneWindowR Bool
o (a -> b
f a
x) (i -> j
g i
i) (b -> WindowR j b) -> b -> WindowR j b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
y
makePrettySum ''WindowL
makePrettySum ''WindowR
renderWindowL ∷ WindowL Doc Doc → Doc
renderWindowL :: WindowL Doc Doc -> Doc
renderWindowL WindowL Doc Doc
dL
| WindowL Doc Doc -> Bool
forall i a. WindowL i a -> Bool
overflowL WindowL Doc Doc
dL = [Doc] -> Doc
forall t. ToIter Doc t => t -> Doc
ppVertical
[ WindowL Doc Doc -> Doc
forall a t. (Monoid a, ToIter a t) => t -> a
concat WindowL Doc Doc
dL
, Formats -> Doc -> Doc
ppFormat ([Format] -> Formats
forall t. ToIter Format t => t -> Formats
formats [Color -> Format
BG Color
grayLight]) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ 𝕊 -> Doc
ppString 𝕊
"…"
]
| Bool
otherwise = WindowL Doc Doc -> Doc
forall a t. (Monoid a, ToIter a t) => t -> a
concat WindowL Doc Doc
dL
renderWindowR ∷ WindowR Doc Doc → Doc
renderWindowR :: WindowR Doc Doc -> Doc
renderWindowR WindowR Doc Doc
dR
| WindowR Doc Doc -> Bool
forall i a. WindowR i a -> Bool
overflowR WindowR Doc Doc
dR = [Doc] -> Doc
forall t. ToIter Doc t => t -> Doc
ppVertical
[ Formats -> Doc -> Doc
ppFormat ([Format] -> Formats
forall t. ToIter Format t => t -> Formats
formats [Color -> Format
BG Color
grayLight]) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ 𝕊 -> Doc
ppString 𝕊
"…"
, WindowR Doc Doc -> Doc
forall a t. (Monoid a, ToIter a t) => t -> a
concat WindowR Doc Doc
dR
]
| Bool
otherwise = WindowR Doc Doc -> Doc
forall a t. (Monoid a, ToIter a t) => t -> a
concat WindowR Doc Doc
dR