Allow terminals to block input
This commit is contained in:
+18
-11
@@ -25,7 +25,7 @@ quitCommand = TerminalCommand
|
||||
}
|
||||
disconnectTerminal :: Terminal -> World -> World
|
||||
disconnectTerminal tm w = w
|
||||
& terminals . ix (_tmID tm) . tmStatus .~ Disconnected
|
||||
& terminals . ix (_tmID tm) . tmStatus .~ TerminalOff
|
||||
& exitTerminalSubInv
|
||||
& terminals . ix (_tmID tm) . tmFutureLines .~
|
||||
[ TerminalLineTerminalEffect 0 (tmDisplayedLines .~ [])
|
||||
@@ -185,15 +185,21 @@ singleCommand followingLines command aliases htext eff = TerminalCommand
|
||||
,_tcEffect = \_ _ -> NoArguments $ TerminalLineEffect 0 (const eff) : map makeTermLine followingLines
|
||||
}
|
||||
|
||||
guardDisconnected :: Terminal -> World -> World -> World
|
||||
guardDisconnected tm w w' = case _tmStatus tm of
|
||||
TerminalOff -> w
|
||||
TerminalBusy -> w
|
||||
TerminalReady -> w'
|
||||
|
||||
doTerminalEffectLB :: Terminal -> World -> World
|
||||
doTerminalEffectLB tm w = fromMaybe w $ do
|
||||
doTerminalEffectLB tm w = guardDisconnected tm w $ fromMaybe w $ do
|
||||
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText
|
||||
if null (words s)
|
||||
then Just $ defocusTerminalInput w
|
||||
else return $ terminalReturnEffect tm w
|
||||
|
||||
terminalReturnEffect :: Terminal -> World -> World
|
||||
terminalReturnEffect tm w = fromMaybe w $ do
|
||||
terminalReturnEffect tm w = guardDisconnected tm w $ fromMaybe w $ do
|
||||
s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText
|
||||
return $ runTerminalString s tm $ w
|
||||
& terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>':s)]
|
||||
@@ -241,9 +247,7 @@ basicTerminal = defaultTerminal
|
||||
,_tmInput = defaultTerminalInput
|
||||
,_tmScrollCommands = [quitCommand]
|
||||
,_tmWriteCommands = [helpCommand,commandsCommand]
|
||||
,_tmProgram = \_ _ -> termSoundLine computerBeepingS
|
||||
: TerminalLineTerminalEffect 0 (tmStatus .~ Connected)
|
||||
: map makeTermLine connectionBlurb
|
||||
,_tmProgram = \_ _ -> connectionBlurb1
|
||||
, _tmDeathEffect = doDeathTriggers
|
||||
}
|
||||
|
||||
@@ -255,8 +259,11 @@ doDeathTriggers tm w = w
|
||||
doDeathToggle :: TerminalToggle -> IM.IntMap (World -> Bool) -> IM.IntMap (World -> Bool)
|
||||
doDeathToggle (TerminalToggle trid f) = ix trid %~ f
|
||||
|
||||
connectionBlurb :: [String]
|
||||
connectionBlurb =
|
||||
["CONNECTING ..."
|
||||
,"COMPLETE"
|
||||
]
|
||||
connectionBlurb1 :: [TerminalLine]
|
||||
connectionBlurb1 =
|
||||
[termSoundLine computerBeepingS
|
||||
,TerminalLineDisplay 0 (const ("CONNECTING ...",white))
|
||||
,TerminalLineDisplay 10 (const ("...",white))
|
||||
,TerminalLineDisplay 10 (const ("CONNECTED",white))
|
||||
,TerminalLineTerminalEffect 0 (tmStatus .~ TerminalReady)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user