diff options
Diffstat (limited to 'src/Sequence/Utils.hs')
-rw-r--r-- | src/Sequence/Utils.hs | 8 |
1 files changed, 8 insertions, 0 deletions
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 | |||
4 | ( withArg, withFocus, withFocus' | 4 | ( withArg, withFocus, withFocus' |
5 | , focusState | 5 | , focusState |
6 | , toName, toDesc | 6 | , toName, toDesc |
7 | , outputLogged | ||
7 | , Argument(..) | 8 | , Argument(..) |
8 | , Completion(..) | 9 | , Completion(..) |
9 | , module Sequence.Utils.Ask | 10 | , module Sequence.Utils.Ask |
@@ -47,6 +48,8 @@ import Sequence.Utils.Ask | |||
47 | import Sequence.Contact.Types | 48 | import Sequence.Contact.Types |
48 | import Sequence.Formula | 49 | import Sequence.Formula |
49 | 50 | ||
51 | import Text.Regex (mkRegex, subRegex) | ||
52 | |||
50 | class Argument a st | a -> st where | 53 | class Argument a st | a -> st where |
51 | arg :: String -> Sh st (Maybe a) | 54 | arg :: String -> Sh st (Maybe a) |
52 | 55 | ||
@@ -85,6 +88,11 @@ toDesc ident = do | |||
85 | Just dmg -> return $ name ++ " " ++ show dmg | 88 | Just dmg -> return $ name ++ " " ++ show dmg |
86 | Nothing -> return name | 89 | Nothing -> return name |
87 | 90 | ||
91 | outputLogged :: EntityIdentifier -> String -> Sh GameState () | ||
92 | outputLogged id str = gLog <>= pure (id, clean str) >> shellPutStrLn str | ||
93 | where | ||
94 | clean str = subRegex (mkRegex "(\x9B|\x1B\\[)[0-?]*[ -/]*[@-~]") str "" -- remove ANSI escapes | ||
95 | |||
88 | instance Completion EntityIdentifier GameState where | 96 | instance Completion EntityIdentifier GameState where |
89 | completableLabel _ = "<entity>" | 97 | completableLabel _ = "<entity>" |
90 | complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities | 98 | complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities |