From 253b56ec950701ba98a70da94bd987d378d90f34 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 14 Jun 2022 18:57:46 +0200 Subject: Main that also allows direct ghci access --- src/Main.hs | 36 +++++++++++++++++++++++++----------- 1 file 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 ""]) 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 "" + Error err -> putStrLn err + loop ghci' + makeGhci >>= loop + +main :: IO () +main = do + getArgs >>= \case + ["-irc"] -> mainIRC + ["-ghci"] -> mainGHCI + [] -> mainGHCI + _ -> die "Command line not recognised" -- cgit v1.2.3-70-g09d2