aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/Main.hs b/src/Main.hs
index ee11e92..cc4fda2 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,8 +1,11 @@
+{-# LANGUAGE LambdaCase #-}
module Main where
import Control.Concurrent.MVar
import Data.Text (Text)
import qualified Data.Text as T
+import System.Environment (getArgs)
+import System.Exit (die)
import Ghci
import IRC
@@ -18,8 +21,8 @@ runInGhci ghci message = do
Return "" -> return (ghci', [T.pack "<no output>"])
Return s -> return (ghci', [T.pack s])
-main :: IO ()
-main = do
+mainIRC :: IO ()
+mainIRC = do
ghci0 <- makeGhci
ghcivar <- newMVar ghci0
connectIRC
@@ -30,12 +33,23 @@ main = do
putMVar ghcivar ghci'
return msgs)
- -- let loop :: Ghci -> IO ()
- -- loop ghci = do
- -- line <- getLine
- -- (ghci', moutput) <- runStmtClever ghci line
- -- case moutput of
- -- Just output -> putStrLn $ "output = <" ++ output ++ ">"
- -- Nothing -> putStrLn "oops"
- -- loop ghci'
- -- makeGhci >>= loop
+mainGHCI :: IO ()
+mainGHCI = do
+ let loop :: Ghci -> IO ()
+ loop ghci = do
+ line <- getLine
+ (ghci', moutput) <- runStmtClever ghci line
+ case moutput of
+ Return output -> putStrLn $ "output = <" ++ output ++ ">"
+ Ignored -> putStrLn "<ignored>"
+ Error err -> putStrLn err
+ loop ghci'
+ makeGhci >>= loop
+
+main :: IO ()
+main = do
+ getArgs >>= \case
+ ["-irc"] -> mainIRC
+ ["-ghci"] -> mainGHCI
+ [] -> mainGHCI
+ _ -> die "Command line not recognised"