diff options
author | tv <tv@nomic.retiolum> | 2016-02-27 02:03:58 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2016-02-27 02:39:43 +0100 |
commit | 237b7fd8b0c9c8d4ef6d7b8a758c039a217257e5 (patch) | |
tree | 77e9bd01617773e2294069af9e706ffafb0e0bc8 /Screen.hs | |
parent | 045dc986b4de225a927175f81c8ccfdab450202c (diff) |
Screen: init
Diffstat (limited to 'Screen.hs')
-rw-r--r-- | Screen.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Screen.hs b/Screen.hs new file mode 100644 index 0000000..2bf0329 --- /dev/null +++ b/Screen.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE RecordWildCards #-} +module Screen (Screen(..), setScreen, withScreen) where + +import Control.Exception +import Data.List +import System.IO + +data Screen = Screen + { stdinEcho :: Bool + , stdinBufferMode :: BufferMode + , stdoutBufferMode :: BufferMode + , decsetPm :: [Int] + , decrstPm :: [Int] + } + +setScreen :: Screen -> IO Screen +setScreen Screen{..} = get <* set where + get = Screen <$> hGetEcho stdin + <*> hGetBuffering stdin + <*> hGetBuffering stdout + <*> pure decrstPm + <*> pure decsetPm + set = do + hSetEcho stdin stdinEcho + hSetBuffering stdin stdinBufferMode + hSetBuffering stdout stdoutBufferMode + hPutStr stdout $ "\ESC[?" ++ intercalate ";" (map show decsetPm) ++ "h" + hPutStr stdout $ "\ESC[?" ++ intercalate ";" (map show decrstPm) ++ "l" + hFlush stdout + +withScreen :: Screen -> (Screen -> IO a) -> IO a +withScreen s = bracket (setScreen s) setScreen |