diff --git a/src/Dodge/Terminal/ReturnEffect.hs b/src/Dodge/Terminal/ReturnEffect.hs new file mode 100644 index 000000000..4b67d1b8b --- /dev/null +++ b/src/Dodge/Terminal/ReturnEffect.hs @@ -0,0 +1,28 @@ +module Dodge.Terminal.ReturnEffect + where + +import Control.Monad +import Data.Maybe +import Dodge.Data.World +import LensHelp +import Dodge.Terminal -- this should be rethought + +terminalReturnEffect :: Terminal -> World -> World +terminalReturnEffect tm w = fromMaybe w $ do + guard $ _tmStatus tm == TerminalReady + s <- w ^? cWorld . lWorld . terminals . ix (_tmID tm) . tmInput . tiText + let pc = maybe "" (++ " ") $ tm ^? tmPartialCommand . _Just + return $ + runTerminalString (pc ++ s) tm $ + w + & cWorld . lWorld . terminals . ix (_tmID tm) . tmPartialCommand .~ Nothing + & cWorld . lWorld . terminals . ix (_tmID tm) . tmFutureLines .~ + [makeTermLine (pc ++ "> " ++ s)] + +runTerminalString :: String -> Terminal -> World -> World +runTerminalString s tm w = + w & cWorld . lWorld . terminals . ix (_tmID tm) + %~ ( (tmInput .~ TerminalInput mempty True (0, 0)) + . (tmFutureLines ++.~ commandFutureLines s tm w) + . (tmCommandHistory %~ take 10 . (s :)) + )