haskeline 0.8.1.3 → 0.8.2
raw patch · 3 files changed
+34/−10 lines, 3 filesdep ~basedep ~transformersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, transformers
API changes (from Hackage documentation)
+ System.Console.Haskeline.Completion: completeWord' :: Monad m => Maybe Char -> (Char -> Bool) -> (String -> m [Completion]) -> CompletionFunc m
+ System.Console.Haskeline.Completion: completeWordWithPrev' :: Monad m => Maybe Char -> (Char -> Bool) -> (String -> String -> m [Completion]) -> CompletionFunc m
Files
- Changelog +3/−0
- System/Console/Haskeline/Completion.hs +30/−9
- haskeline.cabal +1/−1
Changelog view
@@ -1,3 +1,6 @@+Changed in version 0.8.2:+ * Add versions of `completeWord{,withPrev}` that take predicates for word break chars (#164)+ Changed in version 0.8.1.3: * Use the capi calling convention for ioctl (#163).
System/Console/Haskeline/Completion.hs view
@@ -6,7 +6,9 @@ fallbackCompletion, -- * Word completion completeWord,+ completeWord', completeWordWithPrev,+ completeWordWithPrev', completeQuotedWord, -- * Filename completion completeFilename,@@ -59,6 +61,14 @@ -> CompletionFunc m completeWord esc ws = completeWordWithPrev esc ws . const +-- | The same as 'completeWord' but takes a predicate for the whitespace characters+completeWord' :: Monad m => Maybe Char+ -- ^ An optional escape character+ -> (Char -> Bool) -- ^ Characters which count as whitespace+ -> (String -> m [Completion]) -- ^ Function to produce a list of possible completions+ -> CompletionFunc m+completeWord' esc ws = completeWordWithPrev' esc ws . const+ -- | A custom 'CompletionFunc' which completes the word immediately to the left of the cursor, -- and takes into account the line contents to the left of the word. --@@ -71,16 +81,27 @@ -- line contents to the left of the word, reversed. The second argument is the word -- to be completed. -> CompletionFunc m-completeWordWithPrev esc ws f (line, _) = do+completeWordWithPrev esc ws = completeWordWithPrev' esc (`elem` ws)++-- | The same as 'completeWordWithPrev' but takes a predicate for the whitespace characters+completeWordWithPrev' :: Monad m => Maybe Char+ -- ^ An optional escape character+ -> (Char -> Bool) -- ^ Characters which count as whitespace+ -> (String -> String -> m [Completion])+ -- ^ Function to produce a list of possible completions. The first argument is the+ -- line contents to the left of the word, reversed. The second argument is the word+ -- to be completed.+ -> CompletionFunc m+completeWordWithPrev' esc wpred f (line, _) = do let (word,rest) = case esc of- Nothing -> break (`elem` ws) line+ Nothing -> break wpred line Just e -> escapedBreak e line completions <- f rest (reverse word)- return (rest,map (escapeReplacement esc ws) completions)+ return (rest,map (escapeReplacement esc wpred) completions) where- escapedBreak e (c:d:cs) | d == e && c `elem` (e:ws)+ escapedBreak e (c:d:cs) | d == e && (c == e || wpred c) = let (xs,ys) = escapedBreak e cs in (c:xs,ys)- escapedBreak e (c:cs) | notElem c ws+ escapedBreak e (c:cs) | not $ wpred c = let (xs,ys) = escapedBreak e cs in (c:xs,ys) escapedBreak _ cs = ("",cs) @@ -105,12 +126,12 @@ setReplacement :: (String -> String) -> Completion -> Completion setReplacement f c = c {replacement = f $ replacement c} -escapeReplacement :: Maybe Char -> String -> Completion -> Completion-escapeReplacement esc ws f = case esc of+escapeReplacement :: Maybe Char -> (Char -> Bool) -> Completion -> Completion+escapeReplacement esc wpred f = case esc of Nothing -> f Just e -> f {replacement = escape e (replacement f)} where- escape e (c:cs) | c `elem` (e:ws) = e : c : escape e cs+ escape e (c:cs) | c == e || wpred c = e : c : escape e cs | otherwise = c : escape e cs escape _ "" = "" @@ -127,7 +148,7 @@ = case splitAtQuote esc qs left of Just (w,rest) | isUnquoted esc qs rest -> do cs <- completer (reverse w)- return (rest, map (addQuotes . escapeReplacement esc qs) cs)+ return (rest, map (addQuotes . escapeReplacement esc (`elem` qs)) cs) _ -> alterative line addQuotes :: Completion -> Completion
haskeline.cabal view
@@ -1,6 +1,6 @@ Name: haskeline Cabal-Version: >=1.10-Version: 0.8.1.3+Version: 0.8.2 Category: User Interfaces License: BSD3 License-File: LICENSE