vty-unix 0.2.0.0 → 0.4.0.0
raw patch · 6 files changed
Files
- CHANGELOG.md +17/−0
- src/Data/Terminfo/Eval.hs +12/−0
- src/Data/Terminfo/Parse.hs +19/−1
- src/Graphics/Vty/Platform/Unix/Input/Mouse.hs +10/−0
- tools/BuildWidthTable.hs +23/−12
- vty-unix.cabal +3/−3
CHANGELOG.md view
@@ -1,8 +1,25 @@ +0.4.0.0+=======++* Added support for terminfo operators "*", "/", and "m" (thanks Chris+ Forno)++0.3.0.0+=======++* Added support in `Input.Mouse` for parsing horizontal scrolling inputs+ to work with Vty 6.6.+* Improved the `vty-unix-build-width-table` tool (thanks Eric Mertens)+ to make it more robust when the terminal fails to recognize the+ `getCursorPosition` escape sequence.+ 0.2.0.0 ======= API changes:+* The `buildOutput` function in `Graphics.Vty.Platform.Unix.Output` now+ takes a new first argument of type `VtyUserConfig`. * The `settingColorMode` field of `UnixSettings` was removed in favor of Vty 6.1's new `configPreferredColorMode` field of the `VtyUserConfig` type. This package now uses that setting if present; otherwise it does
src/Data/Terminfo/Eval.hs view
@@ -120,6 +120,18 @@ v1 <- pop v0 <- pop push $ v0 - v1+writeCapOp ArithMult = do+ v1 <- pop+ v0 <- pop+ push $ v0 * v1+writeCapOp ArithDiv = do+ v1 <- pop+ v0 <- pop+ push $ v0 `div` v1+writeCapOp ArithMod = do+ v1 <- pop+ v0 <- pop+ push $ v0 `mod` v1 writeCapOp CompareEq = do v1 <- pop v0 <- pop
src/Data/Terminfo/Parse.hs view
@@ -61,7 +61,7 @@ , conditionalParts :: ![(CapOps, CapOps)] } | BitwiseOr | BitwiseXOr | BitwiseAnd- | ArithPlus | ArithMinus+ | ArithPlus | ArithMinus | ArithMult | ArithDiv | ArithMod | CompareEq | CompareLt | CompareGt deriving (Show, Eq) @@ -75,6 +75,9 @@ rnf BitwiseAnd = () rnf ArithPlus = () rnf ArithMinus = ()+ rnf ArithMult = ()+ rnf ArithDiv = ()+ rnf ArithMod = () rnf CompareEq = () rnf CompareLt = () rnf CompareGt = ()@@ -256,6 +259,9 @@ arithOpParser = plusOp <|> minusOp+ <|> multOp+ <|> divOp+ <|> modOp where plusOp = do _ <- char '+'@@ -265,6 +271,18 @@ _ <- char '-' incOffset 1 return $ BuildResults 0 [ ArithMinus ] [ ]+ multOp = do+ _ <- char '*'+ incOffset 1+ return $ BuildResults 0 [ ArithMult ] [ ]+ divOp = do+ _ <- char '/'+ incOffset 1+ return $ BuildResults 0 [ ArithDiv ] [ ]+ modOp = do+ _ <- char 'm'+ incOffset 1+ return $ BuildResults 0 [ ArithMod ] [ ] literalIntOpParser :: CapParser BuildResults literalIntOpParser = do
src/Graphics/Vty/Platform/Unix/Input/Mouse.hs view
@@ -83,12 +83,20 @@ rightButton :: Int rightButton = 2 +-- | See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Wheel-mice scrollUp :: Int scrollUp = 64 scrollDown :: Int scrollDown = 65 +-- | See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Other-buttons+scrollLeft :: Int+scrollLeft = 66++scrollRight :: Int+scrollRight = 67+ hasBitSet :: Int -> Int -> Bool hasBitSet val bit = val .&. bit > 0 @@ -113,6 +121,8 @@ , (rightButton, BRight) , (scrollUp, BScrollUp) , (scrollDown, BScrollDown)+ , (scrollLeft, BScrollLeft)+ , (scrollRight, BScrollRight) ] in case lookup (mods .&. buttonMask) buttonMap of Nothing -> failParse
tools/BuildWidthTable.hs view
@@ -1,18 +1,29 @@-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE CPP #-}-module Main where+module Main (main) where +import Graphics.Vty.UnicodeWidthTable.Main (defaultMain) import System.Console.ANSI (getCursorPosition)-import Text.Printf (printf) -import Graphics.Vty.UnicodeWidthTable.Main (defaultMain)+main :: IO ()+main = defaultMain charWidth +-- | The number of times we'll attempt to compute a character's width+-- before defaulting to @1@ and continuing.+attempts :: Int+attempts = 3++-- | Experimentally determine the console width of the character. charWidth :: Char -> IO Int-charWidth c = do- printf "\r"- putChar c- Just (_, col) <- getCursorPosition- return col+charWidth = charWidth' 0 -main :: IO ()-main = defaultMain charWidth+-- | Helper for 'charWidth' with the number of failed attempts counted.+charWidth' :: Int {- ^ failed attempts -} -> Char -> IO Int+charWidth' n c+ | n >= attempts =+ do putStrLn ("\rUnable to check: " ++ [c] ++ " (" ++ show c ++ ")")+ pure 1 -- fallback default to 1+ | otherwise =+ do putStr ['\r', c]+ mb <- getCursorPosition+ case mb of+ Nothing -> charWidth' (n+1) c+ Just (_, col) -> pure col
vty-unix.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: vty-unix-version: 0.2.0.0+version: 0.4.0.0 synopsis: Unix backend for Vty description: This package provides Unix terminal support for Vty. license: BSD-3-Clause@@ -53,7 +53,7 @@ mtl, unix, terminfo,- vty >= 6.1,+ vty >= 6.6, deepseq, vector, parsec,@@ -74,6 +74,6 @@ if !impl(ghc >= 8.0) build-depends: semigroups >= 0.16 - build-depends: base,+ build-depends: base >= 4.8 && < 5, vty, ansi-terminal