diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-08-19 13:00:05 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-08-19 13:17:48 +0200 |
commit | 4e5590d148a7f2b517dce18c231b9d4cb0b1d19f (patch) | |
tree | dd04cecda1525f826f06752102ea2a58754fdbf7 /src/System/IO/Terminal/IO.hs |
Import of source files
Diffstat (limited to 'src/System/IO/Terminal/IO.hs')
-rw-r--r-- | src/System/IO/Terminal/IO.hs | 57 |
1 files changed, 57 insertions, 0 deletions
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 |