This commit is contained in:
2023-05-03 11:19:59 +01:00
parent ed8d8f0e93
commit 1d5f982fcc
+28
View File
@@ -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 :))
)