System.Console.Terminal.Size

terminal-size-0.3.2.1: Get terminal window height and width

Safe Haskell | Safe
Language | Haskell2010

System.Console.Terminal.Size

Description

Get terminal window height and width without ncurses dependency

Based on answer by Andreas Hammar at http://stackoverflow.com/a/12807521/972985

Synopsis

- data Window a = Window {
  - height :: !a
  - width :: !a
  }
- size :: Integral n => IO (Maybe (Window n))
- fdSize :: Integral n => Fd -> IO (Maybe (Window n))
- hSize :: Integral n => Handle -> IO (Maybe (Window n))

# Documentation

data Window a #

Terminal window width and height

Constructors

Window |
Fields height :: !a width :: !a

Instances

Functor Window # |
Methods fmap :: (a -> b) -> Window a -> Window b # (<$) :: a -> Window b -> Window a #
Foldable Window # |
Methods fold :: Monoid m => Window m -> m # foldMap :: Monoid m => (a -> m) -> Window a -> m # foldr :: (a -> b -> b) -> b -> Window a -> b # foldr' :: (a -> b -> b) -> b -> Window a -> b # foldl :: (b -> a -> b) -> b -> Window a -> b # foldl' :: (b -> a -> b) -> b -> Window a -> b # foldr1 :: (a -> a -> a) -> Window a -> a # foldl1 :: (a -> a -> a) -> Window a -> a # toList :: Window a -> [a] # null :: Window a -> Bool # length :: Window a -> Int # elem :: Eq a => a -> Window a -> Bool # maximum :: Ord a => Window a -> a # minimum :: Ord a => Window a -> a # sum :: Num a => Window a -> a # product :: Num a => Window a -> a #
Traversable Window # |
Methods traverse :: Applicative f => (a -> f b) -> Window a -> f (Window b) # sequenceA :: Applicative f => Window (f a) -> f (Window a) # mapM :: Monad m => (a -> m b) -> Window a -> m (Window b) # sequence :: Monad m => Window (m a) -> m (Window a) #
Generic1 Window # |
Associated Types type Rep1 (Window :: * -> *) :: * -> * # Methods from1 :: Window a -> Rep1 Window a # to1 :: Rep1 Window a -> Window a #
Eq a => Eq (Window a) # |
Methods (==) :: Window a -> Window a -> Bool # (/=) :: Window a -> Window a -> Bool #
Data a => Data (Window a) # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Window a -> c (Window a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Window a) # toConstr :: Window a -> Constr # dataTypeOf :: Window a -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Window a)) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Window a)) # gmapT :: (forall b. Data b => b -> b) -> Window a -> Window a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Window a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Window a -> r # gmapQ :: (forall d. Data d => d -> u) -> Window a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Window a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Window a -> m (Window a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Window a -> m (Window a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Window a -> m (Window a) #
Read a => Read (Window a) # |
Methods readsPrec :: Int -> ReadS (Window a) # readList :: ReadS [Window a] # readPrec :: ReadPrec (Window a) # readListPrec :: ReadPrec [Window a] #
Show a => Show (Window a) # |
Methods showsPrec :: Int -> Window a -> ShowS # show :: Window a -> String # showList :: [Window a] -> ShowS #
Generic (Window a) # |
Associated Types type Rep (Window a) :: * -> * # Methods from :: Window a -> Rep (Window a) x # to :: Rep (Window a) x -> Window a #
type Rep1 Window # |
type Rep1 Window = D1 (MetaData "Window" "System.Console.Terminal.Common" "terminal-size-0.3.2.1-LpkVHWZKZXdLX20uKh4q0i" False) (C1 (MetaCons "Window" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "height") NoSourceUnpackedness SourceStrict DecidedStrict) Par1) (S1 (MetaSel (Just Symbol "width") NoSourceUnpackedness SourceStrict DecidedStrict) Par1)))
type Rep (Window a) # |
type Rep (Window a) = D1 (MetaData "Window" "System.Console.Terminal.Common" "terminal-size-0.3.2.1-LpkVHWZKZXdLX20uKh4q0i" False) (C1 (MetaCons "Window" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "height") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)) (S1 (MetaSel (Just Symbol "width") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a))))

size :: Integral n => IO (Maybe (Window n)) #

Get terminal window width and height for `stdout`.

    >>> import System.Console.Terminal.Size
    >>> size
    Just (Window {height = 60, width = 112})

fdSize :: Integral n => Fd -> IO (Maybe (Window n)) #

Not available on Windows: Get terminal window width and height for a specified file descriptor. If it's not attached to a terminal then `Nothing` is returned.

    >>> import System.Console.Terminal.Size
    >>> import System.Posix
    >>> fdSize stdOutput
    Just (Window {height = 56, width = 85})
    >>> fd <- openFd "foo" ReadWrite (Just stdFileMode) defaultFileFlags
    >>> fdSize fd
    Nothing

hSize :: Integral n => Handle -> IO (Maybe (Window n)) #

Not available on Windows: Same as `fdSize`, but takes `Handle` instead of `Fd` (file descriptor).

    >>> import System.Console.Terminal.Size
    >>> import System.IO
    >>> hSize stdout
    Just (Window {height = 56, width = 85})