module Neovim.User.Input
where
import Neovim
import Neovim.User.Choice
import System.Directory
input :: String
-> Maybe String
-> Maybe String
-> Neovim env (Either NeovimException Object)
input message mPrefilled mCompletion = vim_call_function "input" $
(message <> " ")
+: maybe "" id mPrefilled
+: maybe [] (+: []) mCompletion
askForDirectory :: String
-> Maybe FilePath
-> Neovim env FilePath
askForDirectory message mPrefilled = do
fp <- errOnInvalidResult $ input message mPrefilled (Just "dir")
efp <- errOnInvalidResult $
vim_call_function "expand" $ (fp :: FilePath) +: []
whenM (not <$> liftIO (doesDirectoryExist efp)) $
whenM (yesOrNo (efp ++ " does not exist, create it?")) $
liftIO $ createDirectoryIfMissing True efp
return efp
askForString :: String
-> Maybe String
-> Neovim env String
askForString message mPrefilled =
errOnInvalidResult $ input message mPrefilled Nothing