@@ -10,10 +10,12 @@
1010-- Copyright Corey O'Connor (coreyoconnor@gmail.com)
1111module Graphics.Vty.Output.TerminfoBased
1212 ( reserveTerminal
13+ , setWindowSize
1314 )
1415where
1516
1617import Control.Monad (when)
18+import Data.Bits (shiftL)
1719import qualified Data.ByteString as BS
1820import Data.ByteString.Internal (toForeignPtr)
1921import Data.Terminfo.Parse
@@ -66,6 +68,8 @@ data DisplayAttrCaps = DisplayAttrCaps
6668 , exitStandout :: Maybe CapExpression
6769 , enterItalic :: Maybe CapExpression
6870 , exitItalic :: Maybe CapExpression
71+ , enterStrikethrough :: Maybe CapExpression
72+ , exitStrikethrough :: Maybe CapExpression
6973 , enterUnderline :: Maybe CapExpression
7074 , exitUnderline :: Maybe CapExpression
7175 , enterReverseVideo :: Maybe CapExpression
@@ -164,6 +168,10 @@ reserveTerminal termName outFd = do
164168 sendCap setDefaultAttr []
165169 maybeSendCap cnorm []
166170 , supportsBell = return $ isJust $ ringBellAudio terminfoCaps
171+ , supportsItalics = return $ (isJust $ enterItalic (displayAttrCaps terminfoCaps)) &&
172+ (isJust $ exitItalic (displayAttrCaps terminfoCaps))
173+ , supportsStrikethrough = return $ (isJust $ enterStrikethrough (displayAttrCaps terminfoCaps)) &&
174+ (isJust $ exitStrikethrough (displayAttrCaps terminfoCaps))
167175 , ringTerminalBell = maybeSendCap ringBellAudio []
168176 , reserveDisplay = do
169177 -- If there is no support for smcup: Clear the screen
@@ -174,6 +182,8 @@ reserveTerminal termName outFd = do
174182 , releaseDisplay = do
175183 maybeSendCap rmcup []
176184 maybeSendCap cnorm []
185+ , setDisplayBounds = \(w, h) ->
186+ setWindowSize outFd (w, h)
177187 , displayBounds = do
178188 rawSize <- getWindowSize outFd
179189 case rawSize of
@@ -231,6 +241,8 @@ currentDisplayAttrCaps ti
231241 <*> probeCap ti "rmso"
232242 <*> probeCap ti "sitm"
233243 <*> probeCap ti "ritm"
244+ <*> probeCap ti "smxx"
245+ <*> probeCap ti "rmxx"
234246 <*> probeCap ti "smul"
235247 <*> probeCap ti "rmul"
236248 <*> probeCap ti "rev"
@@ -244,6 +256,13 @@ getWindowSize fd = do
244256 (a,b) <- (`divMod` 65536) `fmap` c_getWindowSize fd
245257 return (fromIntegral b, fromIntegral a)
246258
259+foreign import ccall "gwinsz.h vty_c_set_window_size" c_setWindowSize :: Fd -> CLong -> IO ()
260+
261+setWindowSize :: Fd -> (Int, Int) -> IO ()
262+setWindowSize fd (w, h) = do
263+ let val = (h `shiftL` 16) + w
264+ c_setWindowSize fd $ fromIntegral val
265+
247266terminfoDisplayContext :: Output -> TerminfoCaps -> DisplayRegion -> IO DisplayContext
248267terminfoDisplayContext tActual terminfoCaps r = return dc
249268 where dc = DisplayContext
@@ -259,7 +278,11 @@ terminfoDisplayContext tActual terminfoCaps r = return dc
259278 , writeSetAttr = terminfoWriteSetAttr dc terminfoCaps
260279 , writeDefaultAttr = \urlsEnabled ->
261280 writeCapExpr (setDefaultAttr terminfoCaps) [] `mappend`
262− (if urlsEnabled then writeURLEscapes EndLink else mempty)
281+ (if urlsEnabled then writeURLEscapes EndLink else mempty) `mappend`
282+ (case exitStrikethrough $ displayAttrCaps terminfoCaps of
283+ Just cap -> writeCapExpr cap []
284+ Nothing -> mempty
285+ )
263286 , writeRowEnd = writeCapExpr (clearEol terminfoCaps) []
264287 , inlineHack = return ()
265288 }
@@ -337,6 +360,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
337360 )
338361 (sgrArgsForState state)
339362 `mappend` setItalics
363+ `mappend` setStrikethrough
340364 `mappend` setColors
341365 -- Otherwise the display colors are not changing or changing
342366 -- between two non-default points.
@@ -364,6 +388,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
364388 )
365389 (sgrArgsForState state)
366390 `mappend` setItalics
391+ `mappend` setStrikethrough
367392 `mappend` setColors
368393 where
369394 urlAttrs True = writeURLEscapes (urlDiff diffs)
@@ -381,6 +406,11 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
381406 , Just sitm <- enterItalic (displayAttrCaps terminfoCaps)
382407 = writeCapExpr sitm []
383408 | otherwise = mempty
409+ setStrikethrough
410+ | hasStyle (fixedStyle attr) strikethrough
411+ , Just smxx <- enterStrikethrough (displayAttrCaps terminfoCaps)
412+ = writeCapExpr smxx []
413+ | otherwise = mempty
384414 setColors =
385415 (case fixedForeColor attr of
386416 Just c -> writeCapExpr (setForeColor terminfoCaps)
@@ -449,6 +479,7 @@ data DisplayAttrState = DisplayAttrState
449479 { applyStandout :: Bool
450480 , applyUnderline :: Bool
451481 , applyItalic :: Bool
482+ , applyStrikethrough :: Bool
452483 , applyReverseVideo :: Bool
453484 , applyBlink :: Bool
454485 , applyDim :: Bool
@@ -485,6 +516,8 @@ reqDisplayCapSeqFor caps s diffs
485516 -- set state cap then just use the set state cap.
486517 ( True, True ) -> SetState $ stateForStyle s
487518 where
519+ noEnterExitCap ApplyStrikethrough = isNothing $ enterStrikethrough caps
520+ noEnterExitCap RemoveStrikethrough = isNothing $ exitStrikethrough caps
488521 noEnterExitCap ApplyItalic = isNothing $ enterItalic caps
489522 noEnterExitCap RemoveItalic = isNothing $ exitItalic caps
490523 noEnterExitCap ApplyStandout = isNothing $ enterStandout caps
@@ -499,6 +532,8 @@ reqDisplayCapSeqFor caps s diffs
499532 noEnterExitCap RemoveDim = True
500533 noEnterExitCap ApplyBold = isNothing $ enterBoldMode caps
501534 noEnterExitCap RemoveBold = True
535+ enterExitCap ApplyStrikethrough = fromJust $ enterStrikethrough caps
536+ enterExitCap RemoveStrikethrough = fromJust $ exitStrikethrough caps
502537 enterExitCap ApplyItalic = fromJust $ enterItalic caps
503538 enterExitCap RemoveItalic = fromJust $ exitItalic caps
504539 enterExitCap ApplyStandout = fromJust $ enterStandout caps
@@ -515,6 +550,7 @@ stateForStyle s = DisplayAttrState
515550 { applyStandout = isStyleSet standout
516551 , applyUnderline = isStyleSet underline
517552 , applyItalic = isStyleSet italic
553+ , applyStrikethrough = isStyleSet strikethrough
518554 , applyReverseVideo = isStyleSet reverseVideo
519555 , applyBlink = isStyleSet blink
520556 , applyDim = isStyleSet dim
@@ -527,6 +563,7 @@ styleToApplySeq s = concat
527563 [ applyIfRequired ApplyStandout standout
528564 , applyIfRequired ApplyUnderline underline
529565 , applyIfRequired ApplyItalic italic
566+ , applyIfRequired ApplyStrikethrough strikethrough
530567 , applyIfRequired ApplyReverseVideo reverseVideo
531568 , applyIfRequired ApplyBlink blink
532569 , applyIfRequired ApplyDim dim