summaryrefslogtreecommitdiffstats
path: root/test5.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-03-05 00:56:24 +0100
committertv <tv@shackspace.de>2015-03-05 00:56:24 +0100
commit5d0537e5be15e82e43dc0beaa42809f8e5ef3510 (patch)
tree56ce241c16aa29a71686a94d1b70ff803742d41d /test5.hs
parentc2506144edbe41f896a54c5cfd7c829f35ec120d (diff)
test5: add prompt
Diffstat (limited to 'test5.hs')
-rw-r--r--test5.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/test5.hs b/test5.hs
index 1709be5..4333b20 100644
--- a/test5.hs
+++ b/test5.hs
@@ -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