aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644
index 0000000..ee11e92
--- /dev/null
+++ b/src/Main.hs
@@ -0,0 +1,41 @@
+module Main where
+
+import Control.Concurrent.MVar
+import Data.Text (Text)
+import qualified Data.Text as T
+
+import Ghci
+import IRC
+
+
+runInGhci :: Ghci -> Text -> IO (Ghci, [Text])
+runInGhci ghci message = do
+ (ghci', output) <- runStmtClever ghci (T.unpack message)
+ case output of
+ Error "" -> return (ghci', [T.pack "Error?"])
+ Error err -> return (ghci', [T.pack err])
+ Ignored -> return (ghci', [])
+ Return "" -> return (ghci', [T.pack "<no output>"])
+ Return s -> return (ghci', [T.pack s])
+
+main :: IO ()
+main = do
+ ghci0 <- makeGhci
+ ghcivar <- newMVar ghci0
+ connectIRC
+ (\t -> T.take 2 t == T.pack "% ")
+ (\recvmsg -> do
+ ghci <- takeMVar ghcivar
+ (ghci', msgs) <- runInGhci ghci (T.drop 2 recvmsg)
+ 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