@@ -52,6 +52,7 @@ import Graphics.Vty.Picture
5252import Graphics.Vty.Image
5353import Graphics.Vty.Attributes
5454
55+import Control.Monad (when)
5556import Control.Concurrent.STM
5657
5758import Data.IORef
@@ -115,10 +116,16 @@ mkVty appConfig = do
115116intMkVty :: Input -> Output -> IO Vty
116117intMkVty input out = do
117118 reserveDisplay out
119+
120+ shutdownVar <- atomically $ newTVar False
118121 let shutdownIo = do
119− shutdownInput input
120− releaseDisplay out
121− releaseTerminal out
122+ alreadyShutdown <- atomically $ readTVar shutdownVar
123+ when (not alreadyShutdown) $ do
124+ atomically $ writeTVar shutdownVar True
125+ shutdownInput input
126+ releaseDisplay out
127+ releaseTerminal out
128+
122129 lastPicRef <- newIORef Nothing
123130 lastUpdateRef <- newIORef Nothing
124131