From fc69cbaf3306bd3840db2cb48cb34996127a20db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 17 Apr 2024 21:35:46 +0200 Subject: Command name completion using Haskeline Changelog: Tab-completion of command name --- main/Main.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main/Main.hs b/main/Main.hs index 90e4079..5dbad60 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -140,8 +140,11 @@ main = do else interactiveLoop st opts +inputSettings :: Settings IO +inputSettings = setComplete commandCompletion $ defaultSettings + interactiveLoop :: Storage -> Options -> IO () -interactiveLoop st opts = runInputT defaultSettings $ do +interactiveLoop st opts = runInputT inputSettings $ do erebosHead <- liftIO $ loadLocalStateHead st outputStrLn $ T.unpack $ displayIdentity $ headLocalIdentity erebosHead @@ -322,6 +325,14 @@ commands = #endif ] +commandCompletion :: CompletionFunc IO +commandCompletion = completeWordWithPrev Nothing [ ' ', '\t', '\n', '\r' ] $ curry $ \case + ([], '/':pref) -> return . map (simpleCompletion . ('/':)) . filter (pref `isPrefixOf`) $ sortedCommandNames + _ -> return [] + where + sortedCommandNames = sort $ map fst commands + + cmdUnknown :: String -> Command cmdUnknown cmd = liftIO $ putStrLn $ "Unknown command: " ++ cmd -- cgit v1.2.3