From 4e5590d148a7f2b517dce18c231b9d4cb0b1d19f Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 19 Aug 2019 13:00:05 +0200 Subject: Import of source files --- src/System/IO/Terminal/IO.hs | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/System/IO/Terminal/IO.hs (limited to 'src/System/IO/Terminal/IO.hs') diff --git a/src/System/IO/Terminal/IO.hs b/src/System/IO/Terminal/IO.hs new file mode 100644 index 0000000..fb0f1c2 --- /dev/null +++ b/src/System/IO/Terminal/IO.hs @@ -0,0 +1,57 @@ +{-| +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 + -- ,withWinchHandler + ,toAlternateScreen + ,fromAlternateScreen) + where + +-- import Foreign.C.Types +import qualified System.Console.Terminal.Size as TS +-- import System.Exit +import System.IO +-- import System.Posix.Signals + + +-- sigWINCH :: CInt +-- sigWINCH = 28 + + +-- | 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 -> error "Cannot get terminal size" + +-- withWinchHandler :: IO () -> IO a -> IO a +-- withWinchHandler h act = do +-- prevh <- installHandler sigWINCH (Catch h) Nothing +-- case prevh of +-- Default -> return () +-- Ignore -> return () +-- _ -> die "ERROR: A signal handler was already installed for the WINCH signal!" + +-- res <- act + +-- _ <- installHandler sigWINCH prevh Nothing +-- return res + +-- | 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 -- cgit v1.2.3-70-g09d2