Skip to content

Commit

Permalink
Merge pull request #1 from jtdaugherty/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
KommuSoft authored Feb 16, 2021
2 parents 90ea183 + dfa4c1e commit 598b014
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 35 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@

5.32
----

New features:
* Meta-PageUp and Meta-PageDown are now supported (#193)
* Added `supportsItalics` and `supportsStrikethrough` functions to
check for feature support in terminfo

Bug fixes:
* Detect utf-8 mode in `LANG` regardless of case (thanks Emeka
Nkurumeh)

5.31
----

New features and API changes:
* Added support for strikethrough mode. This change adds a new
`strikethrough` `Style` value and uses the `smxx` and `rmxx`
Terminfo capabilities to activate and deactivate strikethrough mode,
respectively. If the terminfo does not report those capabilities,
this style is ignored.
* `Output`: added the `setDisplayBounds` field to set the output
dimensions of the output handle; added an implementation of this for
the `TerminfoBased` backend.

Other changes:
* The C prototype for `vty_c_get_window_size` in `gwinsz.h` was fixed.

5.30
----

Expand Down
2 changes: 1 addition & 1 deletion src/Data/Sequence/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Data.Sequence
import Control.Parallel.Strategies

instance NFData a => NFData (Seq a) where
rnf = \v -> rnf' (viewl v)
rnf = rnf' . viewl
where
rnf' EmptyL = ()
rnf' (a :< r) = rnf a >| rnf' (viewl r)
10 changes: 5 additions & 5 deletions src/Data/Terminfo/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ instance Show CapExpression where
++ " <= " ++ show (sourceString c)
where
hexDump :: [Word8] -> String
hexDump = foldr (\b s -> showHex b s) ""
hexDump = foldr showHex ""

instance NFData CapExpression where
rnf (CapExpression ops !_bytes !str !c !pOps)
Expand Down Expand Up @@ -99,7 +99,7 @@ parseCapExpression capString =
Left e -> Left e
Right buildResults -> Right $ constructCapExpression capString buildResults

constructCapExpression :: [Char] -> BuildResults -> CapExpression
constructCapExpression :: String -> BuildResults -> CapExpression
constructCapExpression capString buildResults =
let expr = CapExpression
{ capOps = outCapOps buildResults
Expand Down Expand Up @@ -336,9 +336,9 @@ data BuildResults = BuildResults
instance Semigroup BuildResults where
v0 <> v1
= BuildResults
{ outParamCount = (outParamCount v0) `max` (outParamCount v1)
, outCapOps = (outCapOps v0) <> (outCapOps v1)
, outParamOps = (outParamOps v0) <> (outParamOps v1)
{ outParamCount = outParamCount v0 `max` outParamCount v1
, outCapOps = outCapOps v0 <> outCapOps v1
, outParamOps = outParamOps v0 <> outParamOps v1
}

instance Monoid BuildResults where
Expand Down
21 changes: 8 additions & 13 deletions src/Graphics/Vty/Attributes.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}

Expand Down Expand Up @@ -43,6 +40,7 @@ module Graphics.Vty.Attributes
, withStyle
, standout
, italic
, strikethrough
, underline
, reverseVideo
, blink
Expand Down Expand Up @@ -145,20 +143,14 @@ data FixedAttr = FixedAttr
-- | The style and color attributes can either be the terminal defaults.
-- Or be equivalent to the previously applied style. Or be a specific
-- value.
data MaybeDefault v where
Default :: MaybeDefault v
KeepCurrent :: MaybeDefault v
SetTo :: forall v . ( Eq v, Show v, Read v ) => !v -> MaybeDefault v
data MaybeDefault v = Default | KeepCurrent | SetTo !v
deriving (Eq, Read, Show)

instance (NFData v) => NFData (MaybeDefault v) where
rnf Default = ()
rnf KeepCurrent = ()
rnf (SetTo v) = rnf v

deriving instance Eq v => Eq (MaybeDefault v)
deriving instance Eq v => Show (MaybeDefault v)
deriving instance (Eq v, Show v, Read v) => Read (MaybeDefault v)

instance Eq v => Semigroup (MaybeDefault v) where
Default <> Default = Default
Default <> KeepCurrent = Default
Expand All @@ -181,7 +173,7 @@ instance Eq v => Monoid ( MaybeDefault v ) where
-- if the style attribute should not be applied.
type Style = Word8

-- | The 7 possible style attributes:
-- | Valid style attributes include:
--
-- * standout
--
Expand All @@ -197,16 +189,19 @@ type Style = Word8
--
-- * italic
--
-- * strikethrough (via the smxx/rmxx terminfo capabilities)
--
-- (The invisible, protect, and altcharset display attributes some
-- terminals support are not supported via VTY.)
standout, underline, reverseVideo, blink, dim, bold, italic :: Style
standout, underline, reverseVideo, blink, dim, bold, italic, strikethrough :: Style
standout = 0x01
underline = 0x02
reverseVideo = 0x04
blink = 0x08
dim = 0x10
bold = 0x20
italic = 0x40
strikethrough = 0x80

defaultStyleMask :: Style
defaultStyleMask = 0x00
Expand Down
3 changes: 3 additions & 0 deletions src/Graphics/Vty/DisplayAttributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ data StyleStateChange
| RemoveStandout
| ApplyItalic
| RemoveItalic
| ApplyStrikethrough
| RemoveStrikethrough
| ApplyUnderline
| RemoveUnderline
| ApplyReverseVideo
Expand Down Expand Up @@ -144,6 +146,7 @@ diffStyles prev cur
[ styleDiff standout ApplyStandout RemoveStandout
, styleDiff underline ApplyUnderline RemoveUnderline
, styleDiff italic ApplyItalic RemoveItalic
, styleDiff strikethrough ApplyStrikethrough RemoveStrikethrough
, styleDiff reverseVideo ApplyReverseVideo RemoveReverseVideo
, styleDiff blink ApplyBlink RemoveBlink
, styleDiff dim ApplyDim RemoveDim
Expand Down
6 changes: 3 additions & 3 deletions src/Graphics/Vty/Input/Classify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import qualified Data.Set as S( fromList, member )
import Data.Char
import Data.Word

compile :: ClassifyMap -> [Char] -> KClass
compile :: ClassifyMap -> String -> KClass
compile table = cl' where
-- take all prefixes and create a set of these
prefixSet = S.fromList $ concatMap (init . inits . fst) $ table
Expand All @@ -51,7 +51,7 @@ compile table = cl' where
-- neither a prefix or a full event.
[] -> Invalid

classify :: ClassifyMap -> [Char] -> KClass
classify :: ClassifyMap -> String -> KClass
classify table =
let standardClassifier = compile table
in \s -> case s of
Expand All @@ -64,7 +64,7 @@ classify table =
c:cs | ord c >= 0xC2 -> classifyUtf8 c cs
_ -> standardClassifier s

classifyUtf8 :: Char -> [Char] -> KClass
classifyUtf8 :: Char -> String -> KClass
classifyUtf8 c cs =
let n = utf8Length (ord c)
(codepoint,rest) = splitAt n (c:cs)
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Vty/Input/Classify/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ where
import Graphics.Vty.Input.Events

data KClass
= Valid Event [Char]
= Valid Event String
-- ^ A valid event was parsed. Any unused characters from the input
-- stream are also provided.
| Invalid
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Vty/Input/Loop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ logInitialInputState input classifyTable = case _inputDebug input of
Just h -> do
Config{ vmin = Just theVmin
, vtime = Just theVtime
, termName = Just theTerm, .. } <- readIORef $ _configRef input
, termName = Just theTerm } <- readIORef $ _configRef input
_ <- hPrintf h "initial (vmin,vtime): %s\n" (show (theVmin, theVtime))
forM_ classifyTable $ \i -> case i of
(inBytes, EvKey k mods) -> hPrintf h "map %s %s %s %s\n" (show theTerm)
Expand Down
8 changes: 5 additions & 3 deletions src/Graphics/Vty/Input/Terminfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ visibleChars = [ ([x], EvKey (KChar x) [])
ctrlChars :: ClassifyMap
ctrlChars =
[ ([toEnum x],EvKey (KChar y) [MCtrl])
| (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_'])
| (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_'])
, y /= 'i' -- Resolve issue #3 where CTRL-i hides TAB.
, y /= 'h' -- CTRL-h should not hide BS
]
Expand All @@ -86,8 +86,10 @@ ctrlMetaChars = map (\(s,EvKey c m) -> ('\ESC':s, EvKey c (MMeta:m))) ctrlChars
-- | Esc, meta-esc, delete, meta-delete, enter, meta-enter.
specialSupportKeys :: ClassifyMap
specialSupportKeys =
[ -- special support for ESC
("\ESC",EvKey KEsc []), ("\ESC\ESC",EvKey KEsc [MMeta])
[ ("\ESC\ESC[5~",EvKey KPageUp [MMeta])
, ("\ESC\ESC[6~",EvKey KPageDown [MMeta])
-- special support for ESC
, ("\ESC",EvKey KEsc []), ("\ESC\ESC",EvKey KEsc [MMeta])
-- Special support for backspace
, ("\DEL",EvKey KBS []), ("\ESC\DEL",EvKey KBS [MMeta])
-- Special support for Enter
Expand Down
22 changes: 22 additions & 0 deletions src/Graphics/Vty/Output/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ data Output = Output
, ringTerminalBell :: IO ()
-- | Returns whether the terminal has an audio bell feature.
, supportsBell :: IO Bool
-- | Returns whether the terminal supports italicized text.
--
-- This is terminal-dependent and should make a best effort to
-- determine whether this feature is supported, but even if the
-- terminal advertises support (e.g. via terminfo) that might not
-- be a reliable indicator of whether the feature will work as
-- desired.
, supportsItalics :: IO Bool
-- | Returns whether the terminal supports strikethrough text.
--
-- This is terminal-dependent and should make a best effort to
-- determine whether this feature is supported, but even if the
-- terminal advertises support (e.g. via terminfo) that might not
-- be a reliable indicator of whether the feature will work as
-- desired.
, supportsStrikethrough :: IO Bool
}

displayContext :: Output -> DisplayRegion -> IO DisplayContext
Expand Down Expand Up @@ -191,6 +207,12 @@ outputPicture dc pic = do
AbsoluteCursor x y ->
writeShowCursor dc `mappend`
writeMoveCursor dc (clampX x) (clampY y)
PositionOnly isAbs x y ->
if isAbs
then writeMoveCursor dc (clampX x) (clampY y)
else let (ox, oy) = charToOutputPos m (clampX x, clampY y)
m = cursorOutputMap ops $ picCursor pic
in writeMoveCursor dc (clampX ox) (clampY oy)
Cursor x y ->
let m = cursorOutputMap ops $ picCursor pic
(ox, oy) = charToOutputPos m (clampX x, clampY y)
Expand Down
2 changes: 2 additions & 0 deletions src/Graphics/Vty/Output/Mock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ mockTerminal r = liftIO $ do
, releaseDisplay = return ()
, ringTerminalBell = return ()
, supportsBell = return False
, supportsItalics = return False
, supportsStrikethrough = return False
, setDisplayBounds = const $ return ()
, displayBounds = return r
, outputByteBuffer = \bytes -> do
Expand Down
30 changes: 28 additions & 2 deletions src/Graphics/Vty/Output/TerminfoBased.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ data DisplayAttrCaps = DisplayAttrCaps
, exitStandout :: Maybe CapExpression
, enterItalic :: Maybe CapExpression
, exitItalic :: Maybe CapExpression
, enterStrikethrough :: Maybe CapExpression
, exitStrikethrough :: Maybe CapExpression
, enterUnderline :: Maybe CapExpression
, exitUnderline :: Maybe CapExpression
, enterReverseVideo :: Maybe CapExpression
Expand Down Expand Up @@ -166,6 +168,10 @@ reserveTerminal termName outFd = do
sendCap setDefaultAttr []
maybeSendCap cnorm []
, supportsBell = return $ isJust $ ringBellAudio terminfoCaps
, supportsItalics = return $ (isJust $ enterItalic (displayAttrCaps terminfoCaps)) &&
(isJust $ exitItalic (displayAttrCaps terminfoCaps))
, supportsStrikethrough = return $ (isJust $ enterStrikethrough (displayAttrCaps terminfoCaps)) &&
(isJust $ exitStrikethrough (displayAttrCaps terminfoCaps))
, ringTerminalBell = maybeSendCap ringBellAudio []
, reserveDisplay = do
-- If there is no support for smcup: Clear the screen
Expand Down Expand Up @@ -203,7 +209,7 @@ reserveTerminal termName outFd = do
, assumedStateRef = newAssumedStateRef
-- I think fix would help assure tActual is the only
-- reference. I was having issues tho.
, mkDisplayContext = \tActual -> terminfoDisplayContext tActual terminfoCaps
, mkDisplayContext = (`terminfoDisplayContext` terminfoCaps)
}
sendCap s = sendCapToTerminal t (s terminfoCaps)
maybeSendCap s = when (isJust $ s terminfoCaps) . sendCap (fromJust . s)
Expand Down Expand Up @@ -235,6 +241,8 @@ currentDisplayAttrCaps ti
<*> probeCap ti "rmso"
<*> probeCap ti "sitm"
<*> probeCap ti "ritm"
<*> probeCap ti "smxx"
<*> probeCap ti "rmxx"
<*> probeCap ti "smul"
<*> probeCap ti "rmul"
<*> probeCap ti "rev"
Expand Down Expand Up @@ -270,7 +278,11 @@ terminfoDisplayContext tActual terminfoCaps r = return dc
, writeSetAttr = terminfoWriteSetAttr dc terminfoCaps
, writeDefaultAttr = \urlsEnabled ->
writeCapExpr (setDefaultAttr terminfoCaps) [] `mappend`
(if urlsEnabled then writeURLEscapes EndLink else mempty)
(if urlsEnabled then writeURLEscapes EndLink else mempty) `mappend`
(case exitStrikethrough $ displayAttrCaps terminfoCaps of
Just cap -> writeCapExpr cap []
Nothing -> mempty
)
, writeRowEnd = writeCapExpr (clearEol terminfoCaps) []
, inlineHack = return ()
}
Expand Down Expand Up @@ -348,6 +360,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
)
(sgrArgsForState state)
`mappend` setItalics
`mappend` setStrikethrough
`mappend` setColors
-- Otherwise the display colors are not changing or changing
-- between two non-default points.
Expand Down Expand Up @@ -375,6 +388,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
)
(sgrArgsForState state)
`mappend` setItalics
`mappend` setStrikethrough
`mappend` setColors
where
urlAttrs True = writeURLEscapes (urlDiff diffs)
Expand All @@ -392,6 +406,11 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
, Just sitm <- enterItalic (displayAttrCaps terminfoCaps)
= writeCapExpr sitm []
| otherwise = mempty
setStrikethrough
| hasStyle (fixedStyle attr) strikethrough
, Just smxx <- enterStrikethrough (displayAttrCaps terminfoCaps)
= writeCapExpr smxx []
| otherwise = mempty
setColors =
(case fixedForeColor attr of
Just c -> writeCapExpr (setForeColor terminfoCaps)
Expand Down Expand Up @@ -460,6 +479,7 @@ data DisplayAttrState = DisplayAttrState
{ applyStandout :: Bool
, applyUnderline :: Bool
, applyItalic :: Bool
, applyStrikethrough :: Bool
, applyReverseVideo :: Bool
, applyBlink :: Bool
, applyDim :: Bool
Expand Down Expand Up @@ -496,6 +516,8 @@ reqDisplayCapSeqFor caps s diffs
-- set state cap then just use the set state cap.
( True, True ) -> SetState $ stateForStyle s
where
noEnterExitCap ApplyStrikethrough = isNothing $ enterStrikethrough caps
noEnterExitCap RemoveStrikethrough = isNothing $ exitStrikethrough caps
noEnterExitCap ApplyItalic = isNothing $ enterItalic caps
noEnterExitCap RemoveItalic = isNothing $ exitItalic caps
noEnterExitCap ApplyStandout = isNothing $ enterStandout caps
Expand All @@ -510,6 +532,8 @@ reqDisplayCapSeqFor caps s diffs
noEnterExitCap RemoveDim = True
noEnterExitCap ApplyBold = isNothing $ enterBoldMode caps
noEnterExitCap RemoveBold = True
enterExitCap ApplyStrikethrough = fromJust $ enterStrikethrough caps
enterExitCap RemoveStrikethrough = fromJust $ exitStrikethrough caps
enterExitCap ApplyItalic = fromJust $ enterItalic caps
enterExitCap RemoveItalic = fromJust $ exitItalic caps
enterExitCap ApplyStandout = fromJust $ enterStandout caps
Expand All @@ -526,6 +550,7 @@ stateForStyle s = DisplayAttrState
{ applyStandout = isStyleSet standout
, applyUnderline = isStyleSet underline
, applyItalic = isStyleSet italic
, applyStrikethrough = isStyleSet strikethrough
, applyReverseVideo = isStyleSet reverseVideo
, applyBlink = isStyleSet blink
, applyDim = isStyleSet dim
Expand All @@ -538,6 +563,7 @@ styleToApplySeq s = concat
[ applyIfRequired ApplyStandout standout
, applyIfRequired ApplyUnderline underline
, applyIfRequired ApplyItalic italic
, applyIfRequired ApplyStrikethrough strikethrough
, applyIfRequired ApplyReverseVideo reverseVideo
, applyIfRequired ApplyBlink blink
, applyIfRequired ApplyDim dim
Expand Down
Loading

0 comments on commit 598b014

Please sign in to comment.