Try to autocomplete before doing terminal return

This commit is contained in:
2025-08-20 17:53:39 +01:00
parent 3936e1a386
commit 21460ceaa8
3 changed files with 63 additions and 58 deletions
+28 -16
View File
@@ -59,7 +59,8 @@ getCommand :: World
-> Terminal -> TCom -> PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
getCommand w tm = \case
TCInfo x z -> PTE.singleton x (PTE.singleton "" (makeTermPara z))
TCBase -> helpCommand <> quitCommand <> toggleCommands tm
--TCBase -> helpCommand <> quitCommand <> toggleCommands tm
TCBase -> quitCommand <> toggleCommands tm
TCDamageCommand -> damageCodeCommand w
TCSensorInfo -> sensorCommand w tm
@@ -104,14 +105,17 @@ toggleCommands tm
(TmWdWdfromWdWd (WdWdNegateTrig $ x ^. ttTriggerID))
])
helpCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
helpCommand = PTE.singleton "HELP" (fmap makeTermPara helpStrings)
--helpCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
--helpCommand = PTE.singleton "" (fmap makeTermPara helpStrings)
--
--helpStrings :: PTE.TrieMap Char String
--helpStrings =
-- PTE.fromList
-- [ ("", "THIS TERMINAL PROCESSES KEYBOARD INPUT. USE [RETURN] OR [LMB] TO REGISTER YOUR INPUT. AVAILABLE COMMANDS CAN BE SCROLLED THROUGH, HOLD [RMB] TO SCROLL THROUGH ARGUMENTS. USE [TAB] FOR AUTOCOMPLETE.")
-- ]
helpStrings :: PTE.TrieMap Char String
helpStrings =
PTE.fromList
[ ("", "THIS TERMINAL PROCESSES KEYBOARD INPUT. USE [RETURN] OR [LMB] TO REGISTER YOUR INPUT. AVAILABLE COMMANDS CAN BE SCROLLED THROUGH, HOLD [RMB] TO SCROLL THROUGH ARGUMENTS. USE [TAB] FOR AUTOCOMPLETE.")
]
helpPara :: [TerminalLine]
helpPara = makeTermPara "THIS TERMINAL PROCESSES KEYBOARD INPUT. USE [RETURN] OR [LMB] TO REGISTER YOUR INPUT. AVAILABLE COMMANDS CAN BE SCROLLED THROUGH, HOLD [RMB] TO SCROLL THROUGH ARGUMENTS. USE [TAB] FOR AUTOCOMPLETE."
quitCommand :: PTE.TrieMap Char (PTE.TrieMap Char [TerminalLine])
quitCommand = PTE.singleton "QUIT" (PTE.singleton "" [TLine 0 [] TmWdWdPowerDownTerminal])
@@ -137,9 +141,14 @@ makeColorTermLine col str = TLine 1 [TerminalLineConst str col] TmWdId
commandColor :: Color
commandColor = yellow
-- ugly
tabComplete :: String -> World -> Terminal -> Terminal
tabComplete s' w tm = case PTE.lookup s $ getCommands w tm of
tabComplete :: World -> Terminal -> Terminal
tabComplete w tm = fromMaybe tm $ do
s <- tm ^? tmStatus . tiText
return $ tabComplete' s w tm
-- ugly, can improve output to explain when showing available arguments
tabComplete' :: String -> World -> Terminal -> Terminal
tabComplete' s' w tm = case PTE.lookup s $ getCommands w tm of
Just m -> f (s ++ " ") $ PTE.toList $ PTE.lookupPrefix a m
Nothing -> f "" $ PTE.toList $ PTE.lookupPrefix s $ getCommands w tm
where
@@ -184,14 +193,17 @@ simpleTermMessage strs = defaultTerminal & tmBootLines .~ map makeTermLine strs
terminalReturnEffect :: Int -> World -> World
terminalReturnEffect tmid w = fromMaybe w $ do
tm <- w ^? cWorld . lWorld . terminals . ix tmid
tm' <- w ^? cWorld . lWorld . terminals . ix tmid
let tm = tabComplete w tm'
s <- tm ^? tmStatus . tiText
let ss = fromMaybe [makeTermLine "ERROR: INPUT NOT RECOGNISED"] $ do
let args = words s
x <- args ^? ix 0
teff <- PTE.lookup x (getCommands w tm)
let y = fromMaybe "" (args ^? ix 1)
PTE.lookup y teff
case args of
[] -> return helpPara
(x:_) -> do
teff <- PTE.lookup x (getCommands w tm)
let y = fromMaybe "" (args ^? ix 1)
PTE.lookup y teff
return $ w
& totm . tmDisplayedLines .:~ (getPromptTM ++ s, termTextColor)
& totm . tmFutureLines .~ ss <> tlSetStatus (TerminalTextInput "")
+1 -3
View File
@@ -405,9 +405,7 @@ updateKeysTextInputTerminal tmid u =
uvWorld %~ terminalReturnEffect tmid
| otherwise = id
tryTabComplete
| u ^. uvWorld . input . pressedKeys . at ScancodeTab == Just 0 = fromMaybe id $ do
s <- u ^? uvWorld . cWorld . lWorld . terminals . ix tmid . tmStatus . tiText
return $ uvWorld . cWorld . lWorld . terminals . ix tmid %~ tabComplete s (u ^. uvWorld)
| u ^. uvWorld . input . pressedKeys . at ScancodeTab == Just 0 = uvWorld . cWorld . lWorld . terminals . ix tmid %~ tabComplete (u ^. uvWorld)
| otherwise = id
updateKeyInGame :: Universe -> Scancode -> Int -> Universe