-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Open the user's $EDITOR for text input. -- -- You know when you run git commit, and an editor pops open so -- you can enter a commit message? This is a Haskell library that does -- that. -- -- This library isn't very portable. It relies on the $EDITOR -- environment variable. The concept only exists on *nix systems. @package editor-open @version 0.2.0.0 -- | You know when you run git commit, and a little editor pops -- up? This is a Haskell library that does that. module Text.Editor -- | If you don't want to use ByteString, use this function. -- --
--   >>> :t runUserEditorDWIM plainTemplate mempty
--   ByteString
--   
--   >>> :t wrapStr <$> runUserEditorDWIM plainTemplate mempty
--   String
--   
wrapStr :: ByteString -> String -- | This is most likely the function you want to use. It takes a file type -- template as an argument, along with what you want displayed when the -- user opens the editor. It then runs the editor, and returns the -- version of the text that the user modified. -- --
--   runUserEditorDWIM templ initialContents = userEditorDefault _default_editor >>= theEditor ->
--                                               runSpecificEditor theEditor templ initialContents
--   
-- -- Examples: -- --
--   >>> :set -XOverloadedStrings
--   
--   >>> runUserEditorDWIM jsonTemplate "{\n\n}\n"
--   
-- -- This will open up the user's $EDITOR configured to edit JSON, -- and with the initial text: -- --
--   {
--   }
--   
-- -- There are a bunch of templates. See the "File-type extensions" -- section. It's also trivially easy to make your own templates. Say you -- want one for, I dunno, Python: -- --
--   pythonTemplate = mkTemplate "py"
--   
-- -- The argument to mkTemplate should be the file extension you -- want. In that case, I used "py", because Python's file -- extension is .py. runUserEditorDWIM :: Template -> ByteString -> IO ByteString -- | This is the same as above, it just takes a file as an argument instead -- of the ByteString -- --
--   runUserEditorDWIMFile templ fp = B.readFile fp >>=  runUserEditorDWIM templ
--   
runUserEditorDWIMFile :: Template -> FilePath -> IO ByteString -- | This is likely the simplest function here. It opens up the user's -- editor, and fetches a ByteString from it -- --
--   runUserEditor = userEditorDefault _default_editor >>= theEditor ->
--                     runSpecificEditor theEditor plainTemplate mempty
--   
runUserEditor :: IO ByteString -- | This is probably the second-simplest function. runUserEditorWithTemplate :: Template -> IO ByteString type Template = String -- | Make a template -- --
--   mkTemplate ext = _ftempl <> "." <> ext
--   
-- --
--   >>> mkTemplate "blah"
--   tmp.blah
--   
mkTemplate :: String -> Template -- | File-type template for HTML -- --
--   htmlTemplate = mkTemplate "html"
--   
htmlTemplate :: Template -- | File-type template for JSON -- --
--   jsonTemplate = mkTemplate "json"
--   
jsonTemplate :: Template -- | File-type template for Markdown -- --
--   markdownTemplate = mkTemplate "md"
--   
markdownTemplate :: Template -- | Older file-type template for Markdown -- --
--   markdownTemplate = mkTemplate "markdown"
--   
oldMarkdownTemplate :: Template -- | File-type template for plain text -- --
--   plainTemplate = mkTemplate "txt"
--   
plainTemplate :: Template -- | File-type template for XML -- --
--   xmlTemplate = mkTemplate "xml"
--   
xmlTemplate :: Template -- | Same as plainTemplate txtTemplate :: Template -- | File-type template for YAML -- --
--   yamlTemplate = mkTemplate "yaml"
--   
yamlTemplate :: Template -- | Open an editor. You probably don't want to use this function. -- --
--   runSpecific editorName templ initialContents =
--     withSystemTempFile templ $ filePath hdl -> do
--       hSetBinaryMode hdl True
--       hSetBuffering hdl NoBuffering
--       B.hPut hdl initialContents
--       callProcess editorName [filePath]
--       B.hGetContents hdl
--   
runSpecificEditor :: String -> Template -> ByteString -> IO ByteString -- | This uses getEnv from System.Posix to attempt to get the -- user's $EDITOR variable. -- --
--   userEditor = getEnv _editor
--   
userEditor :: IO (Maybe String) -- | Wrapper around userEditor that includes a fallback option if -- the $EDITOR variable doesn't exist. userEditorDefault -- def = userEditor >>= case Just e -> pure e Nothing -> pure -- def userEditorDefault :: String -> IO String -- | The default editor if no other editor is found -- --
--   _default_editor = "nano"
--   
_default_editor :: String -- | The variable we should search when finding the user's editor. -- --
--   _editor = EDITOR
--   
_editor :: String -- | The standard filename template -- --
--   _ftempl = "tmp"
--   
_ftempl :: String