nvim-hs-contrib 0.2.0 → 1.0.0.0
raw patch · 3 files changed
+23/−21 lines, 3 filesdep +prettyprinterdep +prettyprinter-ansi-terminaldep −ansi-wl-pprintdep −exceptionsdep ~messagepackdep ~nvim-hs
Dependencies added: prettyprinter, prettyprinter-ansi-terminal
Dependencies removed: ansi-wl-pprint, exceptions
Dependency ranges changed: messagepack, nvim-hs
Files
- library/Neovim/User/Choice.hs +13/−11
- library/Neovim/User/Input.hs +3/−3
- nvim-hs-contrib.cabal +7/−7
library/Neovim/User/Choice.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE OverloadedStrings #-} {- | Module : Neovim.User.Choice Description : Ask the user for an answer@@ -15,26 +16,26 @@ import Neovim -import Data.Char (toLower)-import Data.List (isPrefixOf)-import Text.PrettyPrint.ANSI.Leijen as P hiding ((<$>))+import Data.Char (toLower)+import Data.List (isPrefixOf) -- | Call @inputlist()@ on the neovim side and ask the user for a choice. This -- function returns 'Nothing' if the user input was invalid or 'Just' the chosen -- element. The elements are rendered via 'Pretty'.-oneOf :: Pretty a => [a] -> Neovim r st (Maybe a)+oneOf :: [String] -> Neovim env (Maybe String) oneOf cs = fmap (\i -> cs !! (i-1)) <$> askForIndex (zipWith mkChoice cs [1..]) where- mkChoice c i = docToObject $ int i P.<> text "." <+> pretty c+ mkChoice :: String -> Int -> Object+ mkChoice c i = toObject $ show i <> ". " <> c -- | Ask user for a choice and 'Maybe' return the index of that choice -- (1-based).-askForIndex :: [Object] -> Neovim r st (Maybe Int)+askForIndex :: [Object] -> Neovim env (Maybe Int) askForIndex cs = vim_call_function "inputlist" [ObjectArray cs] >>= \case Left e ->- (err . text . show) e+ err $ exceptionToDoc e Right a -> case fromObject a of Right i | i >= 1 && i <= length cs ->@@ -48,7 +49,7 @@ -- | Same as 'oneOf' only that @a@ is constrained by 'Show' insted of 'Pretty'.-oneOfS :: Show a => [a] -> Neovim r st (Maybe a)+oneOfS :: Show a => [a] -> Neovim env (Maybe a) oneOfS cs = fmap (\i -> cs !! (i-1)) <$> askForIndex (zipWith mkChoice cs [1..]) where mkChoice c i = toObject $ show (i :: Int) ++ ". " ++ show c@@ -58,10 +59,11 @@ -- prefix of @yes@ or @no@ or alternatively aborted the dialog. Defaults to -- @yes@ for the empty input. yesOrNo :: String -- ^ Question to the user- -> Neovim r st Bool+ -> Neovim env Bool yesOrNo message = do spec <- vim_call_function- "inputdialog" $ (message ++ " (Y/n) ") +: "" +: "no" +: []+ "inputdialog" $ (message ++ " (Y/n) ")+ +: ("" :: String) +: ("no" :: String) +: [] case fmap fromObject spec of Right (Right s) | map toLower s `isPrefixOf` "yes" -> return True
library/Neovim/User/Input.hs view
@@ -23,7 +23,7 @@ input :: String -- ^ Message to display -> Maybe String -- ^ Input fiiled in -> Maybe String -- ^ Completion mode- -> Neovim r st (Either NeovimException Object)+ -> Neovim env (Either NeovimException Object) input message mPrefilled mCompletion = vim_call_function "input" $ (message <> " ") +: maybe "" id mPrefilled@@ -35,7 +35,7 @@ -- If the directory does not exist, ask the usere whether it should be created. askForDirectory :: String -- ^ Message to put in front -> Maybe FilePath -- ^ Prefilled text- -> Neovim r st FilePath+ -> Neovim env FilePath askForDirectory message mPrefilled = do fp <- errOnInvalidResult $ input message mPrefilled (Just "dir") @@ -51,6 +51,6 @@ askForString :: String -- ^ message to put in front -> Maybe String -- ^ Prefilled text- -> Neovim r st String+ -> Neovim env String askForString message mPrefilled = errOnInvalidResult $ input message mPrefilled Nothing
nvim-hs-contrib.cabal view
@@ -1,9 +1,9 @@ name: nvim-hs-contrib-version: 0.2.0+version: 1.0.0.0 synopsis: Haskell plugin backend for neovim description: Library for nvim-hs.-homepage: https://github.com/neovimhaskell/nvim-hs+homepage: https://github.com/neovimhaskell/nvim-hs-contrib license: Apache-2.0 license-file: LICENSE author: Sebastian Witte@@ -15,7 +15,7 @@ extra-source-files: CHANGELOG.md source-repository head type: git- location: https://github.com/neovimhaskell/nvim-hs+ location: https://github.com/neovimhaskell/nvim-hs-contrib library exposed-modules: Neovim.BuildTool@@ -24,14 +24,14 @@ -- other-extensions: build-depends: base >=4.6 && < 5- , nvim-hs >= 0.2.0- , ansi-wl-pprint+ , nvim-hs >= 1.0+ , prettyprinter+ , prettyprinter-ansi-terminal , bytestring , data-default , directory- , exceptions , filepath- , messagepack >= 0.4+ , messagepack , mtl >= 2.2.1 && < 2.3 , text , time