mirror of
https://github.com/jaspervdj/patat.git
synced 2024-11-26 09:52:59 +03:00
24 lines
817 B
Haskell
24 lines
817 B
Haskell
--------------------------------------------------------------------------------
|
|
module Patat.Size
|
|
( Size (..)
|
|
, getTerminalSize
|
|
) where
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
import Data.Maybe (fromMaybe)
|
|
import qualified System.Console.Terminal.Size as Terminal
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
data Size = Size {sRows :: Int, sCols :: Int} deriving (Show)
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
getTerminalSize :: IO Size
|
|
getTerminalSize = do
|
|
mbWindow <- Terminal.size
|
|
let rows = fromMaybe 24 $ Terminal.height <$> mbWindow
|
|
cols = fromMaybe 72 $ Terminal.width <$> mbWindow
|
|
pure $ Size {sRows = rows, sCols = cols}
|