{-| Module : System.IO.Terminal.IO Copyright : (c) UU, 2019 License : MIT Maintainer : Tom Smeding Stability : experimental Portability : POSIX, macOS, Windows Extra terminal management utility functions. This module basically extends the @ansi-terminal@ package. -} module System.IO.Terminal.IO ( queryTermSize, toAlternateScreen, fromAlternateScreen, ) where import qualified System.Console.Terminal.Size as TS import System.Exit import System.IO -- | Request the current terminal size from the terminal. Probably not very -- fast. queryTermSize :: IO (Int, Int) queryTermSize = TS.size >>= \case Just win -> return (TS.width win, TS.height win) Nothing -> die "ERROR: Cannot get terminal size" -- | Switch to the \"alternate screen\", if the terminal supports it. toAlternateScreen :: IO () toAlternateScreen = putStr "\x1B[?1049h" >> hFlush stdout -- | Switch from the \"alternate screen\" back to the normal buffer, if the -- terminal supports it. fromAlternateScreen :: IO () fromAlternateScreen = putStr "\x1B[?1049l" >> hFlush stdout