elsa 0.2.1.1 → 0.2.1.2
raw patch · 3 files changed
+35/−4 lines, 3 filesdep +ansi-terminalPVP ok
version bump matches the API change (PVP)
Dependencies added: ansi-terminal
API changes (from Hackage documentation)
Files
- elsa.cabal +2/−1
- src/Language/Elsa/Runner.hs +12/−3
- src/Language/Elsa/Utils.hs +21/−0
elsa.cabal view
@@ -1,5 +1,5 @@ name: elsa-version: 0.2.1.1+version: 0.2.1.2 synopsis: A tiny language for understanding the lambda-calculus description: elsa is a small proof checker for verifying sequences of reductions of lambda-calculus terms. The goal is to help@@ -34,6 +34,7 @@ array, mtl, megaparsec >= 7.0.4,+ ansi-terminal, hashable, unordered-containers, directory,
src/Language/Elsa/Runner.hs view
@@ -20,6 +20,7 @@ import Language.Elsa.Types import Language.Elsa.UX import Language.Elsa.Eval+import qualified Language.Elsa.Utils as Utils topMain:: IO () topMain = do@@ -49,14 +50,21 @@ exitErrors mode f es = esHandle mode (modeWriter mode f) resultExit es resultExit :: [UserError] -> IO a-resultExit [] = exitSuccess-resultExit _ = exitFailure+resultExit [] = say Utils.Happy >> exitSuccess+resultExit _ = say Utils.Sad >> exitFailure +say :: Utils.Mood -> IO () +say m = Utils.colorStrLn m (Utils.wrapStars (msg m))+ where + msg Utils.Happy = "OK"+ msg Utils.Sad = "Errors found!"++ esHandle :: Mode -> (Text -> IO ()) -> ([UserError] -> IO a) -> [UserError] -> IO a esHandle mode writer exitF es = renderErrors mode es >>= writer >> exitF es modeWriter :: Mode -> FilePath -> Text -> IO ()-modeWriter Cmdline _ s = hPutStrLn stderr s+modeWriter Cmdline _ s = hPutStrLn stderr s modeWriter Json _ s = hPutStrLn stderr s modeWriter Server f s = do createDirectoryIfMissing True jsonDir writeFile jsonFile s@@ -64,6 +72,7 @@ where jsonDir = takeDirectory f </> ".elsa" jsonFile = jsonDir </> addExtension (takeFileName f) ".json"+ --------------------------------------------------------------------------------------------------------- runElsa :: Mode -> FilePath -> Text -> IO ()
src/Language/Elsa/Utils.hs view
@@ -10,7 +10,9 @@ import System.Directory import System.FilePath import Debug.Trace (trace)+import System.Console.ANSI + groupBy :: (Eq k, Hashable k) => (a -> k) -> [a] -> [(k, [a])] groupBy f = M.toList . L.foldl' (\m x -> inserts (f x) x m) M.empty @@ -74,3 +76,22 @@ qPop (Q q) = case Q.popBack q of Nothing -> Nothing Just (x, q') -> Just (x, Q q')+++data Mood = Happy | Sad ++moodColor :: Mood -> Color+moodColor Sad = Red +moodColor Happy = Green++wrapStars :: String -> String+wrapStars msg = "\n**** " ++ msg ++ " " ++ replicate (74 - length msg) '*'++withColor :: Color -> IO () -> IO ()+withColor c act = do + setSGR [ SetConsoleIntensity BoldIntensity, SetColor Foreground Vivid c]+ act+ setSGR [ Reset]++colorStrLn :: Mood -> String -> IO ()+colorStrLn c = withColor (moodColor c) . putStrLn