aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-06-14 18:57:46 +0200
committerTom Smeding <tom@tomsmeding.com>2022-06-14 18:57:46 +0200
commit253b56ec950701ba98a70da94bd987d378d90f34 (patch)
treec5599eb9e1e503ec43e72effabb52b5e0961b04c
parent971a56735cddf95aa11cd540ec362fd5e56e1205 (diff)
Main that also allows direct ghci access
-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"