From 1d5f982fcc689e88845fa9c0ba400ed3611c8011 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 3 May 2023 11:19:59 +0100 Subject: [PATCH] Add file --- src/Dodge/Terminal/ReturnEffect.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Dodge/Terminal/ReturnEffect.hs 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 :)) + )