packages feed

vty 5.28.2 → 5.29

raw patch · 5 files changed

+82/−33 lines, 5 files

Files

CHANGELOG.md view
@@ -1,4 +1,23 @@ +5.29+----++API changes:+ * The Input type got a new field, 'restoreInputState'. This field+   allows the end user to have direct access to the logic needed to+   restore the terminal's input state flags. Prior to having this field,+   this state restoration logic could only be invoked as part of calling+   'shutdownInput', but since that function does other things (like+   killing threads) it is not advisable to call it repeatedly (which is+   necessary in the use case this change is intended to support). This+   can be called directly to restore the input state flags as needed,+   although this is not required if 'shutdown' (or 'shutdownInput') is+   called.++Other changes:+ * attributeControl: explicitly enable the ICRNL terminal mode flag (see+   #187 and c572ad).+ 5.28.2 ------ 
src/Graphics/Vty/Image.hs view
@@ -117,14 +117,16 @@ vertCat :: [Image] -> Image vertCat = foldr vertJoin EmptyImage --- | Make an 'Image' from a lazy text value. This function should not be--- given a text value containing escapes.+-- | Make an 'Image' from a lazy text value. The text value should be+-- sanitized of escape sequences (ASCII 27) and carriage returns;+-- otherwise layout and attribute problems may result. text :: Attr -> TL.Text -> Image text a txt = let displayWidth = safeWctlwidth txt              in HorizText a txt displayWidth (fromIntegral $! TL.length txt) --- | Make an 'Image' from a text value. This function should not be--- given a text value containing escapes.+-- | Make an 'Image' from a text value. The text value should be+-- sanitized of escape sequences (ASCII 27) and carriage returns;+-- otherwise layout and attribute problems may result. text' :: Attr -> T.Text -> Image text' a txt = let displayWidth = safeWctwidth txt               in HorizText a (TL.fromStrict txt) displayWidth (T.length txt)@@ -138,8 +140,9 @@  -- | Make an image from a string of characters layed out on a single -- row with the same display attribute. The string is assumed to be a--- sequence of ISO-10646 characters. This function should not be given a--- string containing escapes.+-- sequence of ISO-10646 characters. The input string should be+-- sanitized of escape sequences (ASCII 27) and carriage returns;+-- otherwise layout and attribute problems may result. -- -- Note: depending on how the Haskell compiler represents string -- literals, a string literal in a UTF-8 encoded source file, for@@ -156,8 +159,7 @@ -- -- This is an alias for iso10646String since the usual case is that a -- literal string like "foo" is represented internally as a list of ISO--- 10646 31 bit characters. This function should not be given a string--- containing escapes.+-- 10646 31 bit characters. -- -- Note: Keep in mind that GHC will compile source encoded as UTF-8 -- but the literal strings, while UTF-8 encoded in the source, will be
src/Graphics/Vty/Input.hs view
@@ -143,22 +143,8 @@ -- bytes comes from 'classifyMapForTerm' which is then overridden by -- the the applicable entries from the configuration's 'inputMap'. ----- The terminal device is configured with the attributes:------ * IXON disabled: disables software flow control on outgoing data.--- This stops the process from being suspended if the output terminal--- cannot keep up.------ * Raw mode is used for input.------ * ISIG disabled (enables keyboard combinations that result in--- signals)------ * ECHO disabled (input is not echoed to the output)------ * ICANON disabled (canonical mode (line mode) input is not used)------ * IEXTEN disabled (extended functions are disabled)+-- The terminal device's mode flags are configured by the+-- 'attributeControl' function. inputForConfig :: Config -> IO Input inputForConfig config@Config{ termName = Just termName                             , inputFd = Just termFd@@ -168,7 +154,7 @@     terminal <- Terminfo.setupTerm termName     let inputOverrides = [(s,e) | (t,s,e) <- inputMap, t == Nothing || t == Just termName]         activeInputMap = classifyMapForTerm termName terminal `mappend` inputOverrides-    (setAttrs,unsetAttrs) <- attributeControl termFd+    (setAttrs, unsetAttrs) <- attributeControl termFd     setAttrs     input <- initInput config activeInputMap     let pokeIO = Catch $ do@@ -177,11 +163,15 @@             atomically $ writeTChan (input^.eventChannel) (EvResize e e)     _ <- installHandler windowChange pokeIO Nothing     _ <- installHandler continueProcess pokeIO Nothing++    let restore = unsetAttrs+     return $ input         { shutdownInput = do             shutdownInput input             _ <- installHandler windowChange Ignore Nothing             _ <- installHandler continueProcess Ignore Nothing-            unsetAttrs+            restore+        , restoreInputState = restoreInputState input >> restore         } inputForConfig config = (<> config) <$> standardIOConfig >>= inputForConfig
src/Graphics/Vty/Input/Loop.hs view
@@ -52,9 +52,14 @@       -- 'nextEvent' this will not refresh the display if the next event       -- is an 'EvResize'.       _eventChannel  :: TChan Event-      -- | Shuts down the input processing. This should return the-      -- terminal input state to before he input initialized.+      -- | Shuts down the input processing. As part of shutting down the+      -- input, this should also restore the input state.     , shutdownInput :: IO ()+      -- | Restore the terminal's input state to what it was prior+      -- to configuring input for Vty. This should be done as part of+      -- 'shutdownInput' but is exposed in case you need to access it+      -- directly.+    , restoreInputState :: IO ()       -- | Changes to this value are reflected after the next event.     , _configRef :: IORef Config       -- | input debug log@@ -171,15 +176,47 @@                             <*> pure (classify classifyTable)         runReaderT (evalStateT loopInputProcessor s0) input +-- | Construct two IO actions: one to configure the terminal for Vty and+-- one to restore the terminal mode flags to the values they had at the+-- time this function was called.+--+-- This function constructs a configuration action to clear the+-- following terminal mode flags:+--+-- * IXON disabled: disables software flow control on outgoing data.+-- This stops the process from being suspended if the output terminal+-- cannot keep up.+--+-- * Raw mode is used for input.+--+-- * ISIG (enables keyboard combinations that result in+-- signals)+--+-- * ECHO (input is not echoed to the output)+--+-- * ICANON (canonical mode (line mode) input is not used)+--+-- * IEXTEN (extended functions are disabled)+--+-- The configuration action also explicitly sets these flags:+--+-- * ICRNL (input carriage returns are mapped to newlines) attributeControl :: Fd -> IO (IO (), IO ()) attributeControl fd = do     original <- getTerminalAttributes fd-    let vtyMode = foldl withoutMode original [ StartStopOutput, KeyboardInterrupts-                                             , EnableEcho, ProcessInput, ExtendedFunctions-                                             ]+    let vtyMode = foldl withMode clearedFlags flagsToSet+        clearedFlags = foldl withoutMode original flagsToUnset+        flagsToSet = [ MapCRtoLF -- ICRNL+                     ]+        flagsToUnset = [ StartStopOutput -- IXON+                       , KeyboardInterrupts -- ISIG+                       , EnableEcho -- ECHO+                       , ProcessInput -- ICANON+                       , ExtendedFunctions -- IEXTEN+                       ]     let setAttrs = setTerminalAttributes fd vtyMode Immediately         unsetAttrs = setTerminalAttributes fd original Immediately-    return (setAttrs,unsetAttrs)+    return (setAttrs, unsetAttrs)  logInitialInputState :: Input -> ClassifyMap -> IO() logInitialInputState input classifyTable = case _inputDebug input of@@ -203,6 +240,7 @@     applyConfig fd config     stopSync <- newEmptyMVar     input <- Input <$> atomically newTChan+                   <*> pure (return ())                    <*> pure (return ())                    <*> newIORef config                    <*> maybe (return Nothing)
vty.cabal view
@@ -1,5 +1,5 @@ name:                vty-version:             5.28.2+version:             5.29 license:             BSD3 license-file:        LICENSE author:              AUTHORS