haskeline 0.5 → 0.5.0.1
raw patch · 5 files changed
+24/−23 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- System/Console/Haskeline.hs +10/−8
- System/Console/Haskeline/Backend/Win32.hsc +4/−1
- System/Console/Haskeline/Command.hs +1/−9
- System/Console/Haskeline/Prefs.hs +8/−4
- haskeline.cabal +1/−1
System/Console/Haskeline.hs view
@@ -174,23 +174,25 @@ . (MonadTrans d, Term (d m), LineState s, MonadReader Prefs m) => TermOps -> d m Event -> String -> s -> KeyMap m s -> d m (Maybe String)-repeatTillFinish tops getEvent prefix = loop+repeatTillFinish tops getEvent prefix = loop [] where - loop :: forall t . LineState t => t -> KeyMap m t -> d m (Maybe String)- loop s processor = do+ loop :: forall t . LineState t+ => [Key] -> t -> KeyMap m t -> d m (Maybe String)+ loop [] s processor = do event <- handle (\(e::SomeException) -> movePast prefix s >> throwIO e) getEvent case event of- WindowResize -> withReposition tops prefix s $ loop s processor+ WindowResize -> withReposition tops prefix s $ loop [] s processor KeyInput k -> do- action <- lift $ lookupKey processor k- case action of- Nothing -> actBell >> loop s processor+ ks <- lift $ asks $ lookupKeyBinding k+ loop ks s processor+ loop (k:ks) s processor = case lookupKM processor k of+ Nothing -> actBell >> loop [] s processor Just g -> case g s of Left r -> movePast prefix s >> return r Right f -> do KeyAction effect next <- lift f drawEffect prefix s effect- loop (effectState effect) next+ loop ks (effectState effect) next simpleFileLoop :: MonadIO m => String -> RunTerm -> m (Maybe String) simpleFileLoop prefix rterm = liftIO $ do
System/Console/Haskeline/Backend/Win32.hsc view
@@ -68,10 +68,13 @@ processEvent :: InputEvent -> Maybe Event processEvent KeyEvent {keyDown = True, unicodeChar = c, virtualKeyCode = vc, controlKeyState = cstate} - = fmap (KeyInput . Key modifier) $ keyFromCode vc `mplus` simpleKeyChar + = fmap (KeyInput . Key modifier') $ keyFromCode vc `mplus` simpleKeyChar where simpleKeyChar = guard (c /= '\NUL') >> return (KeyChar c) testMod ck = (cstate .&. ck) /= 0 + modifier' = if hasMeta modifier && hasControl modifier + then noModifier {hasShift = hasShift modifier} + else modifier modifier = Modifier {hasMeta = testMod ((#const RIGHT_ALT_PRESSED) .|. (#const LEFT_ALT_PRESSED)) ,hasControl = testMod ((#const RIGHT_CTRL_PRESSED)
System/Console/Haskeline/Command.hs view
@@ -2,7 +2,7 @@ -- * Commands Effect(..), KeyMap(), - lookupKey,+ lookupKM, KeyAction(..), CmdAction(..), (>=>),@@ -33,9 +33,6 @@ import Control.Monad(mplus) import System.Console.Haskeline.LineState import System.Console.Haskeline.Key-import System.Console.Haskeline.Monads-import System.Console.Haskeline.Prefs-import qualified Data.Map as Map data Effect s = Change {effectState :: s} @@ -45,11 +42,6 @@ newtype KeyMap m s = KeyMap {lookupKM :: Key -> Maybe (s -> Either (Maybe String) (m (KeyAction m)))}--lookupKey :: MonadReader Prefs m => KeyMap n s -> Key- -> m (Maybe (s -> Either (Maybe String) (n (KeyAction n))))-lookupKey processor k = asks $ lookupKM processor - . Map.findWithDefault k k . customBindings useKey :: Key -> (s -> Either (Maybe String) (m (KeyAction m))) -> KeyMap m s useKey k f = KeyMap $ \k' -> if k==k' then Just f else Nothing
System/Console/Haskeline/Prefs.hs view
@@ -4,7 +4,8 @@ readPrefs, CompletionType(..), BellStyle(..),- EditMode(..)+ EditMode(..),+ lookupKeyBinding ) where import Data.Char(isSpace,toLower)@@ -42,7 +43,7 @@ -- ^ If 'False', completions with multiple possibilities -- will ring the bell and only display them if the user -- presses @TAB@ again.- customBindings :: Map.Map Key Key,+ customBindings :: Map.Map Key [Key], -- (termName, keysequence, key) customKeySequences :: [(Maybe String, String,Key)] }@@ -94,8 +95,8 @@ ] addCustomBinding :: String -> Prefs -> Prefs-addCustomBinding str p = case map parseKey (words str) of- [Just k1,Just k2] -> p {customBindings = Map.insert k1 k2 (customBindings p)}+addCustomBinding str p = case sequence $ map parseKey (words str) of+ Just (k:ks) -> p {customBindings = Map.insert k ks (customBindings p)} _ -> p addCustomKeySequence :: String -> Prefs -> Prefs@@ -111,6 +112,9 @@ cs <- readMaybe cstr return (mterm,cs,k) addKS ks p = p {customKeySequences = ks:customKeySequences p}++lookupKeyBinding :: Key -> Prefs -> [Key]+lookupKeyBinding k = Map.findWithDefault [k] k . customBindings -- | Read 'Prefs' from a given file. If there is an error reading the file, -- the 'defaultPrefs' will be returned.
haskeline.cabal view
@@ -1,6 +1,6 @@ Name: haskeline Cabal-Version: >=1.2-Version: 0.5+Version: 0.5.0.1 Category: User Interfaces License: BSD3 License-File: LICENSE