diff options
author | tv <tv@shackspace.de> | 2015-03-05 00:56:24 +0100 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-03-05 00:56:24 +0100 |
commit | 5d0537e5be15e82e43dc0beaa42809f8e5ef3510 (patch) | |
tree | 56ce241c16aa29a71686a94d1b70ff803742d41d /test5.hs | |
parent | c2506144edbe41f896a54c5cfd7c829f35ec120d (diff) |
test5: add prompt
Diffstat (limited to 'test5.hs')
-rw-r--r-- | test5.hs | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -26,6 +26,7 @@ import Event import ParseMail (readMail) import RenderTreeView (renderTreeView) import Scanner (scan) +import Safe import System.Directory import System.Console.Docopt (getArgWithDefault, optionsWithUsage, shortOption) import System.Environment @@ -682,3 +683,25 @@ addDateHeader m@M.Mail{..} = do ) : mailHeaders } + +prompt :: String -> IO (Either ExitCode String) +prompt ps = + withTempFile' "prompt" $ \(path, h_tempFile) -> do + mapM_ (hPutStrLn h_tempFile) $ "" : map comment (lines ps) + hClose h_tempFile + editor <- getEnv "EDITOR" + runInteractive editor [path] >>= \case + ExitSuccess -> Right . removeComments <$> readFile path + code -> return (Left code) + where + comment = ("# "++) + removeComments = + unlines . + filter (maybe True (/='#') . headMay) . + lines + + +runInteractive :: FilePath -> [String] -> IO ExitCode +runInteractive cmd args = do + (_, _, _, h_proc) <- createProcess (proc cmd args) + waitForProcess h_proc |