module Termbox.Internal.Size
  ( Size (..),
    getSize,
  )
where

import GHC.Generics (Generic)
import qualified Termbox.Bindings.Hs

-- | A terminal size.
data Size = Size
  { Size -> Int
width :: {-# UNPACK #-} !Int,
    Size -> Int
height :: {-# UNPACK #-} !Int
  }
  deriving stock (Size -> Size -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Size -> Size -> Bool
$c/= :: Size -> Size -> Bool
== :: Size -> Size -> Bool
$c== :: Size -> Size -> Bool
Eq, forall x. Rep Size x -> Size
forall x. Size -> Rep Size x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Size x -> Size
$cfrom :: forall x. Size -> Rep Size x
Generic, Eq Size
Size -> Size -> Bool
Size -> Size -> Ordering
Size -> Size -> Size
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
min :: Size -> Size -> Size
$cmin :: Size -> Size -> Size
max :: Size -> Size -> Size
$cmax :: Size -> Size -> Size
>= :: Size -> Size -> Bool
$c>= :: Size -> Size -> Bool
> :: Size -> Size -> Bool
$c> :: Size -> Size -> Bool
<= :: Size -> Size -> Bool
$c<= :: Size -> Size -> Bool
< :: Size -> Size -> Bool
$c< :: Size -> Size -> Bool
compare :: Size -> Size -> Ordering
$ccompare :: Size -> Size -> Ordering
Ord, Int -> Size -> ShowS
[Size] -> ShowS
Size -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Size] -> ShowS
$cshowList :: [Size] -> ShowS
show :: Size -> String
$cshow :: Size -> String
showsPrec :: Int -> Size -> ShowS
$cshowsPrec :: Int -> Size -> ShowS
Show)

-- | Get the current terminal size.
getSize :: IO Size
getSize :: IO Size
getSize = do
  Int
width <- IO Int
Termbox.Bindings.Hs.tb_width
  Int
height <- IO Int
Termbox.Bindings.Hs.tb_height
  forall (f :: * -> *) a. Applicative f => a -> f a
pure Size {Int
width :: Int
$sel:width:Size :: Int
width, Int
height :: Int
$sel:height:Size :: Int
height}