{-# LANGUAGE FlexibleContexts, ViewPatterns, OverloadedStrings #-} import Data.PQueue.Prio.Max (MaxPQueue) import qualified Data.PQueue.Prio.Max as MaxPQueue import Data.Sequence (Seq, (|>), (<|), viewl, viewr, ViewL(..), ViewR(..)) import qualified Data.Sequence as Seq import Data.Default.Class import Data.Maybe (fromMaybe) import System.Environment.XDG.BaseDir (getUserCacheFile) import System.Environment (getProgName) import System.Exit import System.Console.Haskeline import Control.Monad.State.Strict import Control.Monad.Writer.Strict import Control.Monad.IO.Class import Types import Utils import Command type SequenceT m a = WriterT History (InputT (StateT Sequence m)) a main :: IO () main = do historyFile <- flip getUserCacheFile "history" =<< getProgName let settings = setComplete noCompletion {- TODO -} . (\x -> x { historyFile = Just historyFile }) $ defaultSettings void . flip runStateT def . runInputT settings . runWriterT $ runCli runCli :: (MonadIO m, MonadException m) => SequenceT m () runCli = do input <- lift $ getInputLine "→ " cmnd <- maybe (return $ ParseError "Trying to parse EOF") parseCmd input case input of Nothing -> liftIO exitSuccess Just _ -> do case cmnd of UnknownCommand cmd -> do lift . outputStrLn $ "Unknown command: »" <> cmd <> "«" ParseError err -> do lift . outputStrLn $ "Error parsing input »" <> (fromMaybe "" input) <> "«: " <> err Quit -> liftIO exitSuccess PerformAlt alt -> apply' alt Step -> undefined runCli