From f235d13556440d9ae6e4cf0885f68e1794b81e61 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 8 Jul 2016 01:31:19 +0200 Subject: More logging --- src/Sequence/Utils.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Sequence/Utils.hs') diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs index 1d34a4f..fbf3c7d 100644 --- a/src/Sequence/Utils.hs +++ b/src/Sequence/Utils.hs @@ -4,6 +4,7 @@ module Sequence.Utils ( withArg, withFocus, withFocus' , focusState , toName, toDesc + , outputLogged , Argument(..) , Completion(..) , module Sequence.Utils.Ask @@ -47,6 +48,8 @@ import Sequence.Utils.Ask import Sequence.Contact.Types import Sequence.Formula +import Text.Regex (mkRegex, subRegex) + class Argument a st | a -> st where arg :: String -> Sh st (Maybe a) @@ -85,6 +88,11 @@ toDesc ident = do Just dmg -> return $ name ++ " " ++ show dmg Nothing -> return name +outputLogged :: EntityIdentifier -> String -> Sh GameState () +outputLogged id str = gLog <>= pure (id, clean str) >> shellPutStrLn str + where + clean str = subRegex (mkRegex "(\x9B|\x1B\\[)[0-?]*[ -/]*[@-~]") str "" -- remove ANSI escapes + instance Completion EntityIdentifier GameState where completableLabel _ = "" complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities -- cgit v1.2.3