on master help sign in
Make the "shutdown" method of Vty idempotent (fixes #159)
5050413Jonathan Daugherty
src/Graphics/Vty.hs+10−3
@@ -52,6 +52,7 @@ import Graphics.Vty.Picture
52import Graphics.Vty.Image
52import Graphics.Vty.Image
53import Graphics.Vty.Attributes
53import Graphics.Vty.Attributes
54
54
55+import Control.Monad (when)
55import Control.Concurrent.STM
56import Control.Concurrent.STM
56
57
57import Data.IORef
58import Data.IORef
@@ -115,10 +116,16 @@ mkVty appConfig = do
115intMkVty :: Input -> Output -> IO Vty
116intMkVty :: Input -> Output -> IO Vty
116intMkVty input out = do
117intMkVty input out = do
117 reserveDisplay out
118 reserveDisplay out
119+
120+ shutdownVar <- atomically $ newTVar False
118 let shutdownIo = do
121 let shutdownIo = do
122+ alreadyShutdown <- atomically $ readTVar shutdownVar
123+ when (not alreadyShutdown) $ do
124+ atomically $ writeTVar shutdownVar True
119− shutdownInput input
125+ shutdownInput input
120− releaseDisplay out
126+ releaseDisplay out
121− releaseTerminal out
127+ releaseTerminal out
128+
122 lastPicRef <- newIORef Nothing
129 lastPicRef <- newIORef Nothing
123 lastUpdateRef <- newIORef Nothing
130 lastUpdateRef <- newIORef Nothing
124
131