@@ -25,9 +25,6 @@ import Graphics.Vty.Output.Interface
26import Blaze.ByteString.Builder (Write, writeToByteString, writeStorable)
26import Blaze.ByteString.Builder (Write, writeToByteString, writeStorable)
28−import Control.Monad.Fail (MonadFail)
29−import Control.Monad.Trans
31import Data.Bits ((.&.))
28import Data.Bits ((.&.))
32import Data.Foldable (foldMap)
29import Data.Foldable (foldMap)
33import Data.IORef
30import Data.IORef
@@ -101,8 +98,8 @@ sendCapToTerminal t cap capParams = do
102-- * Providing independent string capabilities for all display
99-- * Providing independent string capabilities for all display
103-- attributes.
100-- attributes.
104−reserveTerminal :: ( Applicative m, MonadIO m ) => String -> Fd -> m Output
101+reserveTerminal :: String -> Fd -> IO Output
105−reserveTerminal termName outFd = liftIO $ do
102+reserveTerminal termName outFd = do
106 ti <- Terminfo.setupTerm termName
103 ti <- Terminfo.setupTerm termName
107 -- assumes set foreground always implies set background exists.
104 -- assumes set foreground always implies set background exists.
108 -- if set foreground is not set then all color changing style
105 -- if set foreground is not set then all color changing style
@@ -131,13 +128,13 @@ reserveTerminal termName outFd = liftIO $ do
131 curStatus <- terminfoModeStatus m
128 curStatus <- terminfoModeStatus m
132 when (newStatus /= curStatus) $
129 when (newStatus /= curStatus) $
133 case m of
130 case m of
134− Hyperlink -> liftIO $ do
131+ Hyperlink -> do
135 writeIORef hyperlinkModeStatus newStatus
132 writeIORef hyperlinkModeStatus newStatus
136 writeIORef newAssumedStateRef initialAssumedState
133 writeIORef newAssumedStateRef initialAssumedState
137 _ -> return ()
134 _ -> return ()
138 terminfoModeStatus m =
135 terminfoModeStatus m =
139 case m of
136 case m of
140− Hyperlink -> liftIO $ readIORef hyperlinkModeStatus
137+ Hyperlink -> readIORef hyperlinkModeStatus
141 _ -> return False
138 _ -> return False
142 terminfoModeSupported Hyperlink = True
139 terminfoModeSupported Hyperlink = True
143 terminfoModeSupported _ = False
140 terminfoModeSupported _ = False
@@ -159,22 +156,22 @@ reserveTerminal termName outFd = liftIO $ do
159 <*> probeCap ti "bel"
156 <*> probeCap ti "bel"
160 let t = Output
157 let t = Output
161 { terminalID = termName
158 { terminalID = termName
162− , releaseTerminal = liftIO $ do
159+ , releaseTerminal = do
163 sendCap setDefaultAttr []
160 sendCap setDefaultAttr []
164 maybeSendCap cnorm []
161 maybeSendCap cnorm []
165 , supportsBell = return $ isJust $ ringBellAudio terminfoCaps
162 , supportsBell = return $ isJust $ ringBellAudio terminfoCaps
166− , ringTerminalBell = liftIO $ maybeSendCap ringBellAudio []
163+ , ringTerminalBell = maybeSendCap ringBellAudio []
167− , reserveDisplay = liftIO $ do
164+ , reserveDisplay = do
168 -- If there is no support for smcup: Clear the screen
165 -- If there is no support for smcup: Clear the screen
169 -- and then move the mouse to the home position to
166 -- and then move the mouse to the home position to
170 -- approximate the behavior.
167 -- approximate the behavior.
171 maybeSendCap smcup []
168 maybeSendCap smcup []
172 sendCap clearScreen []
169 sendCap clearScreen []
173− , releaseDisplay = liftIO $ do
170+ , releaseDisplay = do
174 maybeSendCap rmcup []
171 maybeSendCap rmcup []
175 maybeSendCap cnorm []
172 maybeSendCap cnorm []
176 , displayBounds = do
173 , displayBounds = do
177− rawSize <- liftIO $ getWindowSize outFd
174+ rawSize <- getWindowSize outFd
178 case rawSize of
175 case rawSize of
179 (w, h) | w < 0 || h < 0 -> fail $ "getwinsize returned < 0 : " ++ show rawSize
176 (w, h) | w < 0 || h < 0 -> fail $ "getwinsize returned < 0 : " ++ show rawSize
180 | otherwise -> return (w,h)
177 | otherwise -> return (w,h)
@@ -198,33 +195,31 @@ reserveTerminal termName outFd = liftIO $ do
198 , assumedStateRef = newAssumedStateRef
195 , assumedStateRef = newAssumedStateRef
199 -- I think fix would help assure tActual is the only
196 -- I think fix would help assure tActual is the only
200 -- reference. I was having issues tho.
197 -- reference. I was having issues tho.
201− , mkDisplayContext = \tActual -> liftIO . terminfoDisplayContext tActual terminfoCaps
198+ , mkDisplayContext = \tActual -> terminfoDisplayContext tActual terminfoCaps
203 sendCap s = sendCapToTerminal t (s terminfoCaps)
200 sendCap s = sendCapToTerminal t (s terminfoCaps)
204 maybeSendCap s = when (isJust $ s terminfoCaps) . sendCap (fromJust . s)
201 maybeSendCap s = when (isJust $ s terminfoCaps) . sendCap (fromJust . s)
207−requireCap :: (Applicative m, MonadIO m, MonadFail m) => Terminfo.Terminal -> String -> m CapExpression
204+requireCap :: Terminfo.Terminal -> String -> IO CapExpression
208requireCap ti capName
205requireCap ti capName
209 = case Terminfo.getCapability ti (Terminfo.tiGetStr capName) of
206 = case Terminfo.getCapability ti (Terminfo.tiGetStr capName) of
210 Nothing -> fail $ "Terminal does not define required capability \"" ++ capName ++ "\""
207 Nothing -> fail $ "Terminal does not define required capability \"" ++ capName ++ "\""
211 Just capStr -> parseCap capStr
208 Just capStr -> parseCap capStr
213−probeCap :: (Applicative m, MonadIO m, MonadFail m) => Terminfo.Terminal -> String -> m (Maybe CapExpression)
210+probeCap :: Terminfo.Terminal -> String -> IO (Maybe CapExpression)
214probeCap ti capName
211probeCap ti capName
215 = case Terminfo.getCapability ti (Terminfo.tiGetStr capName) of
212 = case Terminfo.getCapability ti (Terminfo.tiGetStr capName) of
216 Nothing -> return Nothing
213 Nothing -> return Nothing
217 Just capStr -> Just <$> parseCap capStr
214 Just capStr -> Just <$> parseCap capStr
219−parseCap :: (Applicative m, MonadIO m, MonadFail m) => String -> m CapExpression
216+parseCap :: String -> IO CapExpression
220parseCap capStr = do
217parseCap capStr = do
221 case parseCapExpression capStr of
218 case parseCapExpression capStr of
222 Left e -> fail $ show e
219 Left e -> fail $ show e
223 Right cap -> return cap
220 Right cap -> return cap
225−currentDisplayAttrCaps :: ( Applicative m, MonadIO m, MonadFail m )
226− => Terminfo.Terminal
222+currentDisplayAttrCaps :: Terminfo.Terminal -> IO DisplayAttrCaps
227− -> m DisplayAttrCaps
228currentDisplayAttrCaps ti
223currentDisplayAttrCaps ti
229 = pure DisplayAttrCaps
224 = pure DisplayAttrCaps
230 <*> probeCap ti "sgr"
225 <*> probeCap ti "sgr"